1 // interactions between !=> and &~ mean that I need to rethink the chartage
2 // indentation styling...
3 // literal blocks [[need to ignore bracing]] double-colon style?
4 // definition -- by prior line indentation, like headings in the original structured text
7 // output formats: latex, contex, ps, pdf, html, man, txt, rfc
15 // "reference-style" links
24 // Arrows: <- -> => <= <->
27 // - attention, caution, danger, error, hint, important, note, tip, warning
30 // figure-with-caption
31 // epigraph (end-of-chapter note)
32 // compound paragraph (??)
38 // simple macros (#define) (\define)
40 // table representation
50 // FIXME: these have to go at the top so they have their dropAll bit set before PreSequence.build...
55 //////////////////////////////////////////////////////////////////////////////
59 Doc = Doc:: head:{Header} body:Body /ws
60 Header = Header:: "header" attrs:{ kv */ ws } /ws
61 Body = sections:Section*/ws
62 Section = { section:: SectionHeader Paragraph* /ws }
63 SectionHeader = "==" SectionHeaderBody "=="
64 SectionHeaderBody = "=" SectionHeaderBody "="
68 blank = !sp "\n" !sp "\n" !ws
70 kv = kv:: key:word "=" val:text /ws
73 Paragraph = blockquote:: { "\"\"" !ws text }
77 onums = nums !(". "|") ")
80 uli = li:: "* " (!ws text &~ any (oli|uli))
81 oli = li:: ("# "|onums) (!ws text &~ any (oli|uli))
87 > "[]":: { ul:: uli+/ws } Itemx
88 | "[]":: { ol:: oli+/ws } Itemx
91 > "[]":: structured Itemx
93 > "[]":: (Chars:: alphanum++) Itemx
96 > "[]":: (Symbol:: sym++) Itemx
97 > "[]":: Paragraph Itemx
99 blockquote = blockquote:: "\"\"" text "\"\""
100 | blockquote:: "\"\"" block
102 qtext = quoted:: "\"" text "\""
103 pre = verbatim:: "[verbatim]" { ~[]+ } /ws // FIXME doesn't work
105 styled = underline:: "__" text "__"
106 | footnote:: "((" text "))"
107 | tt:: "[[" text "]]"
108 | citation:: "[" word "]"
109 | strikethrough:: "!!" text "!!"
110 | superscript:: "^^" (word|block)
111 | subscript:: ",," (word|block)
112 | smallcap:: "\\sc" block
113 | bold:: "++" text "++"
114 | keyword:: "!" (word|block)
115 | Italic:: "**" text "**"
119 link = link:: text:({ text }) "->" href:(url|email)
120 > link:: text:alphanum++ !ws "->" href:(url|email)
122 structured = command & "\\" [a-zA-Z0-9]++ block?
127 glyph = euro:: "(e)" | "(r)" | "(c)" | "(tm)" | "--" | "..."
129 command = today:: "\\today"
132 // URLs //////////////////////////////////////////////////////////////////////////////
134 // interesting opportunity to show off boolean grammars here: define other
135 // subtypes of url (ftp, etc) as conjunctions, but the "master pattern"
136 // only gets parsed once
139 username = [a-zA-Z0-9;/?:&=$\-_.+]++
140 password = [a-zA-Z0-9;/?:&=$\-_.+]++
141 urlc = [a-zA-Z0-9;/?:&=$\-_.+@]
144 | "%":: "%" [0-9] [0-9]
145 url = "mailto" ":" email -> ~urlv
146 > method:method "://" url_login? host:host port:(":" nums)? path:("/" urlpath)? -> ~urlv
147 url_login = login:: username (":" password) "@"
148 method = [+\-.a-z0-9]+
149 domain = (part +/ ".") -> ~"."
150 part = [a-zA-Z0-9\-]++
151 // interesting use of boolean grammars
152 // &~ ([\-0-9] ~[]* | ~[]* [\-0-9])
154 email = user:username "@" host:host -> ~[.]
156 host = IP:: nums "." nums "." nums "." nums
161 // Tokens ///////////////////////////////////////////////////////////////////
166 quoted = "\"" ((~[\"\\] | escaped)+) "\""
168 escaped = "\n":: "\\n"
173 // Chars ///////////////////////////////////////////////////////////////
177 alphanum = [a-zA-Z0-9]
178 sym = ~[a-zA-Z0-9\ \r\n=\">]