-
-
Save anonymous/4beb237a975e65e6e775 to your computer and use it in GitHub Desktop.
perl6 grammar test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
grammar Test { | |
rule TOP { ^ <content>* $ } | |
rule block { '(' ~ ')' <content>* } | |
rule content { <-[()]>+ || <block> } | |
} | |
class TestActs { | |
method TOP($/) { | |
$/.make: $<content>».made; | |
} | |
method block($/) { | |
$/.make: '[' ~ $<content>».made ~ ']'; | |
} | |
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