2017 © Pedro PelĂĄez
 

library regex

The Hoa\Regex library.

image

hoa/regex

The Hoa\Regex library.

  • Friday, July 20, 2018
  • by Hoa
  • Repository
  • 10 Watchers
  • 35 Stars
  • 828,330 Installations
  • PHP
  • 6 Dependents
  • 0 Suggesters
  • 11 Forks
  • 5 Open issues
  • 14 Versions
  • 6 % Grown

The README.md

Hoa , (*1)


Build status Code coverage Packagist License , (*2)

Hoa is a modular, extensible and structured set of PHP libraries.
Moreover, Hoa aims at being a bridge between industrial and research worlds. , (*3)

Hoa\Regex

Help on IRC Help on Gitter Documentation Board, (*4)

This library provides tools to analyze regular expressions and generate strings based on regular expressions (Perl Compatible Regular Expressions)., (*5)

Learn more., (*6)

Installation

With Composer, to include this library into your dependencies, you need to require hoa/regex:, (*7)

$ composer require hoa/regex '~1.0'

For more installation procedures, please read the Source page., (*8)

Testing

Before running the test suites, the development dependencies must be installed:, (*9)

$ composer install

Then, to run all the test suites:, (*10)

$ vendor/bin/hoa test:run

For more information, please read the contributor guide., (*11)

Quick usage

As a quick overview, we propose to see two examples. First, analyze a regular expression, i.e. lex, parse and produce an AST. Second, generate strings based on a regular expression by visiting its AST with an isotropic random approach., (*12)

Analyze regular expressions

We need the Hoa\Compiler library to lex, parse and produce an AST of the following regular expression: ab(c|d){2,4}e?. Thus:, (*13)

// 1. Read the grammar.
$grammar  = new Hoa\File\Read('hoa://Library/Regex/Grammar.pp');

// 2. Load the compiler.
$compiler = Hoa\Compiler\Llk\Llk::load($grammar);

// 3. Lex, parse and produce the AST.
$ast      = $compiler->parse('ab(c|d){2,4}e?');

// 4. Dump the result.
$dump     = new Hoa\Compiler\Visitor\Dump();
echo $dump->visit($ast);

/**
 * Will output:
 *     >  #expression
 *     >  >  #concatenation
 *     >  >  >  token(literal, a)
 *     >  >  >  token(literal, b)
 *     >  >  >  #quantification
 *     >  >  >  >  #alternation
 *     >  >  >  >  >  token(literal, c)
 *     >  >  >  >  >  token(literal, d)
 *     >  >  >  >  token(n_to_m, {2,4})
 *     >  >  >  #quantification
 *     >  >  >  >  token(literal, e)
 *     >  >  >  >  token(zero_or_one, ?)
 */

We read that the whole expression is composed of a single concatenation of two tokens: a and b, followed by a quantification, followed by another quantification. The first quantification is an alternation of (a choice betwen) two tokens: c and d, between 2 to 4 times. The second quantification is the e token that can appear zero or one time., (*14)

We can visit the tree with the help of the Hoa\Visitor library., (*15)

Generate strings based on regular expressions

To generate strings based on the AST of a regular expressions, we will use the Hoa\Regex\Visitor\Isotropic visitor:, (*16)

$generator = new Hoa\Regex\Visitor\Isotropic(new Hoa\Math\Sampler\Random());
echo $generator->visit($ast);

/**
 * Could output:
 *     abdcde
 */

Strings are generated at random and match the given regular expression., (*17)

Documentation

The hack book of Hoa\Regex contains detailed information about how to use this library and how it works., (*18)

To generate the documentation locally, execute the following commands:, (*19)

$ composer require --dev hoa/devtools
$ vendor/bin/hoa devtools:documentation --open

More documentation can be found on the project's website: hoa-project.net., (*20)

Getting help

There are mainly two ways to get help:, (*21)

Contribution

Do you want to contribute? Thanks! A detailed contributor guide explains everything you need to know., (*22)

License

Hoa is under the New BSD License (BSD-3-Clause). Please, see LICENSE for details., (*23)

The Versions

13/08 2015

0.15.08.13

0.15.08.13 http://hoa-project.net/

The Hoa\Regex library.

  Sources   Download

BSD-3-Clause

The Requires

 

library regex compiler

29/05 2015

0.15.05.29

0.15.05.29 http://hoa-project.net/

The Hoa\Regex library.

  Sources   Download

BSD-3-Clause

The Requires

 

library regex compiler

24/02 2015

0.15.02.24

0.15.02.24 http://hoa-project.net/

The Hoa\Regex library.

  Sources   Download

BSD-3-Clause

The Requires

 

library regex compiler

10/12 2014

0.14.12.10

0.14.12.10 http://hoa-project.net/

The Hoa\Regex library.

  Sources   Download

BSD-3-Clause

The Requires

 

library regex compiler

15/11 2014

0.14.11.25

0.14.11.25 http://hoa-project.net/

The Hoa\Regex library.

  Sources   Download

BSD-3-Clause

The Requires

 

library regex compiler

14/11 2014

0.14.11.14

0.14.11.14 http://hoa-project.net/

The Hoa\Regex library.

  Sources   Download

BSD-3-Clause

The Requires

 

library regex compiler

23/09 2014

0.14.09.23

0.14.09.23 http://hoa-project.net/

The Hoa\Regex library.

  Sources   Download

BSD-3-Clause

The Requires

 

library regex compiler

17/09 2014

0.14.09.17

0.14.09.17 http://hoa-project.net/

The Hoa\Regex library.

  Sources   Download

BSD-3-Clause

The Requires

 

library regex compiler

16/09 2014

0.14.09.16

0.14.09.16 http://hoa-project.net/

The Hoa\Regex library.

  Sources   Download

BSD-3-Clause

The Requires

 

library regex compiler