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

Commit c90818b7 authored by eckhart's avatar eckhart
Browse files

- LaTeX AST transformation extended

parent cf2c8f75
...@@ -13,9 +13,9 @@ ...@@ -13,9 +13,9 @@
latexdoc = preamble document latexdoc = preamble document
preamble = { [WSPC] command }+ preamble = { [WSPC] command }+
document = [WSPC] "\begin{document}" [WSPC] document = [WSPC] "\begin{document}"
frontpages [WSPC] frontpages
(Chapters | Sections) [WSPC] (Chapters | Sections)
[Bibliography] [Index] [WSPC] [Bibliography] [Index] [WSPC]
"\end{document}" [WSPC] §EOF "\end{document}" [WSPC] §EOF
frontpages = sequence frontpages = sequence
...@@ -27,26 +27,26 @@ frontpages = sequence ...@@ -27,26 +27,26 @@ frontpages = sequence
# #
####################################################################### #######################################################################
Chapters = { Chapter [WSPC] }+ Chapters = { [WSPC] Chapter }+
Chapter = "\chapter" heading [WSPC] { sequence | Sections } Chapter = "\chapter" heading { sequence | Sections }
Sections = { Section [WSPC] }+ Sections = { [WSPC] Section }+
Section = "\section" heading [WSPC] { sequence | SubSections } Section = "\section" heading { sequence | SubSections }
SubSections = { SubSection [WSPC] }+ SubSections = { [WSPC] SubSection }+
SubSection = "\subsection" heading [WSPC] { sequence | SubSubSections } SubSection = "\subsection" heading { sequence | SubSubSections }
SubSubSections = { SubSubSection [WSPC] }+ SubSubSections = { [WSPC] SubSubSection }+
SubSubSection = "\subsubsection" heading [WSPC] { sequence | Paragraphs } SubSubSection = "\subsubsection" heading { sequence | Paragraphs }
Paragraphs = { Paragraph [WSPC] }+ Paragraphs = { [WSPC] Paragraph }+
Paragraph = "\paragraph" heading [WSPC] { sequence | SubParagraphs } Paragraph = "\paragraph" heading { sequence | SubParagraphs }
SubParagraphs = { SubParagraph [WSPC] }+ SubParagraphs = { [WSPC] SubParagraph }+
SubParagraph = "\subparagraph" heading [WSPC] [ sequence ] SubParagraph = "\subparagraph" heading [ sequence ]
Bibliography = "\bibliography" heading [WSPC] Bibliography = [WSPC] "\bibliography" heading
Index = "\printindex" [WSPC] Index = [WSPC] "\printindex"
heading = block heading = block
...@@ -68,7 +68,7 @@ end_generic_block = -&LB end_environment LFF ...@@ -68,7 +68,7 @@ end_generic_block = -&LB end_environment LFF
itemize = "\begin{itemize}" [WSPC] { item } §"\end{itemize}" itemize = "\begin{itemize}" [WSPC] { item } §"\end{itemize}"
enumerate = "\begin{enumerate}" [WSPC] {item } §"\end{enumerate}" enumerate = "\begin{enumerate}" [WSPC] {item } §"\end{enumerate}"
item = "\item" [WSPC] sequence item = "\item" sequence
figure = "\begin{figure}" sequence §"\end{figure}" figure = "\begin{figure}" sequence §"\end{figure}"
quotation = ("\begin{quotation}" sequence §"\end{quotation}") quotation = ("\begin{quotation}" sequence §"\end{quotation}")
...@@ -84,7 +84,7 @@ tabular_config = "{" /[lcr|]+/~ §"}" ...@@ -84,7 +84,7 @@ tabular_config = "{" /[lcr|]+/~ §"}"
#### paragraphs and sequences of paragraphs #### #### paragraphs and sequences of paragraphs ####
block_of_paragraphs = "{" [sequence] §"}" block_of_paragraphs = "{" [sequence] §"}"
sequence = { (paragraph | block_environment ) [PARSEP] }+ sequence = [WSPC] { (paragraph | block_environment ) [PARSEP] }+
paragraph = { !blockcmd text_element //~ }+ paragraph = { !blockcmd text_element //~ }+
text_element = line_element | LINEFEED text_element = line_element | LINEFEED
line_element = text | block | inline_environment | command line_element = text | block | inline_environment | command
......
...@@ -63,9 +63,9 @@ class LaTeXGrammar(Grammar): ...@@ -63,9 +63,9 @@ class LaTeXGrammar(Grammar):
latexdoc = preamble document latexdoc = preamble document
preamble = { [WSPC] command }+ preamble = { [WSPC] command }+
document = [WSPC] "\begin{document}" [WSPC] document = [WSPC] "\begin{document}"
frontpages [WSPC] frontpages
(Chapters | Sections) [WSPC] (Chapters | Sections)
[Bibliography] [Index] [WSPC] [Bibliography] [Index] [WSPC]
"\end{document}" [WSPC] §EOF "\end{document}" [WSPC] §EOF
frontpages = sequence frontpages = sequence
...@@ -77,26 +77,26 @@ class LaTeXGrammar(Grammar): ...@@ -77,26 +77,26 @@ class LaTeXGrammar(Grammar):
# #
####################################################################### #######################################################################
Chapters = { Chapter [WSPC] }+ Chapters = { [WSPC] Chapter }+
Chapter = "\chapter" heading [WSPC] { sequence | Sections } Chapter = "\chapter" heading { sequence | Sections }
Sections = { Section [WSPC] }+ Sections = { [WSPC] Section }+
Section = "\section" heading [WSPC] { sequence | SubSections } Section = "\section" heading { sequence | SubSections }
SubSections = { SubSection [WSPC] }+ SubSections = { [WSPC] SubSection }+
SubSection = "\subsection" heading [WSPC] { sequence | SubSubSections } SubSection = "\subsection" heading { sequence | SubSubSections }
SubSubSections = { SubSubSection [WSPC] }+ SubSubSections = { [WSPC] SubSubSection }+
SubSubSection = "\subsubsection" heading [WSPC] { sequence | Paragraphs } SubSubSection = "\subsubsection" heading { sequence | Paragraphs }
Paragraphs = { Paragraph [WSPC] }+ Paragraphs = { [WSPC] Paragraph }+
Paragraph = "\paragraph" heading [WSPC] { sequence | SubParagraphs } Paragraph = "\paragraph" heading { sequence | SubParagraphs }
SubParagraphs = { SubParagraph [WSPC] }+ SubParagraphs = { [WSPC] SubParagraph }+
SubParagraph = "\subparagraph" heading [WSPC] [ sequence ] SubParagraph = "\subparagraph" heading [ sequence ]
Bibliography = "\bibliography" heading [WSPC] Bibliography = [WSPC] "\bibliography" heading
Index = "\printindex" [WSPC] Index = [WSPC] "\printindex"
heading = block heading = block
...@@ -118,7 +118,7 @@ class LaTeXGrammar(Grammar): ...@@ -118,7 +118,7 @@ class LaTeXGrammar(Grammar):
itemize = "\begin{itemize}" [WSPC] { item } §"\end{itemize}" itemize = "\begin{itemize}" [WSPC] { item } §"\end{itemize}"
enumerate = "\begin{enumerate}" [WSPC] {item } §"\end{enumerate}" enumerate = "\begin{enumerate}" [WSPC] {item } §"\end{enumerate}"
item = "\item" [WSPC] sequence item = "\item" sequence
figure = "\begin{figure}" sequence §"\end{figure}" figure = "\begin{figure}" sequence §"\end{figure}"
quotation = ("\begin{quotation}" sequence §"\end{quotation}") quotation = ("\begin{quotation}" sequence §"\end{quotation}")
...@@ -134,7 +134,7 @@ class LaTeXGrammar(Grammar): ...@@ -134,7 +134,7 @@ class LaTeXGrammar(Grammar):
#### paragraphs and sequences of paragraphs #### #### paragraphs and sequences of paragraphs ####
block_of_paragraphs = "{" [sequence] §"}" block_of_paragraphs = "{" [sequence] §"}"
sequence = { (paragraph | block_environment ) [PARSEP] }+ sequence = [WSPC] { (paragraph | block_environment ) [PARSEP] }+
paragraph = { !blockcmd text_element //~ }+ paragraph = { !blockcmd text_element //~ }+
text_element = line_element | LINEFEED text_element = line_element | LINEFEED
line_element = text | block | inline_environment | command line_element = text | block | inline_environment | command
...@@ -230,7 +230,7 @@ class LaTeXGrammar(Grammar): ...@@ -230,7 +230,7 @@ class LaTeXGrammar(Grammar):
paragraph = Forward() paragraph = Forward()
tabular_config = Forward() tabular_config = Forward()
text_element = Forward() text_element = Forward()
source_hash__ = "fafffa29d26d712fde61c15c1a92dce8" source_hash__ = "a4c1da340e03a51e46030c64f671f1d6"
parser_initialization__ = "upon instantiation" parser_initialization__ = "upon instantiation"
COMMENT__ = r'%.*' COMMENT__ = r'%.*'
WHITESPACE__ = r'[ \t]*(?:\n(?![ \t]*\n)[ \t]*)?' WHITESPACE__ = r'[ \t]*(?:\n(?![ \t]*\n)[ \t]*)?'
...@@ -283,7 +283,7 @@ class LaTeXGrammar(Grammar): ...@@ -283,7 +283,7 @@ class LaTeXGrammar(Grammar):
line_element = Alternative(text, block, inline_environment, command) line_element = Alternative(text, block, inline_environment, command)
text_element.set(Alternative(line_element, LINEFEED)) text_element.set(Alternative(line_element, LINEFEED))
paragraph.set(OneOrMore(Series(NegativeLookahead(blockcmd), text_element, RE('')))) paragraph.set(OneOrMore(Series(NegativeLookahead(blockcmd), text_element, RE(''))))
sequence = OneOrMore(Series(Alternative(paragraph, block_environment), Option(PARSEP))) sequence = Series(Option(WSPC), OneOrMore(Series(Alternative(paragraph, block_environment), Option(PARSEP))))
block_of_paragraphs.set(Series(Token("{"), Option(sequence), Token("}"), mandatory=2)) block_of_paragraphs.set(Series(Token("{"), Option(sequence), Token("}"), mandatory=2))
tabular_config.set(Series(Token("{"), RE('[lcr|]+'), Token("}"), mandatory=2)) tabular_config.set(Series(Token("{"), RE('[lcr|]+'), Token("}"), mandatory=2))
tabular_cell = ZeroOrMore(Series(line_element, RE(''))) tabular_cell = ZeroOrMore(Series(line_element, RE('')))
...@@ -292,7 +292,7 @@ class LaTeXGrammar(Grammar): ...@@ -292,7 +292,7 @@ class LaTeXGrammar(Grammar):
verbatim = Series(Token("\\begin{verbatim}"), sequence, Token("\\end{verbatim}"), mandatory=2) verbatim = Series(Token("\\begin{verbatim}"), sequence, Token("\\end{verbatim}"), mandatory=2)
quotation = Alternative(Series(Token("\\begin{quotation}"), sequence, Token("\\end{quotation}"), mandatory=2), Series(Token("\\begin{quote}"), sequence, Token("\\end{quote}"), mandatory=2)) quotation = Alternative(Series(Token("\\begin{quotation}"), sequence, Token("\\end{quotation}"), mandatory=2), Series(Token("\\begin{quote}"), sequence, Token("\\end{quote}"), mandatory=2))
figure = Series(Token("\\begin{figure}"), sequence, Token("\\end{figure}"), mandatory=2) figure = Series(Token("\\begin{figure}"), sequence, Token("\\end{figure}"), mandatory=2)
item = Series(Token("\\item"), Option(WSPC), sequence) item = Series(Token("\\item"), sequence)
enumerate = Series(Token("\\begin{enumerate}"), Option(WSPC), ZeroOrMore(item), Token("\\end{enumerate}"), mandatory=3) enumerate = Series(Token("\\begin{enumerate}"), Option(WSPC), ZeroOrMore(item), Token("\\end{enumerate}"), mandatory=3)
itemize = Series(Token("\\begin{itemize}"), Option(WSPC), ZeroOrMore(item), Token("\\end{itemize}"), mandatory=3) itemize = Series(Token("\\begin{itemize}"), Option(WSPC), ZeroOrMore(item), Token("\\end{itemize}"), mandatory=3)
end_generic_block.set(Series(Lookbehind(LB), end_environment, LFF)) end_generic_block.set(Series(Lookbehind(LB), end_environment, LFF))
...@@ -301,22 +301,22 @@ class LaTeXGrammar(Grammar): ...@@ -301,22 +301,22 @@ class LaTeXGrammar(Grammar):
known_environment = Alternative(itemize, enumerate, figure, tabular, quotation, verbatim) known_environment = Alternative(itemize, enumerate, figure, tabular, quotation, verbatim)
block_environment.set(Alternative(known_environment, generic_block)) block_environment.set(Alternative(known_environment, generic_block))
heading = Synonym(block) heading = Synonym(block)
Index = Series(Token("\\printindex"), Option(WSPC)) Index = Series(Option(WSPC), Token("\\printindex"))
Bibliography = Series(Token("\\bibliography"), heading, Option(WSPC)) Bibliography = Series(Option(WSPC), Token("\\bibliography"), heading)
SubParagraph = Series(Token("\\subparagraph"), heading, Option(WSPC), Option(sequence)) SubParagraph = Series(Token("\\subparagraph"), heading, Option(sequence))
SubParagraphs = OneOrMore(Series(SubParagraph, Option(WSPC))) SubParagraphs = OneOrMore(Series(Option(WSPC), SubParagraph))
Paragraph = Series(Token("\\paragraph"), heading, Option(WSPC), ZeroOrMore(Alternative(sequence, SubParagraphs))) Paragraph = Series(Token("\\paragraph"), heading, ZeroOrMore(Alternative(sequence, SubParagraphs)))
Paragraphs = OneOrMore(Series(Paragraph, Option(WSPC))) Paragraphs = OneOrMore(Series(Option(WSPC), Paragraph))
SubSubSection = Series(Token("\\subsubsection"), heading, Option(WSPC), ZeroOrMore(Alternative(sequence, Paragraphs))) SubSubSection = Series(Token("\\subsubsection"), heading, ZeroOrMore(Alternative(sequence, Paragraphs)))
SubSubSections = OneOrMore(Series(SubSubSection, Option(WSPC))) SubSubSections = OneOrMore(Series(Option(WSPC), SubSubSection))
SubSection = Series(Token("\\subsection"), heading, Option(WSPC), ZeroOrMore(Alternative(sequence, SubSubSections))) SubSection = Series(Token("\\subsection"), heading, ZeroOrMore(Alternative(sequence, SubSubSections)))
SubSections = OneOrMore(Series(SubSection, Option(WSPC))) SubSections = OneOrMore(Series(Option(WSPC), SubSection))
Section = Series(Token("\\section"), heading, Option(WSPC), ZeroOrMore(Alternative(sequence, SubSections))) Section = Series(Token("\\section"), heading, ZeroOrMore(Alternative(sequence, SubSections)))
Sections = OneOrMore(Series(Section, Option(WSPC))) Sections = OneOrMore(Series(Option(WSPC), Section))
Chapter = Series(Token("\\chapter"), heading, Option(WSPC), ZeroOrMore(Alternative(sequence, Sections))) Chapter = Series(Token("\\chapter"), heading, ZeroOrMore(Alternative(sequence, Sections)))
Chapters = OneOrMore(Series(Chapter, Option(WSPC))) Chapters = OneOrMore(Series(Option(WSPC), Chapter))
frontpages = Synonym(sequence) frontpages = Synonym(sequence)
document = Series(Option(WSPC), Token("\\begin{document}"), Option(WSPC), frontpages, Option(WSPC), Alternative(Chapters, Sections), Option(WSPC), Option(Bibliography), Option(Index), Option(WSPC), Token("\\end{document}"), Option(WSPC), EOF, mandatory=12) document = Series(Option(WSPC), Token("\\begin{document}"), frontpages, Alternative(Chapters, Sections), Option(Bibliography), Option(Index), Option(WSPC), Token("\\end{document}"), Option(WSPC), EOF, mandatory=9)
preamble = OneOrMore(Series(Option(WSPC), command)) preamble = OneOrMore(Series(Option(WSPC), command))
latexdoc = Series(preamble, document) latexdoc = Series(preamble, document)
root__ = latexdoc root__ = latexdoc
......
...@@ -467,25 +467,19 @@ Match-test "3" ...@@ -467,25 +467,19 @@ Match-test "3"
"" ""
"" ""
) )
(:ZeroOrMore (:RegExp
(:Series "% Comment"
(:RegExp )
"% Comment" (:RegExp
) ""
(:RegExp ""
"" )
"" (:RegExp
) "% Comment"
) )
(:Series (:RegExp
(:RegExp ""
"% Comment" ""
)
(:RegExp
""
""
)
)
) )
) )
......
...@@ -78,22 +78,9 @@ Match-test "3" ...@@ -78,22 +78,9 @@ Match-test "3"
### AST ### AST
(footnote (footnote
(:Token
"\footnote"
)
(block_of_paragraphs (block_of_paragraphs
(:Token (text
"{" "footnote"
)
(sequence
(paragraph
(text
"footnote"
)
)
)
(:Token
"}"
) )
) )
) )
......
...@@ -59,10 +59,8 @@ Match-test "2" ...@@ -59,10 +59,8 @@ Match-test "2"
(CMDNAME (CMDNAME
"\emph" "\emph"
) )
(block (text
(text "inline commands"
"inline commands"
)
) )
) )
(:Whitespace (:Whitespace
...@@ -277,9 +275,7 @@ Match-test "7" ...@@ -277,9 +275,7 @@ Match-test "7"
"\xy" "\xy"
) )
(config (config
(text "xycgf"
"xycgf"
)
) )
(block (block
(text (text
...@@ -339,10 +335,8 @@ Match-test "8" ...@@ -339,10 +335,8 @@ Match-test "8"
(CMDNAME (CMDNAME
"\xy" "\xy"
) )
(block (text
(text "complex"
"complex"
)
) )
) )
(text (text
...@@ -482,22 +476,9 @@ Match-test "9" ...@@ -482,22 +476,9 @@ Match-test "9"
"" ""
) )
(footnote (footnote
(:Token
"\footnote"
)
(block_of_paragraphs (block_of_paragraphs
(:Token (text
"{" "footnote"
)
(sequence
(paragraph
(text
"footnote"
)
)
)
(:Token
"}"
) )
) )
) )
...@@ -708,15 +689,13 @@ Match-test "4" ...@@ -708,15 +689,13 @@ Match-test "4"
) )
) )
(quotation (quotation
(sequence (paragraph
(paragraph (text
(text "include block environments"
"include block environments" )
) (:Whitespace
(:Whitespace ""
"" ""
""
)
) )
) )
) )
......
...@@ -20,43 +20,29 @@ Match-test "1" ...@@ -20,43 +20,29 @@ Match-test "1"
### AST ### AST
(generic_block (generic_block
(begin_generic_block (begin_environment
(begin_environment "generic"
"generic"
)
(NEW_LINE
""
""
)
) )
(sequence (paragraph
(paragraph (text
(text "A generic block element is a block element"
"A generic block element is a block element" "that is unknown to DHParser."
"that is unknown to DHParser."
)
)
(paragraph
(text
"Unknown begin-end-structures are always"
"considered as block elements and not"
"as inline elements."
)
(:Whitespace
""
""
)
) )
) )
(end_generic_block (paragraph
(end_environment (text
"generic" "Unknown begin-end-structures are always"
"considered as block elements and not"
"as inline elements."
) )
(NEW_LINE (:Whitespace
"" ""
"" ""
) )
) )
(end_environment
"generic"
)
) )
Match-test "2" Match-test "2"
...@@ -71,42 +57,20 @@ Match-test "2" ...@@ -71,42 +57,20 @@ Match-test "2"
### AST ### AST
(generic_block (generic_block
(begin_generic_block (begin_environment
(begin_environment "generic"
"generic" )
(paragraph
(text
"a single block paragraph"
) )
(NEW_LINE (:Whitespace
"" ""
"" ""
) )
) )
(sequence (end_environment
(paragraph "generic"
(text
"a single block paragraph"
)
(:Whitespace
""
""
)
)
)
(end_generic_block
(end_environment
"generic"
)
(NEW_LINE
(:RegExp
" "
)
(:RegExp
"% ending with"
)
(:RegExp
""
""
)
)
) )
) )
...@@ -120,15 +84,13 @@ Match-test "3" ...@@ -120,15 +84,13 @@ Match-test "3"
### AST ### AST
(quotation (quotation
(sequence (paragraph
(paragraph (text
(text "a known block element"
"a known block element" )
) (:Whitespace
(:Whitespace ""
"" ""
""
)
) )
) )
) )
...@@ -242,34 +204,7 @@ Match-test "1" ...@@ -242,34 +204,7 @@ Match-test "1"
\end{itemize} \end{itemize}
### AST ### AST
(itemize (itemize)
(item
(sequence
(paragraph
(text
"Items doe not need to be"
)
(:Whitespace
""
""
)
)
)