Created
December 28, 2011 20:56
-
-
Save softmoth/1529700 to your computer and use it in GitHub Desktop.
simple IF grammar
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 Directive::Grammar { | |
rule TOP { ^ [<direction> | <quit> | <help> | <command>] $ } | |
rule direction { ['n' | 's' | 'e' | 'w' | 'out' | 'in'] } | |
rule quit { 'quit' } | |
rule help { ['help' | '?'] } | |
rule command { <verb> <noun_phrase>? } | |
rule verb { \w+ } | |
rule noun_phrase { ['the' | 'a' | 'some']? \w+ } | |
} | |
my @tests = | |
'e', | |
'take the garbage', | |
'out', | |
'foo bar baz', | |
'help', | |
'gesundheit' | |
; | |
for @tests -> $line { | |
say "TEST: $line"; | |
Directive::Grammar.parse($line); | |
if $/ { | |
say "YES"; | |
say $/.perl; | |
} | |
else { | |
say "NO"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment