X-Git-Url: http://git.megacz.com/?p=sbp.git;a=blobdiff_plain;f=tests%2Fmeta.g;h=11cb9f8f17f8099f7529151a4fb7d4858d2c8404;hp=0f690221b0a37908bf4a5bab95da6670be7eb4bb;hb=f3b4ef0d81d572694905f4fe284cac6311a29ea4;hpb=ebb5fe5647046306f415e31e4967b23169c9004e diff --git a/tests/meta.g b/tests/meta.g index 0f69022..11cb9f8 100644 --- a/tests/meta.g +++ b/tests/meta.g @@ -1,60 +1,74 @@ -s ::= Grammar ws => "gram" -ws !::= w** | w** "//" (~[\n]*) "\n" ws -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 => "psy" - | e "<-" psy /ws => "psyl" - | psy "->" e /ws => "psyr" - | e "<-" psy "->" e /ws => "psylr" -Sequence ::= Quoted => "qprod" - > psx - | psx "=>" ^"[]" /ws - | psx ^"=>" (word|Quoted) /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 - - | "(" word ^")" /ws - > ^"(" alternatives ")" /ws - | ^"~" e - -w !::= " " - | "\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! Prefix)? + +//Prefix = ([a-zA-Z] ".")+ "*" +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++