X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=tests%2Fmeta.g;h=216d3bfd165b98147de511061d39fe9675494fcb;hb=b8a597c8d1a29afc24f9b89f726d5b1a9b9aeec1;hp=138ec62a9c7ef708b6ea747c502a94c241e95500;hpb=f491592fb43d4fd68221db2b893baaede4cfdaca;p=sbp.git diff --git a/tests/meta.g b/tests/meta.g index 138ec62..216d3bf 100644 --- a/tests/meta.g +++ b/tests/meta.g @@ -1,59 +1,73 @@ -s ::= ws grammar ws => "gram" -ws !::= w** -grammar ::= r+/ws => "grammar" -r ::= word ^"::=" alternatives /ws - | word ^"!::=" alternatives /ws - -ec ::= [~\]\\\-\~] | escaped - -alternatives ::= equiAlt +/ (ws ">" ws) -equiAlt ::= conjuncts +/ (ws "|" ws) => "alternatives" - -sequence ::= Es - > Es ^"/" E /ws -Es ::= E+ -//es ::= E+/ws - -conjuncts ::= rewrite - | rewrite ^"&" sequence /ws - | rewrite ^"&~" sequence /ws - -rewrite ::= sequence /ws => "rewrite" - | sequence ^"=>" word /ws - | sequence ^"=>" quoted /ws - | sequence "=>" "()" /ws => "wrap" - -range ::= ec => "range0" | ec ^"-" ec => "range0" -E ::= word => "nonTerminalY" - | [(][)] => "epsilon" - | ^"{" alternatives "}" - | "[" [\~]? range* "]" => "range" - | E ^"*/" E - | E ^"+/" E - | E ^"?" - | E ^"~/~" - - | E ^"-" E - - | ^"!" E - | "^" quoted => "care" - | ^"`" E - | E ^"#" - | quoted => "literal" - - | (E ^"**" > E ^"*") - | (E ^"++" > E ^"+") - - | "(" word ^")" - > ^"(" alternatives ")" - -w !::= " " - | "//" [~\n]* "\n" - | "\n" - | "\r" -an ::= [a-zA-Z0-9_] -word ::= an++ => "sify" -quoted ::= "\"" ([~\"\\] | escaped)* "\"" => "sify" -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++