Skip to content

Instantly share code, notes, and snippets.

@masak
Created April 1, 2010 13:43
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 masak/351813 to your computer and use it in GitHub Desktop.
Save masak/351813 to your computer and use it in GitHub Desktop.
The tests:
$ alpha t/yapsi/parse.t
ok 1 - will parse ''
ok 2 - will parse ';'
ok 3 - will parse '42'
ok 4 - will parse '42;'
ok 5 - will parse 'my $a'
ok 6 - will parse 'my $a;'
ok 7 - will parse 'say 42'
not ok 8 - will parse 'my $a = 42;'
ok 9 - will parse 'my $a; $a = 42;'
not ok 10 - will parse 'my $a; my $a; my $a'
ok 11 - will parse 'my $a; say $a'
ok 12 - will not parse '$a'
ok 13 - will not parse 'my'
ok 14 - will not parse '$a; my $a'
ok 15 - will not parse 'my $a ='
ok 16 - will not parse '$a = 42'
ok 17 - will not parse 'say $a'
ok 18 - will not parse 'say $a; my $a'
1..18
# Looks like you failed 2 tests of 18
The grammar:
grammar Yapsi::Perl6::Grammar {
regex TOP { ^ <statement> ** ';' $ }
token statement { <expression> || '' }
token expression { <variable> || <literal> || <declaration>
|| <assignment> || <saycall> }
token lvalue { <declaration> || <variable> }
token variable { '$' \w+ }
token literal { \d+ }
rule declaration { 'my' <variable> }
rule assignment { <lvalue> '=' <expression> }
rule saycall { 'say' <expression> } # very temporary solution
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment