X-Git-Url: http://git.megacz.com/?p=sbp.git;a=blobdiff_plain;f=tests%2Fmeta.g;h=17f039903c16260fee556f23eac42f9c3f45dac6;hp=7fbcd9aba81054aba72f75e94b143cc0611d0169;hb=4378d20232cd88fb2a57edc5a5114f952ab58a18;hpb=03f91bd299c8c8724fe966f527b7410d2cea675d diff --git a/tests/meta.g b/tests/meta.g index 7fbcd9a..17f0399 100644 --- a/tests/meta.g +++ b/tests/meta.g @@ -1,22 +1,30 @@ -s = !ws (grammar::Grammar) !ws - -Grammar = NonTerminal +/ ws - -NonTerminal = Word ^"=" RHS /ws - // use 'a'-'z' or 'a-z' instead of [a-z]? // EOF token? // #include (with renaming?) -// ANTLR uses ! and ^ suffixes - -RHS = (Sequence +/ (!ws "|" !ws)) +/ (!ws ">" !ws) + +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 = ps:: Elements - | (Quoted|Word) ^"::" PreSequence /ws - > PreSequence ^"/" e /ws - | PreSequence ^"->" e /ws +PreSequence = Elements + | (Quoted|Word) ^"::" PreSequence /ws + > PreSequence ^"/" e /ws + | PreSequence ^"->" e /ws Sequence = psx:: PreSequence | Sequence ^"&" Elements /ws @@ -25,12 +33,12 @@ Sequence = psx:: PreSequence ec = ~[\-\]\\] | escaped -Range = range:: ec - | ec ^"-" ec +Range = ec + | ec "-" ec e = (Quoted|Word) ^":" e - > nonTerminal:: Word - | literal:: Quoted + > NonTerminalReference + | Literal | ^"()" | ^"{" PreSequence "}" /ws | ^"[" Range* "]" @@ -42,22 +50,24 @@ e = (Quoted|Word) ^":" e | e ^"*" /ws -> ~[*] | e ^"**/" e /ws | e ^"*/" e /ws - | ^"!" e /ws + | e ^"!" | e ^"?" /ws | ^"^" Quoted - | "(" Word ^")" /ws > ^"(" RHS ")" /ws | ^"~" e - > "^^":: "^" 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++