Created
March 5, 2015 17:29
-
-
Save jnthn/2ec8ae8a847310f85210 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
grammar G1 { | |
token TOP { \d+ } | |
} | |
class G1Actions { | |
method TOP($/) { | |
make "G1: $/"; | |
} | |
} | |
grammar G2 { | |
token TOP { \w+ } | |
} | |
class G2Actions { | |
method TOP($/) { | |
make "G2: $/"; | |
} | |
} | |
grammar G { | |
token TOP { | |
<g1=.LANG(G1, G1Actions)> | |
<g2=.LANG(G2, G2Actions)> | |
} | |
method LANG($grammar, $actions) { | |
$grammar.subparse(self.orig, :p(self.pos), :$actions).CURSOR | |
} | |
} | |
class GActions { | |
method TOP($/) { | |
make "$<g1> and $<g2>"; | |
} | |
} | |
say G.parse("123beer", actions => GActions).ast; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment