Skip to content

Instantly share code, notes, and snippets.

@jnthn
Created March 5, 2015 17:29
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 jnthn/2ec8ae8a847310f85210 to your computer and use it in GitHub Desktop.
Save jnthn/2ec8ae8a847310f85210 to your computer and use it in GitHub Desktop.
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