Skip to content

Instantly share code, notes, and snippets.

@tadzik
Created April 19, 2015 14:32
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 tadzik/37cae3e77e645a882d77 to your computer and use it in GitHub Desktop.
Save tadzik/37cae3e77e645a882d77 to your computer and use it in GitHub Desktop.
grammar Foo {
token TOP { <bottom> }
token bottom { <?> }
}
class Foo::Actions {
method TOP($/) {
my $grmr := Metamodel::GrammarHOW.new_type(name => 'BNFGrammar');
$grmr.^add_method('TOP', token { <foo> });
$grmr.^add_method('foo', $<bottom>.ast[0]);
$grmr.^compose;
{
my $/;
say $grmr.new.parse('bar');
}
}
method bottom($/) {
make [token { "bar" }]
}
}
Foo.new.parse('', :actions(Foo::Actions.new))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment