-
-
Save Mouq/7eb9d723d7f05a511529 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.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