Skip to content

Instantly share code, notes, and snippets.

@Mouq
Forked from anonymous/gist:4beb237a975e65e6e775
Last active January 6, 2016 00:25
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 Mouq/7eb9d723d7f05a511529 to your computer and use it in GitHub Desktop.
Save Mouq/7eb9d723d7f05a511529 to your computer and use it in GitHub Desktop.
perl6 grammar test
grammar Test {
rule TOP { ^ <content>* $ }
rule block { '(' ~ ')' <content>* }
rule content { <-[()]>+ || <block> }
}
class TestActs {
method TOP($/) {
$/.make: $<content>».made.join;
}
method block($/) {
$/.make: '[' ~ $<content>».made.join ~ ']';
}
method content($/) {
if $/<block> {
$/.make: $<block>.made;
} else {
$/.make: ~$/;
}
}
}
my $actions = TestActs.new;
my $input = "(a (b))(c (d))";
my $result = Test.parse($input, :$actions);
say ~$result;
say "\n* * * * *\n";
say $result.made;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment