-s ::= ws grammar ws => "gram"
-ws !::= w**
-grammar ::= R+/ws => "grammar"
-Grammar ::= R+ => "grammar"
-R ::= word ^"::=" Alternatives
- | word ^"!::=" Alternatives
-
-ec ::= [~\]\\\-\~] | escaped
-
-Alternatives ::= EquiAlt +/ ">"
-EquiAlt ::= Conjuncts +/ "|" => "alternatives"
-
-sequence ::= Es
- > Es ^"/" E /ws
-Es ::= E+
-//es ::= E+/ws
-
-Conjuncts ::= rewrite
- | rewrite ^"&" sequence
- | rewrite ^"&~" sequence
-
-rewrite ::= sequence /ws => "rewrite"
- | sequence ^"=>" word /ws
- | sequence ^"=>" quoted /ws
- | sequence "=>" "()" /ws => "wrap"
-
-range ::= ec => "range0" | ec ^"-" ec => "range0"
-E ::= word => "nonTerminalY"
- | [(][)] => "epsilon"
- | ^"{" Alternatives "}"
- | "[" [\~]? range* "]" => "range"
- | E ^"*/" E
- | E ^"+/" E
- | E ^"?"
- | E ^"~/~"
-
- | E ^"-" E
-
- | ^"!" E
- | "^" quoted => "care"
- | ^"`" E
- | E ^"#"
- | quoted => "literal"
-
- | (E ^"**" > E ^"*")
- | (E ^"++" > E ^"+")
-
- | "(" word ^")"
- > ^"(" Alternatives ")"
-
-w !::= " "
- | "//" [~\n]* "\n"
- | "\n"
- | "\r"
-an ::= [a-zA-Z0-9_]
-word ::= an++ => "sify"
-quoted ::= "\"" ([~\"\\] | escaped)* "\"" => "sify"
-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! 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 = 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++