checkpoint
[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 num !::= [0-9]++ => "stringify"
51 Paragraph  ::= { "\"\"" ws text }        => "blockquote"
52              > { "*" " " ws text }       => "ul"
53              > { "#" " " ws text }       => "ol"
54              > { num " " ws text }       => "ol"
55              > { "---" "-"* }            => "hr"
56              > { text }                  => "p"
57
58 text       ::= item */ ws
59 pre        ::= "[verbatim]" { ~[]+ } /ws => "verbatim"   // FIXME doesn't work
60 item       ::= pre
61              > email
62              > structured
63              > styled
64              > "\"" text "\""    => quoted
65              > alphanum++        => "stringify"
66              > symbol
67
68 symbol     ::= symbolx & sym++
69 symbolx    ::= "--"  => emdash
70              | ","
71              | ":"
72              | ";"
73
74 styled     ::= "**" text "**" => bold
75              | "__" text "__" => ul
76              | "~~" text "~~" => it     // hard to type
77              | "((" text "))" => footnote
78
79 structured ::= glyph
80 //             | url
81
82 glyph      ::= "(r)" | "(c)" | "(tm)"  // euro symbol?
83
84
85 // URLs //////////////////////////////////////////////////////////////////////////////
86
87 // interesting opportunity to show off boolean grammars here: define other
88 // subtypes of url (ftp, etc) as conjunctions, but the "master pattern"
89 // only gets parsed once
90
91 urlpath    ::= urlchar*
92 username   ::= [a-zA-Z0-9;/?:&=$\-_.+]++ => "stringify"
93 password   ::= [a-zA-Z0-9;/?:&=$\-_.+]++ => "stringify"
94 urlchar    ::= [a-zA-Z0-9;/?:&=$\-_.+@]
95              | "%" [0-9] [0-9]       => "%"
96 url        ::= "mailto" ":"   email
97              > method "://" url_login? host (":" port)? ("/" urlpath)?     => "url"
98 url_login  ::= username (":" password) "@" => "login"
99 method     ::= [+\-.a-z0-9]+ 
100 port       ::= [0-9]+
101
102 domain     ::= part +/ "."
103 part       ::= [a-zA-Z0-9\-]++ => "stringify"   // interesting use of boolean grammars
104 //            &~ ([\-0-9] ~[]* | ~[]* [\-0-9])
105
106 email      ::= username "@" host      => email
107 host       ::= [0-9]+ "." [0-9]+ "." [0-9]+ "." [0-9]+ => "ip"
108              | domain
109
110
111
112 // Tokens ///////////////////////////////////////////////////////////////////
113
114 word     ::= alphanum++ => "stringify"
115            | quoted
116
117 quoted   ::= "\"" ((~[\"\\] | escaped)+) "\""
118            | "\"\"" => ""
119 escaped  ::= "\\n" => "\n"
120            | "\\r" => "\r"
121            | "\\" ~[nr]
122
123
124 // Chars ///////////////////////////////////////////////////////////////
125
126 alpha    ::= [a-zA-Z]
127 num      ::= [0-9]
128 alphanum ::= [a-zA-Z0-9]
129 sym      ::= ~[a-zA-Z0-9\ \r\n]
130
131