2.12.2021, 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

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

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

6
7
8
latexdoc   = preamble document
preamble   = { command }+

9
document   = [PARSEP] sequence [PARSEP] §EOF
10

11
genericenv = beginenv sequence §endenv
12
13
beginenv   = "\begin" §( "{" NAME "}" )
endenv     = "\end" §( "{" ::NAME "}" )
Eckhart Arnold's avatar
Eckhart Arnold committed
14

15
command    = CMDNAME [ config ] block
16
config     = "[" cfgtext §"]"
Eckhart Arnold's avatar
Eckhart Arnold committed
17

18
sequence   = { partext | parblock }
Eckhart Arnold's avatar
Eckhart Arnold committed
19

20
parblock   = "{" paragraph §"}"
21
block      = "{" { text | block } §"}"
Eckhart Arnold's avatar
Eckhart Arnold committed
22

23
24
25
paragraph  = { partext | parblock }

partext    = !blockcmd (text | PARSEP)
26
text       = cfgtext | BRACKETS
27
28
cfgtext    = word_sequence | ESCAPED | WSPC
word_sequence = { TEXTCHUNK WSPC }+
29
30

blockcmd   = "\subsection" | "\section" | "\chapter" | "\subsubsection"
31
             | "\paragraph" | "\subparagraph" | "\begin{enumerate}"
32
             | "\begin{itemize}" | "\item" | "\begin{figure}"
33
34
35

CMDNAME    = /\\\w+/~
NAME       = /\w+/~
Eckhart Arnold's avatar
Eckhart Arnold committed
36

Eckhart Arnold's avatar
Eckhart Arnold committed
37
ESCAPED    = /\\[%$&]/
38
BRACKETS   = /[\[\]]/                   # left or right square bracket: [ ]
Eckhart Arnold's avatar
Eckhart Arnold committed
39
TEXTCHUNK  = /[^\\%$&\{\}\[\]\s\n]+/    # some piece of text excluding whitespace,
40
                                        # linefeed and special characters
41
WSPC       = /[ \t]*\n?(?![ \t]*\n)[ \t]*/ # whitespace, including at most one linefeed
42
LF         = /[ \t]*\n(?!\s*\n)/        # a linefeed, but not an empty line (i.e. par)
43
PARSEP     = /\n[ \t]*(?=\n)/~          # at least one empty line, i.e.
44
                                        # [whitespace] linefeed [whitespace] linefeed
45

46
EOF        = !/./