On 9/14/06, Ovid <[EMAIL PROTECTED]> wrote:
I'm not particularly gifted with grammars, so corrections welcome.

The corrected TAP grammar:

 digit              ::= [:digit:]
 character          ::= ([:print:] - "\n")
 positiveInteger    ::= ( digit - '0' ) {digit}
 nonNegativeInteger ::= digit {digit}

 tap         ::= plan tests | tests plan {comment}
 plan        ::= '1..' nonNegativeInteger "\n"
 lines       ::= line {lines}
 line        ::= (comment | test) "\n"
 tests       ::= test {test}
 test        ::= status positiveInteger? description? directive?
 status      ::= 'not '? 'ok '
 description ::= (character - (digit '#')) {character - '#'}
 directive   ::= '#' ( 'TODO' | 'SKIP' ) ' ' {character}
 comment     ::= '#' {character}

i translated this grammar to a perl 6 grammar. i know it has some bugs
in it (probably 'rule' vs. 'token' among others) but it's a good
start. from translating it, there are a few things that stick out.

first, the grammar:

grammar TAP;

token digit              { \d }
token character          { <+print-[\n]> }
token positiveInteger    { <+digit-[0]> <digit>* }
token nonNegativeInteger { <digit>+ }

rule  tap         { [ <plan> <tests> | <tests> <plan> <comment>? ] }
rule  plan        { <'1..'> <nonNegativeInteger> \n }
rule  lines       { <line>+ }
rule  line        { [ <comment> | <test> ] \n }
rule  tests       { <test>+ }
rule  test        { <status> <positiveInteger>? <description>? <directive>? }
rule  status      { [ not \s ]? ok }
rule  description { <-[#]-digit> <-[#]>* }
rule  directive   { <'#'> [ :ignorecase todo | skip ] <character>* }
rule  comment     { <'#'> <character>* }

~ i thought descriptions started with a hyphen C<->, not an octothorpe C<#>.
~ doesn't <directive> belong before <description> ??
  C<# SKIP comment> rather than C<- comment #SKIP>
~ schwern already mentioned 'skip_all'
~ missing 'Bail out!'

in any case, it looks pretty good, and i'll try to keep my parrot TAP
parser grammar in line with the TAPx::Parser grammar as it develops.

~jerry
btw, i love writing grammars in perl6. what kind of a geek does that
make me? eh, who cares. grammars rock!

Reply via email to