checkpoint
[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 ws         = w**
52 w          =  [\r\n\ ]
53 nw         = ~[\r\n\ ]
54
55 //////////////////////////////////////////////////////////////////////////////
56
57 s                   = Doc
58
59 Doc                 = head:Header body:Body  /ws
60 Header              = H:: { "header" { KeyVal */ ws } /ws }
61 Body                = B:: {Section}*/ws
62 Section             = SectionHeader Paragraph* /ws
63 SectionHeader       = "==" SectionHeaderBody "=="
64 SectionHeaderBody   =  "=" SectionHeaderBody "="
65                     >      ws! alphanum++ ws!
66
67 sp       = " "**
68 blank    = sp! "\n" sp! "\n" ws!
69
70 KeyVal       = key:word "=" val:text /ws
71 wp           = w++
72 num          = [0-9]++
73
74 Paragraph   = Blockquote:: { "\"\" "    text }
75             > HR::         { "---" "-"*      }
76             > P::          { text            }
77
78 onums        = nums (". "|") ")!
79 any          = ~[]*
80
81 uli          =  "* "         (ws! text &~ any (oli|uli)!)
82 oli          = ("# "|onums)! (ws! text &~ any (oli|uli)!)
83
84 text         = Item
85 Itemx        = ws! Item
86              | ()
87 Item
88 //*/ws
89      =
90 // "[]":: blockquote                 ((ws! Item) | ())
91 //             >
92  "[]":: { UL:: uli+/ws }           ((ws! Item) | ())
93              | "[]":: { OL:: oli+/ws }           ((ws! Item) | ())
94              > "[]":: pre                        ((ws! Item) | ())
95              > "[]":: link                       ((ws! Item) | ())
96              > "[]":: structured                 ((ws! Item) | ())
97              > "[]":: styled                     ((ws! Item) | ())
98              > "[]":: (Chars:: alphanum++)       ((ws! Item) | ())
99              > "[]":: "\"" text "\""             ((ws! Item) | ())
100              > "[]":: (Symbol:: sym++)           ((ws! Item) | ())
101              > "[]":: { Block:: text }           ((ws! Item) | ())
102
103
104 //blockquote   = Blockquote:: "\"\"" (block | text "\"\"")
105              
106 pre          = Verbatim:: "[verbatim]" { ~[]+ } /ws   // FIXME doesn't work
107
108 styled       = Underline::     "__" text "__"      
109              | Footnote::      "((" text "))"      
110              | TT::            "[[" text "]]"
111              | Citation::       "[" word "]"
112              | Strikethrough:: "!!" text "!!"      
113              | Superscript::   "^^" (word|block)   
114              | Subscript::     ",," (word|block)   
115              | Smallcap::      "\\sc" block        
116              | Bold::           "++" text "++"
117              | Keyword::         "!" (word|block)    
118              | Italic::         "**" text "**"
119
120 block         = { text }
121
122 link          = LinkText:: text:({ text })      "->" href:(url|email)
123               > LinkChars:: text:alphanum++  ws! "->" href:(url|email)
124
125 structured    = command & "\\" ([a-zA-Z0-9]++)! block?
126               > glyph
127               > email
128               > url
129
130 glyph        = Euro:: "(e)" | "(r)" | "(c)" | "(tm)" | emdash:: "--" | "..."
131
132 command      = Today::     "\\today"
133              | LineBreak:: "\\br"
134
135 // URLs //////////////////////////////////////////////////////////////////////////////
136
137 // interesting opportunity to show off boolean grammars here: define other
138 // subtypes of url (ftp, etc) as conjunctions, but the "master pattern"
139 // only gets parsed once
140
141 urlpath      = urlchar*
142 username     = [a-zA-Z0-9;/?:&=$\-_.+]++
143 password     = [a-zA-Z0-9;/?:&=$\-_.+]++
144 urlc         = [a-zA-Z0-9;/?:&=$\-_.+@]
145 urlv         = urlc | [%]
146 urlchar      = urlc
147              | urlescape:: "%" [0-9] [0-9]
148 url          = Mailto:: "mailto" ":"   email -> ~urlv
149              > URL::
150                   method:method 
151                   "://"
152                   login:url_login?
153                   host:host
154                   port:(":" nums)?
155                   path:("/" urlpath)?
156                      -> ~urlv
157 url_login    = Login:: username:username password:(":" password) "@"
158 method       = [+\-.a-z0-9]+
159 domain       = (part +/ ".") -> ~"."
160 part         = [a-zA-Z0-9\-]++
161 // interesting use of boolean grammars
162 //            &~ ([\-0-9] ~[]* | ~[]* [\-0-9])
163
164 email        = user:username "@" host:host -> ~[.]
165 nums         = [0-9]++
166 host         = IP::  nums "." nums "." nums "." nums
167              | DNS:: domain
168
169
170
171 // Tokens ///////////////////////////////////////////////////////////////////
172
173 word       = alphanum++
174            | quoted
175
176 quoted     = "\"" ((~[\"\\] | escaped)+) "\""
177            | "\"\"":: "\"\""
178 escaped    = lf:: "\\n"
179            | cr:: "\\r"
180            | "\\" ~[nr]
181
182
183 // Chars ///////////////////////////////////////////////////////////////
184
185 alpha      = [a-zA-Z]
186 alphanum   = [a-zA-Z0-9]
187 sym        = ~[a-zA-Z0-9\ \r\n=\">]
188
189