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 w          = " " | "\n" | "\r"
52 ws         =  "()":: w**
53 //           |  "()":: w** "#" (~[\n])* "\n" ws
54 nw         = ~[\r\n\ ]
55
56 //////////////////////////////////////////////////////////////////////////////
57
58 s                   = Doc
59
60 Doc                 = head:Header ws! body:Body
61 Header              = { "\\header" { KeyVal */ ws } /ws }
62 Body                = { Section } */ws
63 Section             = SectionHeader ws! Paragraph*
64 SectionHeader       = "==" SectionHeaderBody "=="
65 SectionHeaderBody   =  "=" SectionHeaderBody "="
66                     >      ws! text ws!
67
68 sp       = " "**
69 blank    = sp! "\n" sp! "\n" ws!
70
71 KeyVal       = key:bareword "=" val:text /ws
72 wp           = w++
73 num          = [0-9]++
74
75 Paragraph   = { Blockquote:: "\"\" "    text }
76             > HR::         { "---" "-"*      }
77             > P::          { UL:: uli+/ws }
78             > P::          { OL:: oli+/ws }
79             > P::          { text            }
80
81 onums        = nums (". "|") ")!
82 any          = ~[]*
83
84 uli          =  "* "         (ws! text &~ any (oli|uli)!)
85 oli          = onums!        (ws! text &~ any (oli|uli)!)
86
87 text         = Item
88
89 Item*/ws     =
90                blockquote
91 //             > ^"#" ws! { ~[]* }
92              > { UL:: uli+/ws }           
93              | { OL:: oli+/ws }           
94              > Verbatim
95              > InlineGrammar
96              > link                       
97              > structured                 
98              > styled                     
99              > (Chars:: alphanum++)       
100              > Quotes:: "\"" text "\""         
101              > (Symbol:: sym++)           
102              > { Block:: text }
103
104 word = Chars:: bareword
105
106 blockquote = "adsfafewag"
107 //blockquote   = Blockquote:: "\"\"" (block | text "\"\"")
108              
109 Verbatim      = "[verbatim]" ws! { (~[])++ }
110
111 #import meta.g as meta
112 InlineGrammar = "\grammar"   ws! { meta.Grammar }
113
114 styled       = Underline::     "__" text "__"      
115              | Footnote::      "((" text "))"      
116              | TT::            "[[" text "]]"
117              | Citation::       "[" word "]"
118              | Strikethrough:: "!!" text "!!"      
119              | Superscript::   "^^" (word|block)   
120              | Subscript::     ",," (word|block)   
121              | Smallcap::      "\\sc" block        
122              | Bold::           "++" text "++"
123              | Keyword::         "!" (word|block)    
124              | Italic::         "**" text "**"
125
126 block         = { text }
127
128 link          = text:({ text }|word)  "->" ws! href:href
129 href          = url | email | {href}
130
131 structured    = command & "\\" ([a-zA-Z0-9]++)! block?
132               > glyph
133               > email
134               > url
135
136 glyph        = euro::     "(e)"
137              | r::        "(r)"
138              | c::        "(c)"
139              | tm::       "(tm)"
140              | emdash::   "--"
141              | ellipses:: "..."
142              | cent::     "\\cent"
143
144 command      = "\\" [a-z]++
145
146 // URLs //////////////////////////////////////////////////////////////////////////////
147
148 // interesting opportunity to show off boolean grammars here: define other
149 // subtypes of url (ftp, etc) as conjunctions, but the "master pattern"
150 // only gets parsed once
151
152 urlpath      = urlchar* -> ~urlv           // this ~urlv should be handled by url! bug!
153 username     = [a-zA-Z0-9;/?:&=$\-_.+]++
154 password     = [a-zA-Z0-9;/?:&=$\-_.+]++
155 urlc         = [a-zA-Z0-9;/?:&=$\-_.+@]
156 urlv         = urlc | [%]
157 urlchar      = urlc
158              | urlescape:: "%" [0-9] [0-9]
159 url          = Mailto:: "mailto" ":"   email -> ~urlv
160              > URL::
161                   method:method 
162                   "://"
163                   login:url_login?
164                   host:host
165                   port:(":" nums)?
166                   path:("/" urlpath)?
167                   ref:("#" urlpath)?
168                      -> ~(urlv|[\#])
169 url_login    = Login:: username:username password:(":" password) "@"
170 method       = [+\-.a-z0-9]+
171 domain       = (part +/ ".") -> ~"."
172 part         = [a-zA-Z0-9\-]++
173 // interesting use of boolean grammars
174 //            &~ ([\-0-9] ~[]* | ~[]* [\-0-9])
175
176 email        = user:username "@" host:host -> ~[.]
177 nums         = [0-9]++
178 host         = IP::  nums "." nums "." nums "." nums
179              | DNS:: domain
180
181
182
183 // Tokens ///////////////////////////////////////////////////////////////////
184
185 bareword   = alphanum++
186            | quoted
187
188 quoted     = "\"" ((~[\"\\] | escaped)+) "\""
189            | "\"\"":: "\"\""
190 escaped    = lf:: "\\n"
191            | cr:: "\\r"
192            | "\\" ~[nr]
193
194
195 // Chars ///////////////////////////////////////////////////////////////
196
197 alpha      = [a-zA-Z]
198 alphanum   = [a-zA-Z0-9]
199 sym        = ~[a-zA-Z0-9\ \r\n=\">]
200 //sym        = [,()]
201
202