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 > { OL:: (text &~ (text! ws! {oli}+)) ws! {oli}+ }
80 onums = nums (". "|") ")!
83 uli = "* " (ws! text &~ any (oli|uli)!)
84 oli = onums! (ws! text &~ any (oli|uli)!)
90 // > ^"#" ws! { ~[]* }
96 > (Chars:: alphanum++)
97 > Quotes:: "\"" text "\""
101 word = Chars:: bareword
103 blockquote = "adsfafewag"
104 //blockquote = Blockquote:: "\"\"" (block | text "\"\"")
106 Verbatim = "[verbatim]" ws! { (~[])++ }
108 #import meta.g as meta
109 InlineGrammar = "\grammar" ws! { meta.Grammar }
111 styled = Underline:: "__" text "__"
112 | Footnote:: "((" text "))"
113 | TT:: "[[" text "]]"
114 | Citation:: "[" word "]"
115 | Strikethrough:: "!!" text "!!"
116 | Superscript:: "^^" (word|block)
117 | Subscript:: ",," (word|block)
118 | Smallcap:: "\\sc" block
119 | Bold:: "++" text "++"
120 | Keyword:: "!" (word|block)
121 | Italic:: "**" text "**"
125 link = text:({ text }|word) "->" ws! href:href
126 href = url | email | {href}
128 structured = command & "\\" ([a-zA-Z0-9]++)! block?
141 command = "\\" [a-z]++
144 // URLs //////////////////////////////////////////////////////////////////////////////
146 // interesting opportunity to show off boolean grammars here: define other
147 // subtypes of url (ftp, etc) as conjunctions, but the "master pattern"
148 // only gets parsed once
150 urlpath = urlchar* -> ~urlv // this ~urlv should be handled by url! bug!
151 username = [a-zA-Z0-9;/?:&=$\-_.+]++
152 password = [a-zA-Z0-9;/?:&=$\-_.+]++
153 urlc = [a-zA-Z0-9;/?:&=$\-_.+@]
156 | urlescape:: "%" [0-9] [0-9]
157 url = Mailto:: "mailto" ":" email -> ~urlv
167 url_login = Login:: username:username password:(":" password) "@"
168 method = [+\-.a-z0-9]+
169 domain = (part +/ ".") -> ~"."
170 part = [a-zA-Z0-9\-]++
171 // interesting use of boolean grammars
172 // &~ ([\-0-9] ~[]* | ~[]* [\-0-9])
174 email = user:username "@" host:host -> ~[.]
176 host = IP:: nums "." nums "." nums "." nums
181 // Tokens ///////////////////////////////////////////////////////////////////
183 bareword = alphanum++
186 quoted = "\"" ((~[\"\\] | escaped)+) "\""
193 // Chars ///////////////////////////////////////////////////////////////
196 alphanum = [a-zA-Z0-9]
197 sym = ~[a-zA-Z0-9\ \r\n=\">]