X-Git-Url: http://git.megacz.com/?p=sbp.git;a=blobdiff_plain;f=tests%2Fmeta.g;h=845af526ba34d8b783b90952d02cc06927073819;hp=bb7cd114d94bf05ab028246df247490f0b38e86d;hb=225993309e6183afa9a88fc13d39df56be54b992;hpb=8ad399319f15cd179fa05a5052314a8f1d7df271 diff --git a/tests/meta.g b/tests/meta.g index bb7cd11..845af52 100644 --- a/tests/meta.g +++ b/tests/meta.g @@ -1,54 +1,63 @@ -s ::= ws grammar ws => "gram" -ws !::= w** -grammar ::= r +/ ws => "grammar" -r ::= word ^"::=" alternatives /ws - | word ^"!::=" alternatives /ws - -alternatives ::= equiAlt +/ (ws ">" ws) -equiAlt ::= conjuncts +/ (ws "|" ws) - -conjuncts ::= sequence - | sequence ^"&" e*/ws /ws - | sequence ^"&~" e*/ws /ws - -sequence ::= e*/ws - (ws "/" e)? - (ws "=>" ws (word|quoted))? => "seq" - -ec ::= [~\-\]\\\~] - | escaped - -range ::= ec => "range" - | ec ^"-" ec - -e ::= word => "nonTerminal" - | [(][)] => "epsilon" - | ^"{" alternatives "}" /ws - | ^"[" (range*) "]" - | ^"[~" (range*) "]" - | ^"^" quoted /ws - | ^"!" e /ws - - | (e ws ^"**" > e ws ^"*") - | e ^"*/" e /ws - | (e ws ^"++" > e ws ^"+") - | e ^"+/" e /ws - | e ^"?" /ws - - | quoted => "literal" - - | "(" word ^")" /ws - > ^"(" alternatives ")" /ws - -w !::= " " - | "//" ([~\n]*) "\n" - | "\n" - | "\r" -word ::= [a-zA-Z0-9_]++ -quoted ::= "\"" (([~\"\\] | escaped)+) "\"" - | "\"\"" => "" -escaped ::= "\\n" => "\n" - | "\\r" => "\r" - | "\\" [~nr] - - +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 = 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++