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