Created
September 22, 2012 14:34
-
-
Save gerdr/3766337 to your computer and use it in GitHub Desktop.
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 Syntax { | |
token TOP { ^ <list> $ } | |
token list { <expression>+ % <.space>+ } | |
token expression { | |
<match=.atom> | |
| <match=.parens> | |
| <match=.squares> | |
} | |
token atom { <.alpha>+ | <.punct>+ | <.digit>+ } | |
token parens { '(' <list> ')' } | |
token squares { <expression> '[' <list> ']' } | |
} | |
my $actions = class { | |
method TOP($/) { | |
make $<list>.ast | |
} | |
method list($/) { | |
make $<expression>>>.ast | |
} | |
method expression($/) { | |
make $<match>.ast | |
} | |
method atom($/) { | |
make ~$/ | |
} | |
method parens($/) { | |
make $<list>.ast | |
} | |
method squares($/) { | |
make $($<expression>.ast, $<list>.ast) | |
} | |
}; | |
say Syntax.parse($_, :$actions).ast.perl given 'f[a b c]'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment