X-Git-Url: http://git.megacz.com/?p=sbp.git;a=blobdiff_plain;f=tests%2Fmeta.g;h=17f039903c16260fee556f23eac42f9c3f45dac6;hp=11fee670fbbc658322cc91004c2ceed3e7c4be1f;hb=4378d20232cd88fb2a57edc5a5114f952ab58a18;hpb=05a1638649b2c25a1eaf26831b1bad48d73f57ef diff --git a/tests/meta.g b/tests/meta.g index 11fee67..17f0399 100644 --- a/tests/meta.g +++ b/tests/meta.g @@ -1,58 +1,73 @@ -s ::= ws grammar ws => "gram" -ws !::= w** -wp !::= w++ -grammar ::= r +/ ws => "grammar" - -r ::= word ^"::=" alternatives /ws - | word ^"!::=" alternatives /ws - -alternatives ::= (conjuncts +/ (ws "|" ws)) +/ (ws ">" ws) - -conjuncts ::= sequence - | sequence ^"&" e*/ws /ws - | sequence ^"&~" e*/ws /ws - -ps ::= e*/ws => "ps" - | (e+/ws ws)? "^" quoted (ws e+/ws)? => "ps2" -psy ::= ps - | ps wp ^"/" ws e -psx ::= psy ^"?=>" e /ws - | psy ^"!=>" e /ws - > psy -sequence ::= quoted => "qprod" - > psx - | psx ^"=>" (word|quoted) /ws - -ec ::= [~\-\]\\\~] - | escaped - -range ::= ec => "range" - | ec ^"-" ec - -e ::= word => "nonTerminal" - | quoted => "literal" - | ^"()" - | ^"{" sequence "}" /ws - | ^"[" range* "]" - | ^"[~" range* "]" - - | (e ^"++" /ws > e ^"+" /ws) - | (e ^"++/" e /ws > e ^"+/" e /ws) - | (e ^"**" /ws > e ^"*" /ws) - | (e ^"**/" e /ws > e ^"*/" e /ws) - | e ^"?" /ws - - | "(" word ^")" /ws - > ^"(" alternatives ")" /ws -w !::= " " - | "//" ([~\n]*) "\n" - | "\n" - | "\r" -word ::= [a-zA-Z0-9_]++ -quoted ::= "\"" (([~\"\\] | escaped)+) "\"" - | "\"\"" => "" -escaped ::= "\\n" => "\n" - | "\\r" => "\r" - | "\\" [~nr] +// use 'a'-'z' or 'a-z' instead of [a-z]? +// EOF token? +// #include (with renaming?) +s = ws! Grammar ws! +Grammar = Declaration +/ ws + +Declaration = NonTerminal + | ^"#import" ws! FileName (ws! "as" ws! Word)? + +FileName = FileNameChar+ -> [\r\n ] +FileNameChar = Space:: "\\ " + | ~[\r\n ] + +NonTerminal = Word "=" RHS /ws + | Word "*" ws! ^"=" ws! RHS + | Word "*/" Word ws! ^"=" ws! RHS + +RHS = (Sequence +/ (ws! "|" ws!)) +/ (ws! ">" ws!) + +Elements = e*/ws + +PreSequence = Elements + | (Quoted|Word) ^"::" PreSequence /ws + > PreSequence ^"/" e /ws + | PreSequence ^"->" e /ws + +Sequence = psx:: PreSequence + | Sequence ^"&" Elements /ws + | Sequence ^"&~" Elements /ws + +ec = ~[\-\]\\] + | escaped + +Range = ec + | ec "-" ec + +e = (Quoted|Word) ^":" e + > NonTerminalReference + | Literal + | ^"()" + | ^"{" PreSequence "}" /ws + | ^"[" Range* "]" + | e ^"++" /ws -> ~[/] + | e ^"+" /ws -> ~[+] + | e ^"++/" e /ws + | e ^"+/" e /ws + | e ^"**" /ws -> ~[/] + | e ^"*" /ws -> ~[*] + | e ^"**/" e /ws + | e ^"*/" e /ws + | e ^"!" + | e ^"?" /ws + | ^"^" Quoted + > ^"(" RHS ")" /ws + | ^"~" e + +NonTerminalReference = Word +Literal = Quoted +Word = [.a-zA-Z0-9_]++ +Quoted = "\"" ((~[\"\\] | escaped)+) "\"" + | EmptyString + EmptyString = "\"\"" + +escaped = "\n":: "\\n" + | "\r":: "\\r" + | "\\" ~[nr] + +w = " " | "\n" | "\r" +ws = w** + | w** "//" (~[\n])*! "\n" ws! +wp = w++