Skip to content

Instantly share code, notes, and snippets.

Created March 15, 2016 19:24
Show Gist options
  • Save anonymous/e0019267b1320a45cf5c to your computer and use it in GitHub Desktop.
Save anonymous/e0019267b1320a45cf5c to your computer and use it in GitHub Desktop.
v6;
grammar BUU {
token TOP { <abc>+ };
token abc { 'a' <bc>* };
token bc { [ 'b' <c>* ]+ }
token c { 'c' };
};
# default result
class BuuAbc1 {
method TOP($/) { make $<abc>>>.ast; }
method abc($/) { make $<bc>>>.ast; }
method bc($/) { make $<c>>>.ast; }
method c($/) { make ~$/; }
};
class BuuAbc2 {
method TOP($/) { make $<abc>>>.ast; }
method abc($/) { make $<bc>>>.ast; }
#method bc($/) { make $<c>>>.ast; }
method bc($/) { make ~@$<c>; }
#method c($/) { make ~3.ast; } # error
method c($/) { my $c = 3; make ~$c; } # this do nothing !
};
my $r = BUU.parse( "abcabccaabbc", :actions( BuuAbc2 ) );
say $r;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment