Skip to content

Instantly share code, notes, and snippets.

@masak
Created April 7, 2011 21:53
Show Gist options
  • Save masak/908829 to your computer and use it in GitHub Desktop.
Save masak/908829 to your computer and use it in GitHub Desktop.
#!/usr/local/bin/perl6
use v6;
use GGE;
my $pattern = '<[hm]> <[ea]> [nk|n|nn] [ing|ell|all]';
# Add :debug to the below call to see AST and generated code
my $ast = GGE::Perl6Regex.new($pattern).exp;
.say for generate($ast);
multi generate(GGE::Exp::Concat $_) { [X~] map { [generate($_)] }, .list }
multi generate(GGE::Exp::EnumCharList $_) { .ast.comb }
multi generate(GGE::Exp::Alt $_) { generate($_) for .[0], .[1] }
multi generate(GGE::Exp::Literal $_) { .ast }
multi generate(GGE::Exp $_) { die "Unhandled expression type {.WHAT.perl}" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment