1 // draft grammar for [La]TeX
2 // note that this is approximate; in reality TeX has no grammar
7 | Text:: `Text (WS:: ws) Token
8 | Text:: `Text (BlankLine:: br) Token
11 | Comment:: "%" ~[\n]* "\n"
12 | EscapedChar:: "\\" ~[a-zA-Z\\]
13 | Environment:: "\\begin{" EnvironmentName "}" Text "\\end{" EnvironmentName! "}"
14 | Word:: ~[\\\r\n\ %{}]++
16 | "$" (Math:: ~[$]+) "$"
17 | "$$" (Math:: ~[$]+) "$$"
22 Command:: = "\\" CommandName ws -> ~[{]
23 | "\\" CommandName OptArgs ws "{" Text "}"
24 CommandName = [A-Za-z0-9]++ &~ "begin" | "end"
25 OptArgs:: = ws ("[" Arg "]") +/ ws
28 Table = "\\begin{tabular}"
29 TableRow +/ (ws "\\\\" ws)
31 TableRow = TableCol +/ (ws "&" ws)
32 TableCol = Text &~ ... "\\\\" ...
34 EnvironmentName = [A-Za-z0-9]++ &~ "verbatim" | "tabular"
36 Verbatim = "\\begin{verbatim}"
37 (Verb:: ... &~ ... "\\end{verbatim}")
41 ws! = (hws* "\n")? hws* -> ~[ \n\r]
42 nl! = [ \r]* "\n" [ \r]* -> ~[ \n\r]
43 br! = [ \r]* "\n" [ \r]* "\n" [ \r\n]* -> ~[ \n\r]
45 // import wix.g as wix
46 // WiX = "\\begin{wix}\n"
48 // "\n\\end{verbatim}"