grammar TGE::Parser;

token start { ^ <TGE::Parser::statements>* [ $ | <syntax_error> ] }

rule statements { 
     <transrule>
    | <grammardec>
}

rule grammardec {
    grammar <type> <inherit>?';'
}

rule inherit {
    is <type>
}

rule transrule {
    transform <name> 
    '(' <type> ')'
    <parent>?
    <language>?
    <action>
}
    
rule parent {
    ':applyto' '(' \'(<-[']>*)\' ')'
}

rule language {
    ':language' '(' \'(\w+)\' ')'
}

token action {
    '{' (<-[}]>*) '}'
}

token type {
    [ '::' | ';' ]? \w+ [ ['::' | ';'] \w+ ]*
}

token name { \w+ }

token ws {
    [ \s+
    | \# \N*
    | <.pod_comment>
    ]*
}


regex pod_comment {
    ^^ '=' [ [ cut \h*: | end [\h\N*]? ]
           | for [ \h\N+: ] \n [ \N+\n ]*:
           | \w\N*: \n .*? \n '=' [ cut \h*: | end [\h\N*:]? ]
           ]
           [\n|$]
}

token syntax_error { <?die: 'Syntax error'> }
