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