f012231431997c63bf8898ceb318bc8b40fb1acc
[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
88 Item*/ws     =
89                blockquote
90              > { UL:: uli+/ws }           
91              | { OL:: oli+/ws }           
92              > pre                        
93              > link                       
94              > structured                 
95              > styled                     
96              > (Chars:: alphanum++)       
97              > "\"" text "\""             
98              > (Symbol:: sym++)           
99              > { Block:: text }           
100
101 blockquote = "adsfafewag"
102 //blockquote   = Blockquote:: "\"\"" (block | text "\"\"")
103              
104 pre          = Verbatim:: "[verbatim]" { ~[]+ } /ws   // FIXME doesn't work
105
106 styled       = Underline::     "__" text "__"      
107              | Footnote::      "((" text "))"      
108              | TT::            "[[" text "]]"
109              | Citation::       "[" word "]"
110              | Strikethrough:: "!!" text "!!"      
111              | Superscript::   "^^" (word|block)   
112              | Subscript::     ",," (word|block)   
113              | Smallcap::      "\\sc" block        
114              | Bold::           "++" text "++"
115              | Keyword::         "!" (word|block)    
116              | Italic::         "**" text "**"
117
118 block         = { text }
119
120 link          = LinkText:: text:({ text })      "->" href:(url|email)
121               > LinkChars:: text:alphanum++  ws! "->" href:(url|email)
122
123 structured    = command & "\\" ([a-zA-Z0-9]++)! block?
124               > glyph
125               > email
126               > url
127
128 glyph        = Euro:: "(e)" | "(r)" | "(c)" | "(tm)" | emdash:: "--" | "..."
129
130 command      = Today::     "\\today"
131              | LineBreak:: "\\br"
132
133 // URLs //////////////////////////////////////////////////////////////////////////////
134
135 // interesting opportunity to show off boolean grammars here: define other
136 // subtypes of url (ftp, etc) as conjunctions, but the "master pattern"
137 // only gets parsed once
138
139 urlpath      = urlchar*
140 username     = [a-zA-Z0-9;/?:&=$\-_.+]++
141 password     = [a-zA-Z0-9;/?:&=$\-_.+]++
142 urlc         = [a-zA-Z0-9;/?:&=$\-_.+@]
143 urlv         = urlc | [%]
144 urlchar      = urlc
145              | urlescape:: "%" [0-9] [0-9]
146 url          = Mailto:: "mailto" ":"   email -> ~urlv
147              > URL::
148                   method:method 
149                   "://"
150                   login:url_login?
151                   host:host
152                   port:(":" nums)?
153                   path:("/" urlpath)?
154                      -> ~urlv
155 url_login    = Login:: username:username password:(":" password) "@"
156 method       = [+\-.a-z0-9]+
157 domain       = (part +/ ".") -> ~"."
158 part         = [a-zA-Z0-9\-]++
159 // interesting use of boolean grammars
160 //            &~ ([\-0-9] ~[]* | ~[]* [\-0-9])
161
162 email        = user:username "@" host:host -> ~[.]
163 nums         = [0-9]++
164 host         = IP::  nums "." nums "." nums "." nums
165              | DNS:: domain
166
167
168
169 // Tokens ///////////////////////////////////////////////////////////////////
170
171 word       = alphanum++
172            | quoted
173
174 quoted     = "\"" ((~[\"\\] | escaped)+) "\""
175            | "\"\"":: "\"\""
176 escaped    = lf:: "\\n"
177            | cr:: "\\r"
178            | "\\" ~[nr]
179
180
181 // Chars ///////////////////////////////////////////////////////////////
182
183 alpha      = [a-zA-Z]
184 alphanum   = [a-zA-Z0-9]
185 sym        = ~[a-zA-Z0-9\ \r\n=\">]
186
187