Skip to content

Instantly share code, notes, and snippets.

@tadzik
Created April 19, 2015 14:16
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/7e7fcb0dfaf9be7dd9d9 to your computer and use it in GitHub Desktop.
Save tadzik/7e7fcb0dfaf9be7dd9d9 to your computer and use it in GitHub Desktop.
─> cat test
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);
$grmr.^compose;
{
my $/;
say $grmr.new.parse('bar');
}
}
method bottom($/) {
make token { "bar" }
}
}
Foo.new.parse('', :actions(Foo::Actions.new))
─> perl6 test
「bar」
foo => 「bar」
─> diff -uN test test.fail
--- test 2015-04-19 16:13:23.475552957 +0200
+++ test.fail 2015-04-19 16:13:47.147928163 +0200
@@ -7,7 +7,7 @@
method TOP($/) {
my $grmr := Metamodel::GrammarHOW.new_type(name => 'BNFGrammar');
$grmr.^add_method('TOP', token { <foo> });
- $grmr.^add_method('foo', $<bottom>.ast);
+ $grmr.^add_method('foo', $<bottom>.ast[0]);
$grmr.^compose;
{
my $/;
@@ -16,7 +16,7 @@
}
method bottom($/) {
- make token { "bar" }
+ make [token { "bar" }]
}
}
─> perl6 test.fail
Cannot find method 'postcircumfix:<( )>'
in regex at test.fail:9
in method parse at src/gen/m-CORE.setting:16692
in method TOP at test.fail:14
in regex TOP at test.fail:2
in method parse at src/gen/m-CORE.setting:16692
in block <unit> at test.fail:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment