-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} body:Body /ws
+Header = "header" attrs:{ KeyVal */ ws } /ws
+Body = {Section}*/ws
+Section = SectionHeader Paragraph* /ws
+SectionHeader = "==" SectionHeaderBody "=="
+SectionHeaderBody = "=" SectionHeaderBody "="
+ > !ws alphanum++ !ws
+
+sp = " "**
+blank = !sp "\n" !sp "\n" !ws
+
+KeyVal = key:word "=" val:text /ws
+wp = w++
+num = [0-9]++
+
+Paragraph = Blockquote:: { "\"\" " text }
+ > HR:: { "---" "-"* }
+ > P:: { text }
+
+onums = nums !(". "|") ")
+any = ~[]*
+
+uli = "* " (!ws text &~ any !(oli|uli))
+oli = !("# "|onums) (!ws text &~ any !(oli|uli))
+
+text = Item
+Itemx = !ws Item
+ | ()
+Item = "[]":: blockquote Itemx
+ > "[]":: { UL:: uli+/ws } Itemx
+ | "[]":: { OL:: oli+/ws } Itemx
+ > "[]":: pre Itemx
+ > "[]":: link Itemx
+ > "[]":: structured Itemx
+ > "[]":: styled Itemx
+ > "[]":: (Chars:: alphanum++) Itemx
+ > "[]":: "\"" text "\"" Itemx
+ > "[]":: (Symbol:: sym++) Itemx
+ > "[]":: { Block:: text } Itemx
+
+blockquote = Blockquote:: "\"\"" (block | text "\"\"")
+
+pre = Verbatim:: "[verbatim]" { ~[]+ } /ws // FIXME doesn't work
+
+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 = LinkText:: text:({ text }) "->" href:(url|email)
+ > LinkChars:: text:alphanum++ !ws "->" href:(url|email)
+
+structured = command & "\\" !([a-zA-Z0-9]++) block?
+ > glyph
+ > email
+ > url
+
+glyph = Euro:: "(e)" | "(r)" | "(c)" | "(tm)" | emdash:: "--" | "..."
+
+command = Today:: "\\today"
+ | LineBreak:: "\\br"