Created
September 3, 2010 01:28
-
-
Save svetlins/563259 to your computer and use it in GitHub Desktop.
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
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