a1414d0248177a60a3a583c0554a4142f3ec8db2
[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 ws! body:Body
60 Header              = { "\\header" { KeyVal */ ws } /ws }
61 Body                = { Section } */ws
62 Section             = SectionHeader ws! Paragraph*
63 SectionHeader       = "==" SectionHeaderBody "=="
64 SectionHeaderBody   =  "=" SectionHeaderBody "="
65                     >      ws! alphanum++ ws!
66
67 sp       = " "**
68 blank    = sp! "\n" sp! "\n" ws!
69
70 KeyVal       = key:bareword "=" 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
86 Item*/ws     =
87                blockquote
88              > { UL:: uli+/ws }           
89              | { OL:: oli+/ws }           
90              > Verbatim
91              > link                       
92              > structured                 
93              > styled                     
94              > (Chars:: alphanum++)       
95              > "\"" text "\""             
96              > (Symbol:: sym++)           
97              > { Block:: text }           
98
99 word = Chars:: bareword
100
101 blockquote = "adsfafewag"
102 //blockquote   = Blockquote:: "\"\"" (block | text "\"\"")
103              
104 Verbatim     = "[verbatim]" ws! { (~[])++ }
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          = text:({ text }|word)  "->" href:(url|email)
121
122 structured    = command & "\\" ([a-zA-Z0-9]++)! block?
123               > glyph
124               > email
125               > url
126
127 glyph        = euro::     "(e)"
128              | r::        "(r)"
129              | c::        "(c)"
130              | tm::       "(tm)"
131              | emdash::   "--"
132              | ellipses:: "..."
133              | cent::     "\\cent"
134
135 command      = "\\" [a-z]++
136
137 // URLs //////////////////////////////////////////////////////////////////////////////
138
139 // interesting opportunity to show off boolean grammars here: define other
140 // subtypes of url (ftp, etc) as conjunctions, but the "master pattern"
141 // only gets parsed once
142
143 urlpath      = urlchar* -> ~urlv           // this ~urlv should be handled by url! bug!
144 username     = [a-zA-Z0-9;/?:&=$\-_.+]++
145 password     = [a-zA-Z0-9;/?:&=$\-_.+]++
146 urlc         = [a-zA-Z0-9;/?:&=$\-_.+@]
147 urlv         = urlc | [%]
148 urlchar      = urlc
149              | urlescape:: "%" [0-9] [0-9]
150 url          = Mailto:: "mailto" ":"   email -> ~urlv
151              > URL::
152                   method:method 
153                   "://"
154                   login:url_login?
155                   host:host
156                   port:(":" nums)?
157                   path:("/" urlpath)?
158                      -> ~urlv
159 url_login    = Login:: username:username password:(":" password) "@"
160 method       = [+\-.a-z0-9]+
161 domain       = (part +/ ".") -> ~"."
162 part         = [a-zA-Z0-9\-]++
163 // interesting use of boolean grammars
164 //            &~ ([\-0-9] ~[]* | ~[]* [\-0-9])
165
166 email        = user:username "@" host:host -> ~[.]
167 nums         = [0-9]++
168 host         = IP::  nums "." nums "." nums "." nums
169              | DNS:: domain
170
171
172
173 // Tokens ///////////////////////////////////////////////////////////////////
174
175 bareword   = alphanum++
176            | quoted
177
178 quoted     = "\"" ((~[\"\\] | escaped)+) "\""
179            | "\"\"":: "\"\""
180 escaped    = lf:: "\\n"
181            | cr:: "\\r"
182            | "\\" ~[nr]
183
184
185 // Chars ///////////////////////////////////////////////////////////////
186
187 alpha      = [a-zA-Z]
188 alphanum   = [a-zA-Z0-9]
189 sym        = ~[a-zA-Z0-9\ \r\n=\">]
190 //sym        = [,()]
191
192