// [1] http://...
//
-// consider ++bold++ and **italic**?
-// \br
// nonbreaking text?
-// ellipsis detection (...)
// degree: 15^o
// Arrows: <- -> => <= <->
// #include
// simple macros (#define) (\define)
-// today's date
// table representation
//
//////////////////////////////////////////////////////////////////////////////
-s = top:: Doc
+s = Doc
-Doc = doc:: {Header} Body /ws
-Header = header:: "header" { kv */ ws } /ws
-Body = body:: Section*/ws
-Section = { section:: SectionHeader Paragraph* /ws }
+Doc = head:{Header} body:Body /ws
+Header = "header" attrs:{ KeyVal */ ws } /ws
+Body = {Section}*/ws
+Section = SectionHeader Paragraph* /ws
SectionHeader = "==" SectionHeaderBody "=="
SectionHeaderBody = "=" SectionHeaderBody "="
- > !ws text !ws
+ > !ws alphanum++ !ws
sp = " "**
blank = !sp "\n" !sp "\n" !ws
-kv = kv1:: word "=" text /ws
+KeyVal = key:word "=" val:text /ws
wp = w++
num = [0-9]++
-Paragraph = blockquote:: { "\"\"" !ws text }
- > hr:: { "---" "-"* }
- > p:: { text }
+
+Paragraph = Blockquote:: { "\"\" " text }
+ > HR:: { "---" "-"* }
+ > P:: { text }
onums = nums !(". "|") ")
any = ~[]*
-uli = li:: "* " (!ws text &~ any (oli|uli))
-oli = li:: ("# "|onums) (!ws text &~ any (oli|uli))
-
-//
+uli = "* " (!ws text &~ any !(oli|uli))
+oli = !("# "|onums) (!ws text &~ any !(oli|uli))
-text = text:: Item
+text = Item
Itemx = !ws Item
| ()
-Item = blockquote
- > "[]":: { ul:: uli+/ws } Itemx
- | "[]":: { ol:: oli+/ws } Itemx
- > "[]":: pre Itemx
- > "[]":: structured Itemx
- > "[]":: structuredx Itemx
- > "[]":: styled Itemx
- > "[]":: qtext Itemx
- > "[]":: (stringify:: alphanum++) Itemx
- > "[]":: symbol Itemx
- > "[]":: (stringify:: sym++) Itemx
- > "[]":: Paragraph Itemx
-
-blockquote = blockquote:: "\"\"" text "\"\""
- | blockquote:: "\"\"" block
+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 "\"\"")
-qtext = quoted:: "\"" 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)
- > it:: "*" text "*"
-
-//
-
-block = { text }
-structured = link:: { text } "->" (url|email)
- //> alphanum++ "->" (url|email) => link
-structuredx = glyph
+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 = "(r)" | "(c)" | "(tm)" | "--" // euro symbol?
- | today:: "\\today" -> ~[a-z]
+glyph = Euro:: "(e)" | "(r)" | "(c)" | "(tm)" | emdash:: "--" | "..."
+command = Today:: "\\today"
+ | LineBreak:: "\\br"
// URLs //////////////////////////////////////////////////////////////////////////////
// only gets parsed once
urlpath = urlchar*
-username = stringify:: [a-zA-Z0-9;/?:&=$\-_.+]++
-password = stringify:: [a-zA-Z0-9;/?:&=$\-_.+]++
-urlchar = [a-zA-Z0-9;/?:&=$\-_.+@]
- | "%":: "%" [0-9] [0-9]
-url = "mailto" ":" email
- > url:: method "://" url_login? host (":" nums)? ("/" urlpath)?
-url_login = login:: username (":" password) "@"
-method = stringify:: [+\-.a-z0-9]+
-domain = domain:: (part +/ ".") -> ~"."
-part = stringify:: [a-zA-Z0-9\-]++
+username = [a-zA-Z0-9;/?:&=$\-_.+]++
+password = [a-zA-Z0-9;/?:&=$\-_.+]++
+urlc = [a-zA-Z0-9;/?:&=$\-_.+@]
+urlv = urlc | [%]
+urlchar = urlc
+ | urlescape:: "%" [0-9] [0-9]
+url = Mailto:: "mailto" ":" email -> ~urlv
+ > URL::
+ method:method
+ "://"
+ login:url_login?
+ host:host
+ port:(":" nums)?
+ path:("/" urlpath)?
+ -> ~urlv
+url_login = Login:: username:username password:(":" password) "@"
+method = [+\-.a-z0-9]+
+domain = (part +/ ".") -> ~"."
+part = [a-zA-Z0-9\-]++
// interesting use of boolean grammars
// &~ ([\-0-9] ~[]* | ~[]* [\-0-9])
-email = emailaddr:: username "@" host -> ~[.]
-nums = stringify:: [0-9]++
-host = ip:: nums "." nums "." nums "." nums
- | domain
+email = Email:: user:username "@" host:host -> ~[.]
+nums = [0-9]++
+host = IP:: nums "." nums "." nums "." nums
+ | DNS:: domain
// Tokens ///////////////////////////////////////////////////////////////////
-word = stringify:: alphanum++
+word = alphanum++
| quoted
quoted = "\"" ((~[\"\\] | escaped)+) "\""
- | "":: "\"\""
-escaped = "\n":: "\\n"
- | "\r":: "\\r"
+ | "\"\"":: "\"\""
+escaped = lf:: "\\n"
+ | cr:: "\\r"
| "\\" ~[nr]
// Chars ///////////////////////////////////////////////////////////////
alpha = [a-zA-Z]
-//num = [0-9]
alphanum = [a-zA-Z0-9]
sym = ~[a-zA-Z0-9\ \r\n=\">]