added stuff to TibDoc
[sbp.git] / tests / tibdoc.g
1
2 // URGENT: why does swapping [a-zA-Z0-9] for alphanum in "item" cause severe breakage?
3 // URGENT: why does enabling "url" cause severe breakage? (probably same cause)
4 //   ... something to do with unit productions
5
6
7
8 // output formats: latex, contex, ps, pdf, html, man, txt, rfc
9 // bullet list
10 // numbered list
11 // horizontal rule
12 // dropcap
13 // smallcap
14 // strikethrough
15 // link
16 // math
17 // image
18 // today's date, last edit date
19 // blockquote
20 // superscript
21 // subscript
22 // citations/references
23 // typewriter-text
24 // figures
25
26 // FIXME: these have to go at the top so they have their dropAll bit set before PreSequence.build...
27 ws      !::= w**
28 w       !::=  [\r\n\ ]
29 nw       ::= [~\r\n\ ]
30
31 //////////////////////////////////////////////////////////////////////////////
32
33 s                 ::= {Doc} => top
34
35 Doc               ::= Header   Body                       /ws => doc
36 Header            ::= "header" { kv */ ws }               /ws => header
37 Body              ::= Section*/ws                             => body
38 Section           ::= SectionHeader ({text}*/ws)          /ws => section
39 SectionHeader     ::= "==" SectionHeaderBody "=="
40 SectionHeaderBody ::=  "=" SectionHeaderBody "="
41                     >      ws text ws
42
43 kv         ::= word "=" text /ws => kv1
44
45 text       ::= item */ ws
46 pre        ::= "[verbatim]" { [~]+ } /ws => "verbatim"   // FIXME doesn't work
47 item       ::= pre
48              > email
49              > structured
50              > styled
51              > "\"" text "\""    => quoted
52              > [a-zA-Z0-9]++
53              > symbol
54
55 symbol     ::= symbolx & sym++
56 symbolx    ::= "--"  => emdash
57              | ","
58              | ":"
59              | ";"
60
61 styled     ::= "**" text "**" => bold
62              | "__" text "__" => ul
63              | "~~" text "~~" => it     // hard to type
64              | "((" text "))" => footnote
65
66 structured ::= glyph
67 //             | url
68
69 glyph      ::= "(r)" | "(c)" | "(tm)"  // euro symbol?
70
71
72 // URLs //////////////////////////////////////////////////////////////////////////////
73
74 // interesting opportunity to show off boolean grammars here: define other
75 // subtypes of url (ftp, etc) as conjunctions, but the "master pattern"
76 // only gets parsed once
77
78 urlpath    ::= urlchar*
79 username   ::= [a-zA-Z0-9;/?:&=$\-_.+]++
80 password   ::= [a-zA-Z0-9;/?:&=$\-_.+]++
81 urlchar    ::= [a-zA-Z0-9;/?:&=$\-_.+@]
82              | "%" [0-9] [0-9]       => "%"
83 url        ::= "mailto" ":"   email
84              > method "://" url_login? host (":" port)? ("/" urlpath)?     => "url"
85 url_login  ::= username (":" password) "@" => "login"
86 method     ::= [+\-.a-z0-9]+ 
87 port       ::= [0-9]+
88
89 domain     ::= part +/ "."
90 part       ::= [a-zA-Z0-9\-]++    // interesting use of boolean grammars
91 //            &~ ([\-0-9] [~]* | [~]* [\-0-9])
92
93 email      ::= username "@" host      => email
94 host       ::= [0-9]+ "." [0-9]+ "." [0-9]+ "." [0-9]+ => "ip"
95              | domain
96
97
98
99 // Tokens ///////////////////////////////////////////////////////////////////
100
101 word     ::= alphanum++
102            | quoted
103
104 quoted   ::= "\"" (([~\"\\] | escaped)+) "\""
105            | "\"\"" => ""
106 escaped  ::= "\\n" => "\n"
107            | "\\r" => "\r"
108            | "\\" [~nr]
109
110
111 // Chars ///////////////////////////////////////////////////////////////
112
113 alpha    ::= [a-zA-Z]
114 num      ::= [0-9]
115 alphanum ::= [a-zA-Z0-9]
116 sym      ::= [~a-zA-Z0-9\ \r\n]
117
118