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