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
22 // consider ++bold++ and **italic**?
25 // ellipsis detection (...)
27 // Arrows: <- -> => <= <->
30 // - attention, caution, danger, error, hint, important, note, tip, warning
33 // figure-with-caption
34 // epigraph (end-of-chapter note)
35 // compound paragraph (??)
41 // simple macros (#define) (\define)
44 // table representation
54 // FIXME: these have to go at the top so they have their dropAll bit set before PreSequence.build...
59 //////////////////////////////////////////////////////////////////////////////
63 Doc = doc:: {Header} Body /ws
64 Header = header:: "header" { kv */ ws } /ws
65 Body = body:: Section*/ws
66 Section = { section:: SectionHeader Paragraph* /ws }
67 SectionHeader = "==" SectionHeaderBody "=="
68 SectionHeaderBody = "=" SectionHeaderBody "="
72 blank = !sp "\n" !sp "\n" !ws
74 kv = kv1:: word "=" text /ws
77 Paragraph = blockquote:: { "\"\"" !ws text }
81 onums = nums !(". "|") ")
84 uli = li:: "* " (!ws text &~ any (oli|uli))
85 oli = li:: ("# "|onums) (!ws text &~ any (oli|uli))
93 > "[]":: { ul:: uli+/ws } Itemx
94 | "[]":: { ol:: oli+/ws } Itemx
96 > "[]":: structured Itemx
97 > "[]":: structuredx Itemx
100 > "[]":: (stringify:: alphanum++) Itemx
101 > "[]":: symbol Itemx
102 > "[]":: (stringify:: sym++) Itemx
103 > "[]":: Paragraph Itemx
105 blockquote = blockquote:: "\"\"" text "\"\""
106 | blockquote:: "\"\"" block
108 qtext = quoted:: "\"" text "\""
109 pre = verbatim:: "[verbatim]" { ~[]+ } /ws // FIXME doesn't work
111 styled = underline:: "__" text "__"
112 | footnote:: "((" text "))"
113 | ( tt:: "[[" text "]]"
114 | citation:: "[" text "]"
116 | strikethrough:: "!!" text "!!"
117 | superscript:: "^^" (word|block)
118 | subscript:: ",," (word|block)
119 | smallcap:: "\\sc" block
120 | bold:: "**" text "**"
121 | keyword:: "!" (word|block)
127 structured = link:: { text } "->" (url|email)
128 //> alphanum++ "->" (url|email) => link
133 glyph = "(r)" | "(c)" | "(tm)" | "--" // euro symbol?
134 | today:: "\\today" -> ~[a-z]
137 // URLs //////////////////////////////////////////////////////////////////////////////
139 // interesting opportunity to show off boolean grammars here: define other
140 // subtypes of url (ftp, etc) as conjunctions, but the "master pattern"
141 // only gets parsed once
144 username = stringify:: [a-zA-Z0-9;/?:&=$\-_.+]++
145 password = stringify:: [a-zA-Z0-9;/?:&=$\-_.+]++
146 urlchar = [a-zA-Z0-9;/?:&=$\-_.+@]
147 | "%":: "%" [0-9] [0-9]
148 url = "mailto" ":" email
149 > url:: method "://" url_login? host (":" nums)? ("/" urlpath)?
150 url_login = login:: username (":" password) "@"
151 method = stringify:: [+\-.a-z0-9]+
152 domain = domain:: (part +/ ".") -> ~"."
153 part = stringify:: [a-zA-Z0-9\-]++
154 // interesting use of boolean grammars
155 // &~ ([\-0-9] ~[]* | ~[]* [\-0-9])
157 email = emailaddr:: username "@" host -> ~[.]
158 nums = stringify:: [0-9]++
159 host = ip:: nums "." nums "." nums "." nums
164 // Tokens ///////////////////////////////////////////////////////////////////
166 word = stringify:: alphanum++
169 quoted = "\"" ((~[\"\\] | escaped)+) "\""
171 escaped = "\n":: "\\n"
176 // Chars ///////////////////////////////////////////////////////////////
180 alphanum = [a-zA-Z0-9]
181 sym = ~[a-zA-Z0-9\ \r\n=\">]