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.65 KB
Newer Older
Eckhart Arnold's avatar
Eckhart Arnold committed
1
2
# latex Grammar

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

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

Eckhart Arnold's avatar
Eckhart Arnold committed
10
document   = [PARSEP] { [PARSEP] paragraph } §EOF
11

12
blockenv   = beginenv sequence §endenv
Eckhart Arnold's avatar
Eckhart Arnold committed
13

14
parblock   = "{" sequence §"}"
Eckhart Arnold's avatar
Eckhart Arnold committed
15

16
sequence   = { paragraph [PARSEP] }+
17
paragraph  = { !blockcmd (command | block | text) //~ }+
Eckhart Arnold's avatar
Eckhart Arnold committed
18

19
20
21
22
inlineenv  = beginenv { command | block | text }+ endenv
beginenv   = "\begin{" §NAME §"}"
endenv     = "\end{" §::NAME §"}"

23
command    = CMDNAME [[ //~ config ] //~ block ]
24
config     = "[" cfgtext §"]"
25
block      = /{/ { command | text | block } §/}/
Eckhart Arnold's avatar
Eckhart Arnold committed
26

27
28
29
text       = { cfgtext | (BRACKETS //~) }+
cfgtext    = { word_sequence | (ESCAPED //~) }+
word_sequence = { TEXTCHUNK //~ }+
30
31

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

35
CMDNAME    = /\\(?:(?!_)\w)+/~
36
NAME       = /\w+/~
Eckhart Arnold's avatar
Eckhart Arnold committed
37

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

47
EOF        = !/./