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...
53 // | "()":: w** "#" (~[\n])* "\n" ws
56 //////////////////////////////////////////////////////////////////////////////
60 Doc = head:Header ws! body:Body
61 Header = { "\\header" { KeyVal */ ws } /ws }
62 Body = { Section } */ws
63 Section = SectionHeader ws! Paragraph*
64 SectionHeader = "==" SectionHeaderBody "=="
65 SectionHeaderBody = "=" SectionHeaderBody "="
69 blank = sp! "\n" sp! "\n" ws!
71 KeyVal = key:bareword "=" val:text /ws
75 Paragraph = { Blockquote:: "\"\" " text }
77 > P:: { UL:: uli+/ws }
78 > P:: { OL:: oli+/ws }
81 onums = nums (". "|") ")!
84 uli = "* " (ws! text &~ any (oli|uli)!)
85 oli = onums! (ws! text &~ any (oli|uli)!)
91 // > ^"#" ws! { ~[]* }
99 > (Chars:: alphanum++)
100 > Quotes:: "\"" text "\""
104 word = Chars:: bareword
106 blockquote = "adsfafewag"
107 //blockquote = Blockquote:: "\"\"" (block | text "\"\"")
109 Verbatim = "[verbatim]" ws! { (~[])++ }
111 #import meta.g as meta
112 InlineGrammar = "\grammar" ws! { meta.Grammar }
114 styled = Underline:: "__" text "__"
115 | Footnote:: "((" text "))"
116 | TT:: "[[" text "]]"
117 | Citation:: "[" word "]"
118 | Strikethrough:: "!!" text "!!"
119 | Superscript:: "^^" (word|block)
120 | Subscript:: ",," (word|block)
121 | Smallcap:: "\\sc" block
122 | Bold:: "++" text "++"
123 | Keyword:: "!" (word|block)
124 | Italic:: "**" text "**"
128 link = text:({ text }|word) "->" ws! href:href
129 href = url | email | {href}
131 structured = command & "\\" ([a-zA-Z0-9]++)! block?
144 command = "\\" [a-z]++
146 // URLs //////////////////////////////////////////////////////////////////////////////
148 // interesting opportunity to show off boolean grammars here: define other
149 // subtypes of url (ftp, etc) as conjunctions, but the "master pattern"
150 // only gets parsed once
152 urlpath = urlchar* -> ~urlv // this ~urlv should be handled by url! bug!
153 username = [a-zA-Z0-9;/?:&=$\-_.+]++
154 password = [a-zA-Z0-9;/?:&=$\-_.+]++
155 urlc = [a-zA-Z0-9;/?:&=$\-_.+@]
158 | urlescape:: "%" [0-9] [0-9]
159 url = Mailto:: "mailto" ":" email -> ~urlv
169 url_login = Login:: username:username password:(":" password) "@"
170 method = [+\-.a-z0-9]+
171 domain = (part +/ ".") -> ~"."
172 part = [a-zA-Z0-9\-]++
173 // interesting use of boolean grammars
174 // &~ ([\-0-9] ~[]* | ~[]* [\-0-9])
176 email = user:username "@" host:host -> ~[.]
178 host = IP:: nums "." nums "." nums "." nums
183 // Tokens ///////////////////////////////////////////////////////////////////
185 bareword = alphanum++
188 quoted = "\"" ((~[\"\\] | escaped)+) "\""
195 // Chars ///////////////////////////////////////////////////////////////
198 alphanum = [a-zA-Z0-9]
199 sym = ~[a-zA-Z0-9\ \r\n=\">]