intermediate checkpoint
[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 => section }
29 SectionHeader     ::= "==" SectionHeaderBody "=="
30 SectionHeaderBody ::=  "=" SectionHeaderBody "="
31                     >      ws text ws
32
33 sp    !::= " "**
34 blank  ::= sp "\n" sp "\n" ws
35
36 kv         ::= word "=" text /ws => kv1
37
38 num !::= [0-9]++
39 Paragraph  ::= { "\"\"" ws text  }  => "blockquote"
40              > { "*" " " ws text }  => "ul"
41              > { "#" " " ws text }  => "ol"
42              > { num " " ws text }  => "ol"
43              > { "---" "-"*      }  => "hr"
44              > { text }             => "p"
45
46 text       ::= Item
47 Itemx      ::= ws Item | ()
48 Item       ::= blockquote
49              > pre         Itemx => []
50              > structured  Itemx => []
51              > structuredx Itemx => []
52              > styled      Itemx => []
53              > qtext       Itemx => []
54              > alphanum++  Itemx => []
55              > symbol      Itemx => []
56 //             > sym++       Itemx => []
57              > Paragraph   Itemx => []
58
59 symbol     ::= sym++
60
61 blockquote ::= "\"\"" text "\"\""        => "blockquote"
62              | "\"\"" block              => "blockquote"
63              
64 qtext      ::= "\"" text "\""            => "quoted"
65 pre        ::= "[verbatim]" { ~[]+ } /ws => "verbatim"   // FIXME doesn't work
66
67 styled     ::= "__" text "__"      => ul
68              | "((" text "))"      => footnote
69              | ( "[[" text "]]"      => tt
70                >  "[" word "]"       => citation
71                )
72              | "!!" text "!!"      => strikethrough
73              | "^^" (word|block)   => superscript
74              | ",," (word|block)   => subscript
75              | "\\sc" block        => smallcap
76              | "**" text "**"      => bold
77              | "!" (word|block)    => keyword
78              >  "*" text "*"       => it
79
80 block ::= { text }
81 structured ::= { text } "->" (url|email) => link
82               //> alphanum++ "->" (url|email) => link
83 structuredx ::= glyph
84               > email
85               > url
86
87 glyph      ::= "(r)" | "(c)" | "(tm)" | "--"  // euro symbol?
88              | "\\today" -> ~[a-z] => today
89
90
91 // URLs //////////////////////////////////////////////////////////////////////////////
92
93 // interesting opportunity to show off boolean grammars here: define other
94 // subtypes of url (ftp, etc) as conjunctions, but the "master pattern"
95 // only gets parsed once
96
97 urlpath    ::= urlchar*
98 username   ::= [a-zA-Z0-9;/?:&=$\-_.+]++
99 password   ::= [a-zA-Z0-9;/?:&=$\-_.+]++
100 urlchar    ::= [a-zA-Z0-9;/?:&=$\-_.+@]
101              | "%" [0-9] [0-9]       => "%"
102 url        ::= "mailto" ":"   email
103              > method "://" url_login? host (":" port)? ("/" urlpath)?     => "url"
104 url_login  ::= username (":" password) "@" => "login"
105 method     ::= [+\-.a-z0-9]+ 
106 port       ::= [0-9]+
107
108 domain     ::= (part +/ ".") -> ~"."
109 part       ::= [a-zA-Z0-9\-]++    // interesting use of boolean grammars
110 //            &~ ([\-0-9] ~[]* | ~[]* [\-0-9])
111
112 email      ::= username "@" host -> ~[.] => emailaddr
113 host       ::= [0-9]+ "." [0-9]+ "." [0-9]+ "." [0-9]+ => "ip"
114              | domain
115
116
117
118 // Tokens ///////////////////////////////////////////////////////////////////
119
120 word     ::= alphanum++
121            | quoted
122
123 quoted   ::= "\"" ((~[\"\\] | escaped)+) "\""
124            | "\"\"" => ""
125 escaped  ::= "\\n" => "\n"
126            | "\\r" => "\r"
127            | "\\" ~[nr]
128
129
130 // Chars ///////////////////////////////////////////////////////////////
131
132 alpha    ::= [a-zA-Z]
133 //num      ::= [0-9]
134 alphanum ::= [a-zA-Z0-9]
135 sym      ::= ~[a-zA-Z0-9\ \r\n=\">]
136
137