Commit 7cba2407 authored by Eckhart Arnold's avatar Eckhart Arnold

examples/LaTeX extended

parent a5ef6415
......@@ -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
......
......@@ -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(1000):
for i in range(1):
result = compileDSL(grammar, nil_scanner, result, transformer, compiler)
print(result)
return result
......
......@@ -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 //~) }+
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment