Skip to content

Instantly share code, notes, and snippets.

@FROGGS
Last active March 27, 2016 21:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FROGGS/acffbcdec3956092e1db to your computer and use it in GitHub Desktop.
Save FROGGS/acffbcdec3956092e1db to your computer and use it in GitHub Desktop.
use MONKEY-SEE-NO-EVAL;
grammar Tabula {
rule TOP { <Scenario> }
rule Scenario { ^^ [:i scenario] ':' <Name=String> <Statement>+ }
rule Statement { ^^ <Step> <Comment>? }
rule Step { '?'? <Symbol> + }
token Symbol { <Word> || <Term> }
token Word { [<:Letter> || '_'] \w* } # using just \w+, numbers were words.
token Term { [ <Number> || <String> || <ID> ] }
token Comment { '//' \N+ }
token Number { \d+ }
token String { '"' <-[ " ]>+ '"' }
token ID { '#' <Word> }
}
my $input-tabula = 'scenario: "Eat the ripe apples"
spawn 7 ripe apples
spawn 3 unripe apples
pick apples // should only pick ripe
? verify 7 in basket
eat 2
? verify they were tasty
? verify 5 in basket';
my $g = Tabula.new;
my $parse = $g.parse( $input-tabula );
say so $parse;
say $g.subparse( $input-tabula );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment