-s = !ws Grammar ws => "gram"
-Grammar = NonTerminal +/ ws => "grammar"
-NonTerminal = word !wp ^"=" !wp RHS
+s = ws! Grammar ws!
+
+Grammar = NonTerminal +/ ws
+
+NonTerminal = Word "=" RHS /ws
+
+// use 'a'-'z' or 'a-z' instead of [a-z]?
+// EOF token?
+// #include (with renaming?)
-RHS = (Conjuncts +/ (!ws "|" !ws)) +/ (!ws ">" !ws)
+RHS = (Sequence +/ (ws! "|" ws!)) +/ (ws! ">" ws!)
-Conjuncts = Sequence
- | Sequence ^"&" Elements /ws
- | Sequence ^"&~" Elements /ws
Elements = e*/ws
-PreSequence = Elements => "ps"
- | PreSequence !wp ^"/" !ws e
- | PreSequence ^"->" e /ws
-// | (Quoted|word) ^"::" PreSequence /ws
- | PreSequence ^"=>" ("[]"|"()"|word|Quoted) /ws
-Sequence = PreSequence => "psx"
+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 => "range"
+Range = ec
| ec ^"-" ec
-e =
- (Quoted|word) ^":" 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
- | e ^"?" /ws
- | ^"^" Quoted /ws
-
- | "(" word ^")" /ws
- > ^"(" RHS ")" /ws
- | ^"~" e
-
-word = [a-zA-Z0-9_]++
-Quoted = "\"" ((~[\"\\] | escaped)+) "\""
- | "\"\"" => ""
-escaped = "\\n" => "\n"
- | "\\r" => "\r"
- | "\\" ~[nr]
+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 => ()
+ws = "()":: w**
+ | "()":: w** "//" (~[\n])* "\n" ws
wp = w++