Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
badw-it
DHParser
Commits
7cba2407
Commit
7cba2407
authored
Jul 08, 2017
by
Eckhart Arnold
Browse files
examples/LaTeX extended
parent
a5ef6415
Changes
3
Hide whitespace changes
Inline
Side-by-side
DHParser/parsers.py
View file @
7cba2407
...
...
@@ -206,6 +206,7 @@ def add_parser_guard(parser_func):
node
,
rest
=
parser
.
visited
.
get
(
location
,
(
None
,
rest
))
# don't overwrite any positive match (i.e. node not None) in the cache
# and don't add empty entries for parsers returning from left recursive calls!
# TODO: Bei Gelegenheit messen, ob sich das hier überhaupt lohnt...
if
node
is
None
and
not
grammar
.
left_recursion_encountered__
:
# ortherwise also cache None-results
parser
.
visited
[
location
]
=
None
,
rest
...
...
dhparser.py
View file @
7cba2407
...
...
@@ -52,7 +52,7 @@ def selftest(file_name):
else
:
# compile the grammar again using the result of the previous
# compilation as parser
for
i
in
range
(
1
000
):
for
i
in
range
(
1
):
result
=
compileDSL
(
grammar
,
nil_scanner
,
result
,
transformer
,
compiler
)
print
(
result
)
return
result
...
...
examples/LaTeX/LaTeX.ebnf
View file @
7cba2407
...
...
@@ -7,22 +7,61 @@
latexdoc = preamble document
preamble = { command }+
document = [PARSEP] { [PARSEP] paragraph } §EOF
document = [PARSEP] "\begin{document}" [PARSEP] frontpages [PARSEP] (chapters | sections)
[bibliography] [index] "\end{document}" §EOF
frontpages = sequence
#######################################################################
#
# document structure
#
#######################################################################
Chapters = { Chapter [PARSEP] }+
Chapter = "\Chapter" block [PARSEP] { sequence | Sections }
Sections = { Section [PARSEP] }+
Section = "\Section" block [PARSEP] { sequence | SubSections }
SubSections = { SubSection [PARSEP] }+
SubSection = "\SubSection" block [PARSEP] { sequence | SubSubSections }
SubSubsections = { SubSubSection [PARSEP] }+
SubSubSection = "\SubSubSection" block [PARSEP] { sequence | Paragraphs }
Paragraphs = { Paragraph [PARSEP] }+
Paragraph = "\paragraph" block [PARSEP] { sequence | SubParagraphs }
SubParagraphs = { SubParagraph [PARSEP] }+
SubParagraph = "\subparagpaph" block [PARSEP] { sequence }
bibliography = "\bibliography" block [PARSEP]
index = "\printindex" [PARSEP
#######################################################################
#
# document content
#
#######################################################################
blockenv = beginenv sequence §endenv
parblock = /{/ sequence §/}/
parblock = "{" sequence §"}"
sequence = { (paragraph | itemize | enumeration | figure | table | blockenv ) [PARSEP] }+
sequence = { paragraph [PARSEP]
}+
paragraph = { !blockcmd (
command | block |
text) //~ }+
paragraph = { !blockcmd textelements //~
}+
textelemts =
command |
text |
block |
inlinemath | inlineenv
inlineenv = beginenv {
command | block | text
}+ endenv
inlineenv = beginenv {
textelements
}+ endenv
beginenv = "\begin{" §NAME §"}"
endenv = "\end{" §::NAME §"}"
command = CMDNAME [[ //~ config ] //~ block ]
command = specialcmd | plaincmd
specialcmd = "\footnote" parblock
plaincmd = CMDNAME [[ //~ config ] //~ block ]
config = "[" cfgtext §"]"
block = /{/ {
command | text | block
} §/}/
block = /{/ {
textelements
} §/}/
text = { cfgtext | (BRACKETS //~) }+
cfgtext = { word_sequence | (ESCAPED //~) }+
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment