X-Git-Url: http://git.megacz.com/?p=sbp.git;a=blobdiff_plain;f=tests%2Fmeta.g;h=845af526ba34d8b783b90952d02cc06927073819;hp=93a9bb8df6f1d02938128d39ad9ecfd15fb79a69;hb=225993309e6183afa9a88fc13d39df56be54b992;hpb=927dc9b785de472f2237c5adbc4d2ad12f16cc2d diff --git a/tests/meta.g b/tests/meta.g index 93a9bb8..845af52 100644 --- a/tests/meta.g +++ b/tests/meta.g @@ -1,61 +1,63 @@ -s ::= !ws Grammar ws => "gram" -Grammar ::= NonTerminal +/ ws => "grammar" -NonTerminal ::= word ^"::=" RHS /ws - -RHS ::= (Conjuncts +/ (!ws "|" !ws)) +/ (!ws ">" !ws) - -Conjuncts ::= Sequence - | Sequence ^"&" Elements /ws - | Sequence ^"&~" Elements /ws -Elements ::= e*/ws - -ps ::= Elements => "ps" - | (e+/ws !ws)? ^"^" Quoted (!ws e+/ws)? -psy ::= ps - | ps !wp ^"/" !ws e -psx ::= psy => "psy" - | psy ^"->" e /ws -Sequence ::= Quoted => "qprod" - > psx => "psx" - | psx "=>" ^"[]" /ws - | psx ^"=>" ("()"|word|Quoted) /ws - -ec ::= ~[\-\]\\] +Grammar = NonTerminal +/ ws +s = !ws (grammar::Grammar) !ws +NonTerminal = Word ^"=" RHS /ws + +// use 'a'-'z' or 'a-z' instead of [a-z]? +// EOF token? +// #include (with renaming?) +// ANTLR uses ! and ^ suffixes + +blah = "Grammar" + +RHS = (Sequence +/ (!ws "|" !ws)) +/ (!ws ">" !ws) + +Elements = e*/ws + +PreSequence = ps:: Elements + | (Quoted|Word) ^"::" PreSequence /ws + > PreSequence ^"/" e /ws + | PreSequence ^"->" e /ws + +Sequence = psx:: PreSequence + | Sequence ^"&" Elements /ws + | Sequence ^"&~" Elements /ws + +ec = ~[\-\]\\] | escaped -Range ::= ec => "range" - | ec ^"-" ec - -e ::= word => "nonTerminal" - | Quoted => "literal" - | ^"()" - | ^"{" Sequence "}" /ws - | ^"[" Range* "]" - - | e ^"++" /ws -> ~[/] - | e ^"+" /ws -> ~[+] - | e ^"++/" e /ws - | e ^"+/" e /ws - | e ^"**" /ws -> ~[/] - | e ^"*" /ws -> ~[*] - | e ^"**/" e /ws - | e ^"*/" e /ws - | ^"!" e /ws - | e ^"?" /ws - - | "(" word ^")" /ws - > ^"(" RHS ")" /ws - | ^"~" e - -word ::= [a-zA-Z0-9_]++ -Quoted ::= "\"" ((~[\"\\] | escaped)+) "\"" - | "\"\"" => "" -escaped ::= "\\n" => "\n" - | "\\r" => "\r" - | "\\" ~[nr] - - -w ::= " " | "\n" | "\r" -ws ::= w** => () - | w** "//" ~[\n]* "\n" ws => () -wp ::= w++ +Range = range:: ec + | ec ^"-" ec + +e = (Quoted|Word) ^":" e + > nonTerminal:: Word + | literal:: Quoted + | ^"()" + | ^"{" PreSequence "}" /ws + | ^"[" Range* "]" + | e ^"++" /ws -> ~[/] + | e ^"+" /ws -> ~[+] + | e ^"++/" e /ws + | e ^"+/" e /ws + | e ^"**" /ws -> ~[/] + | e ^"*" /ws -> ~[*] + | e ^"**/" e /ws + | e ^"*/" e /ws + | ^"!" e /ws + | e ^"?" /ws + | ^"^" Quoted + | "(" Word ^")" /ws + > ^"(" RHS ")" /ws + | ^"~" e + > "^^":: "^" e + +Word = [a-zA-Z0-9_]++ +Quoted = "\"" ((~[\"\\] | escaped)+) "\"" + | "":: "\"\"" +escaped = "\n":: "\\n" + | "\r":: "\\r" + | "\\" ~[nr] + +w = " " | "\n" | "\r" +ws = "()":: w** + | "()":: w** "//" (~[\n])* "\n" ws +wp = w++