X-Git-Url: http://git.megacz.com/?p=sbp.git;a=blobdiff_plain;f=tests%2Fmeta.g;h=02618abf9de083e27a45c796ec9dbde3697a4e25;hp=0920a7a6a5fe8ec1e5f5daae8e92aadf86183613;hb=1d5f76f8144b739719737bfe75f321caf67cfa19;hpb=0a0227b9180534d2a431f3d6e08a398bde2244c4 diff --git a/tests/meta.g b/tests/meta.g index 0920a7a..638fa71 100644 --- a/tests/meta.g +++ b/tests/meta.g @@ -1,54 +1,71 @@ -s ::= w* Grammar w* => "gram" -Grammar ::= R+ => "grammar" -R ::= word ^"::=" Class+/gt - | word ^"!::=" Class+/gt - -ec ::= [~\]\\\-\~] | escaped - -Class ::= Rewrite +/ bar => "alternatives" - -Rewrite ::= Rewritex - | Rewritex ^"&" E+ - | Rewritex ^"&~" E+ - -Rewritex ::= E+ => "rewrite" - | E+ ^"=>" word - | E+ ^"=>" quoted - | E+ "=>" "()" => "wrap" - -range ::= ec => "range0" | ec ^"-" ec => "range0" -gt !::= ">" -bar !::= "|" -E ::= word => "nonTerminalY" - | [(][)] => "epsilon" - | ^"{" Class+/gt "}" - | "[" [\~]? range* "]" => "range" - | E ^"*/" E - | E ^"+/" E - | E ^"?" - | E ^"~/~" - - | E ^"-" E - - | ^"!" E - | "^" quoted => "care" - | ^"`" E - | E ^"#" - | quoted => "literal" - - | (E ^"**" > E ^"*") - | (E ^"++" > E ^"+") - - | "(" word ^")" - > ^"(" Class+/gt ")" - -w !::= " " - | "//" [~\n]* "\n" - | "\n" - | "\r" -an ::= [a-zA-Z0-9_] -word ::= an++ => "sify" -quoted ::= "\"" ([~\"\\] | escaped)* "\"" => "sify" -escaped ::= "\\n" => "\n" - | "\\r" => "\r" - | "\\" [~nr] +//funkanomitron +s = ws Grammar ws + +Grammar:: = Declaration +/ ws + +Declaration = NonTerminal + | ^"#import" FileName /ws + | ^"#import" FileName "as" Word /ws + +FileName:: = (~[\r\n ] | escaped)+ -> [\r\n ] + +NonTerminal = NonTerminal:: Word ws "=" ws RHS + | DropNT:: Word "!" ws "=" ws RHS + | Colons:: Word "::" ws "=" ws RHS + | 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 = PreSequence + | Sequence ^"&" Elements /ws + | ^"~~" Elements /ws + | Sequence ^"&~" Elements /ws + +e = e ^"!" + > (Quoted|Word) ^":" e + > NonTerminalReference:: Word + | Literal:: Quoted + | ^"()" + | ^"{" PreSequence "}" /ws + | ^"[" Range* "]" + | e ^"++" /ws -> ~[/] + | e ^"+" /ws -> ~[+] + | e ^"++/" e /ws + | e ^"+/" e /ws + | e ^"**" /ws -> ~[/] + | e ^"*" /ws -> ~[*] + | e ^"**/" e /ws + | e ^"*/" e /ws + | e ^"?" /ws + | ^"^" Quoted + | ^"`" e + | ^"..." + | "(" Word ^")" + > ^"(" RHS ")" /ws + | "~":: ("~" -> ~"~")! e + | ^"\\{" + | ^"\\}" + +Word:: = [.a-zA-Z0-9_]++ &~ "."+ +Quoted:: = "\"" (~[\"\\] | escaped)+ "\"" + | "\"\"" + +Range:: = ec + | ec "-" ec + +ec = ~[\-\]\\] + | escaped +escaped = "\n":: "\\n" + | "\r":: "\\r" + | "\\" ~[nr] + +ws! = [ \r\n]** + | [ \r\n]** "//" ~[\n]* "\n" ws