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         =// "[]":: blockquote                 Itemx
88 //             >
89  "[]":: { UL:: uli+/ws }           Itemx
90              | "[]":: { OL:: oli+/ws }           Itemx
91              > "[]":: pre                        Itemx
92              > "[]":: link                       Itemx
93              > "[]":: structured                 Itemx
94              > "[]":: styled                     Itemx
95              > "[]":: (Chars:: alphanum++)       Itemx
96              > "[]":: "\"" text "\""             Itemx
97              > "[]":: (Symbol:: sym++)           Itemx
98              > "[]":: { Block:: text }           Itemx
99
100 //blockquote   = Blockquote:: "\"\"" (block | text "\"\"")
101              
102 pre          = Verbatim:: "[verbatim]" { ~[]+ } /ws   // FIXME doesn't work
103
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 "**"
115
116 block         = { text }
117
118 link          = LinkText:: text:({ text })      "->" href:(url|email)
119               > LinkChars:: text:alphanum++  ws! "->" href:(url|email)
120
121 structured    = command & "\\" ([a-zA-Z0-9]++)! block?
122               > glyph
123               > email
124               > url
125
126 glyph        = Euro:: "(e)" | "(r)" | "(c)" | "(tm)" | emdash:: "--" | "..."
127
128 command      = Today::     "\\today"
129              | LineBreak:: "\\br"
130
131 // URLs //////////////////////////////////////////////////////////////////////////////
132
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
136
137 urlpath      = urlchar*
138 username     = [a-zA-Z0-9;/?:&=$\-_.+]++
139 password     = [a-zA-Z0-9;/?:&=$\-_.+]++
140 urlc         = [a-zA-Z0-9;/?:&=$\-_.+@]
141 urlv         = urlc | [%]
142 urlchar      = urlc
143              | urlescape:: "%" [0-9] [0-9]
144 url          = Mailto:: "mailto" ":"   email -> ~urlv
145              > URL::
146                   method:method 
147                   "://"
148                   login:url_login?
149                   host:host
150                   port:(":" nums)?
151                   path:("/" urlpath)?
152                      -> ~urlv
153 url_login    = Login:: username:username password:(":" password) "@"
154 method       = [+\-.a-z0-9]+
155 domain       = (part +/ ".") -> ~"."
156 part         = [a-zA-Z0-9\-]++
157 // interesting use of boolean grammars
158 //            &~ ([\-0-9] ~[]* | ~[]* [\-0-9])
159
160 email        = user:username "@" host:host -> ~[.]
161 nums         = [0-9]++
162 host         = IP::  nums "." nums "." nums "." nums
163              | DNS:: domain
164
165
166
167 // Tokens ///////////////////////////////////////////////////////////////////
168
169 word       = alphanum++
170            | quoted
171
172 quoted     = "\"" ((~[\"\\] | escaped)+) "\""
173            | "\"\"":: "\"\""
174 escaped    = lf:: "\\n"
175            | cr:: "\\r"
176            | "\\" ~[nr]
177
178
179 // Chars ///////////////////////////////////////////////////////////////
180
181 alpha      = [a-zA-Z]
182 alphanum   = [a-zA-Z0-9]
183 sym        = ~[a-zA-Z0-9\ \r\n=\">]
184
185