-s ::= { Doc } => "top"
-
-Doc ::= Header Body /ws => doc
-Header ::= "header" { kv */ ws } /ws => header
-Body ::= Section*/ws => body
-Section ::= SectionHeader Paragraph*/ws /ws => section
-SectionHeader ::= "==" SectionHeaderBody "=="
-SectionHeaderBody ::= "=" SectionHeaderBody "="
- > ws text ws
-
-kv ::= word "=" text /ws => kv1
-
-Paragraph ::= { "\"\"" ws text } => "blockquote"
- > { "*" " " ws text } => "ul"
- > { "#" " " ws text } => "ol"
- > { num " " ws text => "ol" }
- > { "---" "-"* } => "hr"
- > { text } => "p"
-
-text ::= item */ ws
-pre ::= "[verbatim]" { ~[]+ } /ws => "verbatim" // FIXME doesn't work
-item ::= pre
- > email
- > structured
- > styled
- > "\"" text "\"" => quoted
- > alphanum++ => "stringify"
- > symbol
-
-symbol ::= symbolx & sym++
-symbolx ::= "--" => emdash
- | ","
- | ":"
- | ";"
-
-styled ::= "**" text "**" => bold
- | "__" text "__" => ul
- | "~~" text "~~" => it // hard to type
- | "((" text "))" => footnote
-
-structured ::= glyph
-// | url
-
-glyph ::= "(r)" | "(c)" | "(tm)" // euro symbol?
+s = Doc
+
+Doc = head:Header ws! body:Body
+Header = { "\\header" { KeyVal */ ws } /ws }
+Body = { Section } */ws
+Section = SectionHeader ws! Paragraph*
+SectionHeader = "==" SectionHeaderBody "=="
+SectionHeaderBody = "=" SectionHeaderBody "="
+ > ws! text ws!
+
+sp = " "**
+blank = sp! "\n" sp! "\n" ws!
+
+KeyVal = key:bareword "=" val:text /ws
+wp = w++
+num = [0-9]++
+
+Paragraph = { Blockquote:: "\"\" " text }
+ > HR:: { "---" "-"* }
+ > { OL:: (text &~ (text! ws! {oli}+)) ws! {oli}+ }
+ > P:: { text }
+
+onums = nums (". "|") ")!
+any = ~[]*
+
+uli = "* " (ws! text &~ any (oli|uli)!)
+oli = onums! (ws! text &~ any (oli|uli)!)
+
+text = Item
+
+Item*/ws =
+ blockquote
+// > ^"#" ws! { ~[]* }
+ > Verbatim
+ > InlineGrammar
+ > link
+ > structured
+ > styled
+ > (Chars:: alphanum++)
+ > Quotes:: "\"" text "\""
+ > (Symbol:: sym++)
+ > { Block:: text }
+
+word = Chars:: bareword
+
+blockquote = "adsfafewag"
+//blockquote = Blockquote:: "\"\"" (block | text "\"\"")
+
+Verbatim = "[verbatim]" ws! { (~[])++ }
+
+#import meta.g as meta
+InlineGrammar = "\grammar" ws! { meta.Grammar }
+
+styled = Underline:: "__" text "__"
+ | Footnote:: "((" text "))"
+ | TT:: "[[" text "]]"
+ | Citation:: "[" word "]"
+ | Strikethrough:: "!!" text "!!"
+ | Superscript:: "^^" (word|block)
+ | Subscript:: ",," (word|block)
+ | Smallcap:: "\\sc" block
+ | Bold:: "++" text "++"
+ | Keyword:: "!" (word|block)
+ | Italic:: "**" text "**"
+
+block = { text }
+
+link = text:({ text }|word) "->" ws! href:href
+href = url | email | {href}
+
+structured = command & "\\" ([a-zA-Z0-9]++)! block?
+ > glyph
+ > email
+ > url
+
+glyph = euro:: "(e)"
+ | r:: "(r)"
+ | c:: "(c)"
+ | tm:: "(tm)"
+ | emdash:: "--"
+ | ellipses:: "..."
+ | cent:: "\\cent"
+
+command = "\\" [a-z]++