Skip to content

Instantly share code, notes, and snippets.

@softmoth
Created December 28, 2011 20:56
Show Gist options
  • Save softmoth/1529700 to your computer and use it in GitHub Desktop.
Save softmoth/1529700 to your computer and use it in GitHub Desktop.
simple IF grammar
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