Skip to content

Instantly share code, notes, and snippets.

@staabm
Last active August 16, 2023 08:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save staabm/55ffa0f1ff5fe870cf7820f5de512108 to your computer and use it in GitHub Desktop.
Save staabm/55ffa0f1ff5fe870cf7820f5de512108 to your computer and use it in GitHub Desktop.
hoa regex capturing groups
<?php
use PHPStan\ShouldNotHappenException;
use PHPStan\Type\Constant\ConstantArrayTypeBuilder;
require __DIR__ . '/vendor/autoload.php';
// 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('(\d\s(\w))');
// 4. Dump the result.
$dump = new Hoa\Compiler\Visitor\Dump();
echo $dump->visit($ast);
/* OUTPUT
$ php test.php
$ php test.php
> #expression
> > #concatenation
> > > token(character_type, \d)
> > > token(character_type, \s)
> > > token(character_type, \w)
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment