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 = Body:: sections:(Section*/ws)
62 Section = { Section:: header:SectionHeader paragraphs:Paragraph* /ws }
63 SectionHeader = "==" SectionHeaderBody "=="
64 SectionHeaderBody = "=" SectionHeaderBody "="
65 > !ws (Chars:: text:alphanum++) !ws
68 blank = !sp "\n" !sp "\n" !ws
70 kv = kv:: key:word "=" val:text /ws
73 Paragraph = Blockquote:: { "\"\" " text }
77 onums = nums !(". "|") ")
80 uli = "* " (!ws text &~ any (oli|uli))
81 oli = !("# "|onums) (!ws text &~ any (oli|uli))
87 > "[]":: { UL:: uli+/ws } Itemx
88 | "[]":: { OL:: oli+/ws } Itemx
91 > "[]":: structured Itemx
93 > "[]":: (Chars:: text:alphanum++) Itemx
94 > "[]":: "\"" text "\"" Itemx
96 > "[]":: (Symbol:: sym++) Itemx
97 > "[]":: Paragraph Itemx
99 blockquote = Blockquote:: "\"\"" text "\"\""
100 | Blockquote:: "\"\"" block
102 pre = Verbatim:: "[verbatim]" { ~[]+ } /ws // FIXME doesn't work
104 styled = Underline:: "__" text "__"
105 | Footnote:: "((" text "))"
106 | TT:: "[[" text "]]"
107 | Citation:: "[" word "]"
108 | Strikethrough:: "!!" text "!!"
109 | Superscript:: "^^" (word|block)
110 | Subscript:: ",," (word|block)
111 | Smallcap:: "\\sc" block
112 | Bold:: "++" text "++"
113 | Keyword:: "!" (word|block)
114 | Italic:: "**" text "**"
118 link = Link:: text:({ text }) "->" href:(url|email)
119 > Link:: text:alphanum++ !ws "->" href:(url|email)
121 structured = command & "\\" [a-zA-Z0-9]++ block?
126 glyph = Euro:: "(e)" | "(r)" | "(c)" | "(tm)" | emdash:: "--" | "..."
128 command = Today:: "\\today"
131 // URLs //////////////////////////////////////////////////////////////////////////////
133 // interesting opportunity to show off boolean grammars here: define other
134 // subtypes of url (ftp, etc) as conjunctions, but the "master pattern"
135 // only gets parsed once
138 username = [a-zA-Z0-9;/?:&=$\-_.+]++
139 password = [a-zA-Z0-9;/?:&=$\-_.+]++
140 urlc = [a-zA-Z0-9;/?:&=$\-_.+@]
143 | urlescape:: "%" [0-9] [0-9]
144 url = "mailto" ":" email -> ~urlv
145 > URL:: method:method "://" login:url_login? host:host port:(":" nums)? path:("/" urlpath)? -> ~urlv
146 url_login = Login:: username:username password:(":" password) "@"
147 method = [+\-.a-z0-9]+
148 domain = (part +/ ".") -> ~"."
149 part = [a-zA-Z0-9\-]++
150 // interesting use of boolean grammars
151 // &~ ([\-0-9] ~[]* | ~[]* [\-0-9])
153 email = Email:: user:username "@" host:host -> ~[.]
155 host = IP:: nums "." nums "." nums "." nums
160 // Tokens ///////////////////////////////////////////////////////////////////
165 quoted = "\"" ((~[\"\\] | escaped)+) "\""
172 // Chars ///////////////////////////////////////////////////////////////
176 alphanum = [a-zA-Z0-9]
177 sym = ~[a-zA-Z0-9\ \r\n=\">]