4a57992c91a84656583c074375a770fd63d62975
[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 // consider ++bold++ and **italic**?
23 // \br
24 // nonbreaking text?
25 // ellipsis detection (...)
26 // degree: 15^o
27 // Arrows: <- -> => <= <->
28
29 // textblocks:
30 //  - attention, caution, danger, error, hint, important, note, tip, warning
31 // definition
32 // sidebar
33 // figure-with-caption
34 // epigraph (end-of-chapter note)
35 // compound paragraph (??)
36 // csv-table?
37 // table of contents
38 // header, footer
39 // #include
40
41 // simple macros (#define) (\define)
42 // today's date
43
44 // table representation
45 //  
46 //  \table
47 //     a bbb c
48 //     ddd   e
49 //
50 //     [a] ...
51 //     [b] ...
52 //     [c] ...
53
54 // FIXME: these have to go at the top so they have their dropAll bit set before PreSequence.build...
55 ws         = w**
56 w          =  [\r\n\ ]
57 nw         = ~[\r\n\ ]
58
59 //////////////////////////////////////////////////////////////////////////////
60
61 s                   = top:: Doc
62
63 Doc                 = doc::    {Header} Body                   /ws
64 Header              = header:: "header" { kv */ ws }           /ws
65 Body                = body::   Section*/ws
66 Section             = { section:: SectionHeader Paragraph* /ws }
67 SectionHeader       = "==" SectionHeaderBody "=="
68 SectionHeaderBody   =  "=" SectionHeaderBody "="
69                     >      !ws text !ws
70
71 sp       = " "**
72 blank    = !sp "\n" !sp "\n" !ws
73
74 kv           = kv1:: word "=" text /ws
75 wp           = w++
76 num          = [0-9]++
77 Paragraph    = blockquote:: { "\"\"" !ws  text }
78              > hr::         { "---" "-"*      }
79              > p::          { text }
80
81 onums        = nums !(". "|") ")
82 any          = ~[]*
83
84 uli          = li:: "* "          (!ws text &~ any (oli|uli))
85 oli          = li:: ("# "|onums) (!ws text &~ any (oli|uli))
86
87 //
88
89 text         = text:: Item
90 Itemx        = !ws Item
91              | ()
92 Item         = blockquote
93              > "[]":: { ul:: uli+/ws }          Itemx
94              | "[]":: { ol:: oli+/ws }          Itemx
95              > "[]":: pre                       Itemx
96              > "[]":: structured                Itemx
97              > "[]":: structuredx               Itemx
98              > "[]":: styled                    Itemx
99              > "[]":: qtext                     Itemx
100              > "[]":: (stringify:: alphanum++)  Itemx
101              > "[]":: symbol                    Itemx
102              > "[]":: (stringify:: sym++)       Itemx
103              > "[]":: Paragraph                 Itemx
104
105 blockquote   = blockquote:: "\"\"" text "\"\""
106              | blockquote:: "\"\"" block
107              
108 qtext        = quoted:: "\"" text "\""
109 pre          = verbatim:: "[verbatim]" { ~[]+ } /ws   // FIXME doesn't work
110
111 styled       = underline:: "__" text "__"      
112              | footnote:: "((" text "))"      
113              | ( tt:: "[[" text "]]"    
114              | citation::   "[" text "]"     
115                )
116              | strikethrough:: "!!" text "!!"      
117              | superscript:: "^^" (word|block)   
118              | subscript:: ",," (word|block)   
119              | smallcap:: "\\sc" block        
120              | bold:: "**" text "**"      
121              | keyword:: "!" (word|block)    
122              > it:: "*" text "*"
123
124 //
125
126 block   = { text }
127 structured   = link:: { text } "->" (url|email)
128               //> alphanum++ "->" (url|email) => link
129 structuredx   = glyph
130               > email
131               > url
132
133 glyph        = "(r)" | "(c)" | "(tm)" | "--"  // euro symbol?
134              | today:: "\\today" -> ~[a-z]
135
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*
144 username     = stringify:: [a-zA-Z0-9;/?:&=$\-_.+]++
145 password     = stringify:: [a-zA-Z0-9;/?:&=$\-_.+]++
146 urlchar      = [a-zA-Z0-9;/?:&=$\-_.+@]
147              | "%":: "%" [0-9] [0-9]
148 url          = "mailto" ":"   email
149              > url::   method "://" url_login? host (":" nums)? ("/" urlpath)?
150 url_login    = login:: username (":" password) "@"
151 method       = stringify:: [+\-.a-z0-9]+
152 domain       = domain:: (part +/ ".") -> ~"."
153 part         = stringify:: [a-zA-Z0-9\-]++
154 // interesting use of boolean grammars
155 //            &~ ([\-0-9] ~[]* | ~[]* [\-0-9])
156
157 email        = emailaddr:: username "@" host -> ~[.]
158 nums         = stringify:: [0-9]++
159 host         = ip:: nums "." nums "." nums "." nums
160              | domain
161
162
163
164 // Tokens ///////////////////////////////////////////////////////////////////
165
166 word       = stringify:: alphanum++
167            | quoted
168
169 quoted     = "\"" ((~[\"\\] | escaped)+) "\""
170            | "":: "\"\""
171 escaped    = "\n":: "\\n"
172            | "\r":: "\\r"
173            | "\\" ~[nr]
174
175
176 // Chars ///////////////////////////////////////////////////////////////
177
178 alpha      = [a-zA-Z]
179 //num        = [0-9]
180 alphanum   = [a-zA-Z0-9]
181 sym        = ~[a-zA-Z0-9\ \r\n=\">]
182
183