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