2 // interactions between !=> and &~ mean that I need to rethink the chartage
3 // indentation styling...
4 // literal blocks [[need to ignore bracing]] double-colon style?
5 // definition -- by prior line indentation, like headings in the original structured text
8 // output formats: latex, contex, ps, pdf, html, man, txt, rfc
16 // "reference-style" links
23 // consider ++bold++ and **italic**?
26 // ellipsis detection (...)
28 // Arrows: <- -> => <= <->
31 // - attention, caution, danger, error, hint, important, note, tip, warning
34 // figure-with-caption
35 // epigraph (end-of-chapter note)
36 // compound paragraph (??)
42 // simple macros (#define) (\define)
45 // table representation
55 // FIXME: these have to go at the top so they have their dropAll bit set before PreSequence.build...
60 //////////////////////////////////////////////////////////////////////////////
64 Doc = {Header} Body /ws => doc
65 Header = "header" { kv */ ws } /ws => header
66 Body = Section*/ws => body
67 Section = { SectionHeader Paragraph* /ws => section }
68 SectionHeader = "==" SectionHeaderBody "=="
69 SectionHeaderBody = "=" SectionHeaderBody "="
73 blank = sp "\n" sp "\n" ws
75 kv = word "=" text /ws => kv1
78 Paragraph = { "\"\"" ws text } => "blockquote"
79 > { "---" "-"* } => "hr"
82 onums ! = nums (". "|") ")
85 uli = "* " (ws text &~ any (oli|uli)) => "li"
86 oli = ("# "|onums) (ws text &~ any (oli|uli)) => "li"
92 > { uli+/ws => "ul" } Itemx => []
93 | { oli+/ws => "ol" } Itemx => []
95 > structured Itemx => []
96 > structuredx Itemx => []
99 > (alphanum++ => stringify) Itemx => []
101 > (sym++ => stringify) Itemx => []
102 > Paragraph Itemx => []
104 blockquote = "\"\"" text "\"\"" => "blockquote"
105 | "\"\"" block => "blockquote"
107 qtext = "\"" text "\"" => "quoted"
108 pre = "[verbatim]" { ~[]+ } /ws => "verbatim" // FIXME doesn't work
110 styled = "__" text "__" => underline
111 | "((" text "))" => footnote
112 | ( "[[" text "]]" => tt
113 > "[" word "]" => citation
115 | "!!" text "!!" => strikethrough
116 | "^^" (word|block) => superscript
117 | ",," (word|block) => subscript
118 | "\\sc" block => smallcap
119 | "**" text "**" => bold
120 | "!" (word|block) => keyword
124 structured = { text } "->" (url|email) => link
125 //> alphanum++ "->" (url|email) => link
130 glyph = "(r)" | "(c)" | "(tm)" | "--" // euro symbol?
131 | "\\today" -> ~[a-z] => today
134 // URLs //////////////////////////////////////////////////////////////////////////////
136 // interesting opportunity to show off boolean grammars here: define other
137 // subtypes of url (ftp, etc) as conjunctions, but the "master pattern"
138 // only gets parsed once
141 username = [a-zA-Z0-9;/?:&=$\-_.+]++ => stringify
142 password = [a-zA-Z0-9;/?:&=$\-_.+]++ => stringify
143 urlchar = [a-zA-Z0-9;/?:&=$\-_.+@]
144 | "%" [0-9] [0-9] => "%"
145 url = "mailto" ":" email
146 > method "://" url_login? host (":" nums)? ("/" urlpath)? => "url"
147 url_login = username (":" password) "@" => "login"
148 method = [+\-.a-z0-9]+ => stringify
149 domain = (part +/ ".") -> ~"." => domain
150 part = [a-zA-Z0-9\-]++ => stringify
151 // interesting use of boolean grammars
152 // &~ ([\-0-9] ~[]* | ~[]* [\-0-9])
154 email = username "@" host -> ~[.] => emailaddr
155 nums = [0-9]++ => stringify
156 host = nums "." nums "." nums "." nums => "ip"
161 // Tokens ///////////////////////////////////////////////////////////////////
163 word = alphanum++ => stringify
166 quoted = "\"" ((~[\"\\] | escaped)+) "\""
168 escaped = "\\n" => "\n"
173 // Chars ///////////////////////////////////////////////////////////////
177 alphanum = [a-zA-Z0-9]
178 sym = ~[a-zA-Z0-9\ \r\n=\">]