LaTeX.ebnf 1.1 KB
Newer Older
Eckhart Arnold's avatar
Eckhart Arnold committed
1
2
# latex Grammar

3
4
@ whitespace = /[ \t]*\n?(?!\s*\n)[ \t]*/
@ comment    = /%.*(?:\n|$)/
Eckhart Arnold's avatar
Eckhart Arnold committed
5

6
7
8
genericenv = beginenv sequence endenv
beginenv   = "\begin" §( "{" name "}" )
endenv     = "\end" §( "{" ::name "}" )
Eckhart Arnold's avatar
Eckhart Arnold committed
9

10
name       = ~/\w+/
Eckhart Arnold's avatar
Eckhart Arnold committed
11

12
13
14
genericcmd = command [ config ] block
command    = /\\\w+/
config     = "[" cfgtext §"]"
Eckhart Arnold's avatar
Eckhart Arnold committed
15

16
sequence   = { partext | parblock }
Eckhart Arnold's avatar
Eckhart Arnold committed
17

18
19
parblock   = "{" { partext | parblock } §"}"
block      = "{" { text | block } §"}"
Eckhart Arnold's avatar
Eckhart Arnold committed
20

21
22
23
partext    = text | par
text       = cfgtext | brackets
cfgtext    = chunk | wspc | escaped
Eckhart Arnold's avatar
Eckhart Arnold committed
24

25
26
27
28
29
30
31
32
escaped    = /\\[%$&]/
brackets   = /[\[\]]/                   # left and right square brackets: [ ]
chunk      = /[^\\%$&\{\}\[\]\s\n]+/    # some piece of text excluding whitespace,
                                        # linefeed and special characters
wspc       = /[ \t]*\n?(?!\s*\n)[ \t]*/ # whitespace, including at most one linefeed
lf         = /[ \t]*\n(?!\s*\n)/        # a linefeed, but not an empty line (i.e. par)
par        = /\s*\n\s*\n/               # at least one empty line, i.e.
                                        # [whitespace] linefeed [whitespace] linefeed
Eckhart Arnold's avatar
Eckhart Arnold committed
33