X-Git-Url: http://git.megacz.com/?p=sbp.git;a=blobdiff_plain;f=tests%2Fmeta.g;h=11cb9f8f17f8099f7529151a4fb7d4858d2c8404;hp=eba7a6d82b25c908e9e50c0795bb2cd6e15ee24f;hb=f3b4ef0d81d572694905f4fe284cac6311a29ea4;hpb=61446887e40e11e0a7374e591e6d6c25c922093f diff --git a/tests/meta.g b/tests/meta.g index eba7a6d..11cb9f8 100644 --- a/tests/meta.g +++ b/tests/meta.g @@ -1,32 +1,47 @@ -s = gram:: !ws Grammar ws -Grammar = grammar:: NonTerminal +/ ws -NonTerminal = word !wp ^"=" !wp RHS - -RHS = (Conjuncts +/ (!ws "|" !ws)) +/ (!ws ">" !ws) - -Conjuncts = Sequence - | Sequence ^"&" Elements /ws - | Sequence ^"&~" Elements /ws +// 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 = ps:: Elements - | PreSequence !wp ^"/" !ws e - | PreSequence ^"->" e /ws - | (Quoted|word) ^"::" PreSequence /ws - | PreSequence ^"=>" ("[]"|"()"|word|Quoted) /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 = range:: ec - | ec ^"-" ec +Range = ec + | ec ^"-" ec -e = (Quoted|word) ^":" e - > nonTerminal:: word - | literal:: Quoted +e = (Quoted|Word) ^":" e + > NonTerminalReference + | Literal | ^"()" - | ^"{" Sequence "}" /ws + | ^"{" PreSequence "}" /ws | ^"[" Range* "]" | e ^"++" /ws -> ~[/] | e ^"+" /ws -> ~[+] @@ -36,23 +51,24 @@ e = (Quoted|word) ^":" e | e ^"*" /ws -> ~[*] | e ^"**/" e /ws | e ^"*/" e /ws - | ^"!" e /ws + | e ^"!" | e ^"?" /ws - | ^"^" Quoted /ws - - | "(" word ^")" /ws + | ^"^" Quoted > ^"(" RHS ")" /ws | ^"~" e -word = [a-zA-Z0-9_]++ -Quoted = "\"" ((~[\"\\] | escaped)+) "\"" - | "":: "\"\"" +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 => () +ws = "()":: w** + | "()":: w** "//" (~[\n])* "\n" ws wp = w++