7841855bf13bbbafab769f6ab9b70341fca04f1e
[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                 = Doc:: head:{Header} body:Body   /ws
60 Header              = Header:: "header" attrs:{ kv */ ws }     /ws
61 Body                = sections:Section*/ws
62 Section             = { section:: SectionHeader Paragraph* /ws }
63 SectionHeader       = "==" SectionHeaderBody "=="
64 SectionHeaderBody   =  "=" SectionHeaderBody "="
65                     >      !ws text !ws
66
67 sp       = " "**
68 blank    = !sp "\n" !sp "\n" !ws
69
70 kv           = kv:: key:word "=" val:text /ws
71 wp           = w++
72 num          = [0-9]++
73 Paragraph    = blockquote:: { "\"\"" !ws  text }
74              > hr::         { "---" "-"*      }
75              > p::          { text }
76
77 onums        = nums !(". "|") ")
78 any          = ~[]*
79
80 uli          = li:: "* "         (!ws text &~ any (oli|uli))
81 oli          = li:: ("# "|onums) (!ws text &~ any (oli|uli))
82
83 text         = Item
84 Itemx        = !ws Item
85              | ()
86 Item         = blockquote
87              > "[]":: { ul:: uli+/ws }          Itemx
88              | "[]":: { ol:: oli+/ws }          Itemx
89              > "[]":: pre                       Itemx
90              > "[]":: link                      Itemx
91              > "[]":: structured                Itemx
92              > "[]":: styled                    Itemx
93              > "[]":: (Chars:: alphanum++)      Itemx
94              > "[]":: qtext                     Itemx
95              > "[]":: symbol                    Itemx
96              > "[]":: (Symbol:: sym++)          Itemx
97              > "[]":: Paragraph                 Itemx
98
99 blockquote   = blockquote:: "\"\"" text "\"\""
100              | blockquote:: "\"\"" block
101              
102 qtext        = quoted:: "\"" text "\""
103 pre          = verbatim:: "[verbatim]" { ~[]+ } /ws   // FIXME doesn't work
104
105 styled       = underline::     "__" text "__"      
106              | footnote::      "((" text "))"      
107              | tt::            "[[" text "]]"
108              | citation::       "[" word "]"
109              | strikethrough:: "!!" text "!!"      
110              | superscript::   "^^" (word|block)   
111              | subscript::     ",," (word|block)   
112              | smallcap::      "\\sc" block        
113              | bold::           "++" text "++"
114              | keyword::         "!" (word|block)    
115              | Italic::         "**" text "**"
116
117 block         = { text }
118
119 link          = link:: text:({ text })     "->" href:(url|email)
120               > link:: text:alphanum++ !ws "->" href:(url|email)
121
122 structured    = command & "\\" [a-zA-Z0-9]++ block?
123               > glyph
124               > email
125               > url
126
127 glyph        = euro:: "(e)" | "(r)" | "(c)" | "(tm)" | "--" | "..."
128
129 command      = today:: "\\today"
130              | bre::   "\\br"
131
132 // URLs //////////////////////////////////////////////////////////////////////////////
133
134 // interesting opportunity to show off boolean grammars here: define other
135 // subtypes of url (ftp, etc) as conjunctions, but the "master pattern"
136 // only gets parsed once
137
138 urlpath      = urlchar*
139 username     = [a-zA-Z0-9;/?:&=$\-_.+]++
140 password     = [a-zA-Z0-9;/?:&=$\-_.+]++
141 urlc         = [a-zA-Z0-9;/?:&=$\-_.+@]
142 urlv         = urlc | [%]
143 urlchar      = urlc
144              | "%":: "%" [0-9] [0-9]
145 url          = "mailto" ":"   email -> ~urlv
146              > method:method "://" url_login? host:host port:(":" nums)? path:("/" urlpath)? -> ~urlv
147 url_login    = login:: username (":" password) "@"
148 method       = [+\-.a-z0-9]+
149 domain       = (part +/ ".") -> ~"."
150 part         = [a-zA-Z0-9\-]++
151 // interesting use of boolean grammars
152 //            &~ ([\-0-9] ~[]* | ~[]* [\-0-9])
153
154 email        = user:username "@" host:host -> ~[.]
155 nums         = [0-9]++
156 host         = IP::  nums "." nums "." nums "." nums
157              | DNS:: domain
158
159
160
161 // Tokens ///////////////////////////////////////////////////////////////////
162
163 word       = alphanum++
164            | quoted
165
166 quoted     = "\"" ((~[\"\\] | escaped)+) "\""
167            | "":: "\"\""
168 escaped    = "\n":: "\\n"
169            | "\r":: "\\r"
170            | "\\" ~[nr]
171
172
173 // Chars ///////////////////////////////////////////////////////////////
174
175 alpha      = [a-zA-Z]
176 //num        = [0-9]
177 alphanum   = [a-zA-Z0-9]
178 sym        = ~[a-zA-Z0-9\ \r\n=\">]
179
180