X-Git-Url: http://git.megacz.com/?p=sbp.git;a=blobdiff_plain;f=tests%2Fmeta.g;h=17f039903c16260fee556f23eac42f9c3f45dac6;hp=31397949a77b10efdcf15e5b5b02685a607bd407;hb=4378d20232cd88fb2a57edc5a5114f952ab58a18;hpb=8ac1795e6098dcf10b94a854351162695181b83d diff --git a/tests/meta.g b/tests/meta.g index 3139794..17f0399 100644 --- a/tests/meta.g +++ b/tests/meta.g @@ -1,58 +1,73 @@ -s ::= !ws Grammar ws => "gram" -Grammar ::= NonTerminal +/ ws => "grammar" -NonTerminal ::= word ^"::=" RHS /ws +// use 'a'-'z' or 'a-z' instead of [a-z]? +// EOF token? +// #include (with renaming?) -RHS ::= (Conjuncts +/ (!ws "|" !ws)) +/ (!ws ">" !ws) +s = ws! Grammar ws! -Conjuncts ::= Sequence - | Sequence ^"&" Elements /ws - | Sequence ^"&~" Elements /ws -Elements ::= e*/ws +Grammar = Declaration +/ ws -psy ::= Elements => "ps" - | psy !wp ^"/" !ws e - | psy ^"->" e /ws - | psy ^"=>" ("[]"|"()"|word|Quoted) /ws -Sequence ::= Quoted => "qprod" - > psy => "psx" +Declaration = NonTerminal + | ^"#import" ws! FileName (ws! "as" ws! Word)? -ec ::= ~[\-\]\\] +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 => "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 - | ^"^" Quoted /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 = 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++