Skip to content

Instantly share code, notes, and snippets.

@svetlins
Created September 3, 2010 01:28
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 svetlins/563259 to your computer and use it in GitHub Desktop.
Save svetlins/563259 to your computer and use it in GitHub Desktop.
my $test = "1 2 3";
grammar TestGrammar {
regex TOP { <char> ** ' ' }
proto regex char { }
regex char:sym<digit> { \d }
regex char:sym<letter> { \w }
}
class TestActions {
method TOP($/) {
make $<char>.map({$_.ast});
}
method char:sym<letter>($/) {
say "matched letter";
#make join('', $/.chunks>>.value)
make "l";
}
method char:sym<digit>($/) {
say "matched digit";
#make join('', $/.chunks>>.value)
make "d";
}
}
my $actions = TestActions.new();
say TestGrammar.parse($test, :$actions).ast;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment