Last active
August 16, 2023 08:53
-
-
Save staabm/55ffa0f1ff5fe870cf7820f5de512108 to your computer and use it in GitHub Desktop.
hoa regex capturing groups
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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