LaTeX.ebnf 1.54 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
genericenv = beginenv sequence §endenv
13
14
beginenv   = "\begin" §( "{" NAME "}" )
endenv     = "\end" §( "{" ::NAME "}" )
Eckhart Arnold's avatar
Eckhart Arnold committed
15

16
parblock   = "{" sequence §"}"
Eckhart Arnold's avatar
Eckhart Arnold committed
17

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

21
22
command    = CMDNAME [ config ] block
config     = "[" cfgtext §"]"
23
block      = "{" { text | block } §"}"
Eckhart Arnold's avatar
Eckhart Arnold committed
24

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

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

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

Eckhart Arnold's avatar
Eckhart Arnold committed
36
ESCAPED    = /\\[%$&]/
37
BRACKETS   = /[\[\]]/                   # left or right square bracket: [ ]
Eckhart Arnold's avatar
Eckhart Arnold committed
38
TEXTCHUNK  = /[^\\%$&\{\}\[\]\s\n]+/    # some piece of text excluding whitespace,
39
                                        # linefeed and special characters
40
41
42
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.
43
                                        # [whitespace] linefeed [whitespace] linefeed
44

45
EOF        = !/./