99bab8349118b1c9a94d930b941e5f342a742cbe
[sbp.git] / tests / tibdoc.g
1 x::="x"
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 // URGENT: why does swapping [a-zA-Z0-9] for alphanum in "item" cause severe breakage?
10 // URGENT: why does enabling "url" cause severe breakage? (probably same cause)
11 //   ... something to do with unit productions
12
13 // output formats: latex, contex, ps, pdf, html, man, txt, rfc
14 // bullet list
15 // numbered list
16 // horizontal rule
17 // dropcap
18 // smallcap
19 // strikethrough
20 // link
21 // math
22 // image
23 // today's date, last edit date
24 // blockquote
25 // superscript
26 // subscript
27 // citations/references
28 // typewriter-text
29 // figures
30
31 // FIXME: these have to go at the top so they have their dropAll bit set before PreSequence.build...
32 ws      !::= w**
33 w       !::=  [\r\n\ ]
34 nw       ::= ~[\r\n\ ]
35
36 //////////////////////////////////////////////////////////////////////////////
37
38 s                 ::= { Doc } => "top"
39
40 Doc               ::= Header   Body                       /ws => doc
41 Header            ::= "header" { kv */ ws }               /ws => header
42 Body              ::= Section*/ws                             => body
43 Section           ::= SectionHeader Paragraph*/ws         /ws => section
44 SectionHeader     ::= "==" SectionHeaderBody "=="
45 SectionHeaderBody ::=  "=" SectionHeaderBody "="
46                     >      ws text ws
47
48 kv         ::= word "=" text /ws => kv1
49
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              > alphanum++        => "stringify"
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;/?:&=$\-_.+]++ => "stringify"
92 password   ::= [a-zA-Z0-9;/?:&=$\-_.+]++ => "stringify"
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\-]++ => "stringify"
103 //            &~ ([\-0-9] ~[]* | ~[]* [\-0-9])
104
105 email      ::= username "@" host      => email
106 host       ::= domain
107              | [0-9]+ "." [0-9]+ "." [0-9]+ "." [0-9]+ => "ip"
108
109
110
111 // Tokens ///////////////////////////////////////////////////////////////////
112
113 word     ::= alphanum++ => "stringify"
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]++ => "stringify"
127 //num      ::= [0-9]
128 alphanum ::= [a-zA-Z0-9]
129 sym      ::= ~[a-zA-Z0-9\ \r\n]
130
131