update TODO
[sbp.git] / tests / tibdoc.g
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
5 // tables
6 // dropcap
7 // output formats: latex, contex, ps, pdf, html, man, txt, rfc
8
9 // escapification
10 // comment
11 // math
12 // image
13 // figures
14
15 // "reference-style" links
16 //
17 //   this[1] is fun
18 //
19 //   [1] http://...
20 //
21
22 // nonbreaking text?
23 // degree: 15^o
24 // Arrows: <- -> => <= <->
25
26 // textblocks:
27 //  - attention, caution, danger, error, hint, important, note, tip, warning
28 // definition
29 // sidebar
30 // figure-with-caption
31 // epigraph (end-of-chapter note)
32 // compound paragraph (??)
33 // csv-table?
34 // table of contents
35 // header, footer
36 // #include
37
38 // simple macros (#define) (\define)
39
40 // table representation
41 //  
42 //  \table
43 //     a bbb c
44 //     ddd   e
45 //
46 //     [a] ...
47 //     [b] ...
48 //     [c] ...
49
50 // FIXME: these have to go at the top so they have their dropAll bit set before PreSequence.build...
51 w          = " " | "\n" | "\r"
52 ws         =  "()":: w**
53 //           |  "()":: w** "#" (~[\n])* "\n" ws
54 nw         = ~[\r\n\ ]
55
56 //////////////////////////////////////////////////////////////////////////////
57
58 s                   = Doc
59
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 "="
66                     >      ws! text ws!
67
68 sp       = " "**
69 blank    = sp! "\n" sp! "\n" ws!
70
71 KeyVal       = key:bareword "=" val:text /ws
72 wp           = w++
73 num          = [0-9]++
74
75 Paragraph   = { Blockquote:: "\"\" "    text }
76             > HR::         { "---" "-"*      }
77             >         { OL:: (text &~ (text! ws! {oli}+)) ws! {oli}+  }
78             > P::          { text          }
79
80 onums        = nums (". "|") ")!
81 any          = ~[]*
82
83 uli          =  "* "         (ws! text &~ any (oli|uli)!)
84 oli          = onums!        (ws! text &~ any (oli|uli)!)
85
86 text         = Item
87
88 Item*/ws     =
89                blockquote
90 //             > ^"#" ws! { ~[]* }
91              > Verbatim
92              > InlineGrammar
93              > link                       
94              > structured                 
95              > styled                     
96              > (Chars:: alphanum++)       
97              > Quotes:: "\"" text "\""         
98              > (Symbol:: sym++)           
99              > { Block:: text }
100
101 word = Chars:: bareword
102
103 blockquote = "adsfafewag"
104 //blockquote   = Blockquote:: "\"\"" (block | text "\"\"")
105              
106 Verbatim      = "[verbatim]" ws! { (~[])++ }
107
108 #import meta.g as meta
109 InlineGrammar = "\grammar"   ws! { meta.Grammar }
110
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 "**"
122
123 block         = { text }
124
125 link          = text:({ text }|word)  "->" ws! href:href
126 href          = url | email | {href}
127
128 structured    = command & "\\" ([a-zA-Z0-9]++)! block?
129               > glyph
130               > email
131               > url
132
133 glyph        = euro::     "(e)"
134              | r::        "(r)"
135              | c::        "(c)"
136              | tm::       "(tm)"
137              | emdash::   "--"
138              | ellipses:: "..."
139              | cent::     "\\cent"
140
141 command      = "\\" [a-z]++
142
143
144 // URLs //////////////////////////////////////////////////////////////////////////////
145
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
149
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;/?:&=$\-_.+@]
154 urlv         = urlc | [%]
155 urlchar      = urlc
156              | urlescape:: "%" [0-9] [0-9]
157 url          = Mailto:: "mailto" ":"   email -> ~urlv
158              > URL::
159                   method:method 
160                   "://"
161                   login:url_login?
162                   host:host
163                   port:(":" nums)?
164                   path:("/" urlpath)?
165                   ref:("#" urlpath)?
166                      -> ~(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])
173
174 email        = user:username "@" host:host -> ~[.]
175 nums         = [0-9]++
176 host         = IP::  nums "." nums "." nums "." nums
177              | DNS:: domain
178
179
180
181 // Tokens ///////////////////////////////////////////////////////////////////
182
183 bareword   = alphanum++
184            | quoted
185
186 quoted     = "\"" ((~[\"\\] | escaped)+) "\""
187            | "\"\"":: "\"\""
188 escaped    = lf:: "\\n"
189            | cr:: "\\r"
190            | "\\" ~[nr]
191
192
193 // Chars ///////////////////////////////////////////////////////////////
194
195 alpha      = [a-zA-Z]
196 alphanum   = [a-zA-Z0-9]
197 sym        = ~[a-zA-Z0-9\ \r\n=\">]
198 //sym        = [,()]
199
200