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

Commit 90d11281 authored by Eckhart Arnold's avatar Eckhart Arnold
Browse files

further LaTeX.ebnf tests

parent 9a6df97d
...@@ -432,9 +432,9 @@ def remove_tokens(node, tokens: AbstractSet[str] = frozenset()): ...@@ -432,9 +432,9 @@ def remove_tokens(node, tokens: AbstractSet[str] = frozenset()):
@transformation_factory @transformation_factory
def remove_parser(node, regexp: str): def remove_parser(node, tag_names: AbstractSet[str]):
"""Removes children by 'tag name'.""" """Removes children by tag name."""
remove_children_if(node, partial(is_one_of, regexp=regexp)) remove_children_if(node, partial(is_one_of, tag_name_set=tag_names))
@transformation_factory @transformation_factory
......
...@@ -144,8 +144,9 @@ ESCAPED = /\\[%$&_\/]/ ...@@ -144,8 +144,9 @@ ESCAPED = /\\[%$&_\/]/
BRACKETS = /[\[\]]/ # left or right square bracket: [ ] BRACKETS = /[\[\]]/ # left or right square bracket: [ ]
TEXTCHUNK = /[^\\%$&\{\}\[\]\s\n]+/ # some piece of text excluding whitespace, TEXTCHUNK = /[^\\%$&\{\}\[\]\s\n]+/ # some piece of text excluding whitespace,
# linefeed and special characters # linefeed and special characters
LF = !PARSEP /[ \t]*\n[ \t]*/ # linefeed but not an empty line LF = !GAP /[ \t]*\n[ \t]*/ # linefeed but not an empty line
PARSEP = /[ \t]*(?:\n[ \t]*)+\n[ \t]*/ # at least one empty line, i.e. PARSEP = { GAP }+ # paragraph separator
GAP = /[ \t]*(?:\n[ \t]*)+\n/~ # at least one empty line, i.e.
# [whitespace] linefeed [whitespace] linefeed # [whitespace] linefeed [whitespace] linefeed
LB = /\s*?\n|$/ # backwards line break for Lookbehind-Operator LB = /\s*?\n|$/ # backwards line break for Lookbehind-Operator
# beginning of text marker '$' added for test code # beginning of text marker '$' added for test code
......
...@@ -155,7 +155,7 @@ class LaTeXGrammar(Grammar): ...@@ -155,7 +155,7 @@ class LaTeXGrammar(Grammar):
generic_command = !no_command CMDNAME [[ //~ config ] //~ block ] generic_command = !no_command CMDNAME [[ //~ config ] //~ block ]
footnote = "\footnote" block_of_paragraphs footnote = "\footnote" block_of_paragraphs
includegraphics = "\includegraphics" config block includegraphics = "\includegraphics" [ config ] block
caption = "\caption" block caption = "\caption" block
...@@ -197,8 +197,9 @@ class LaTeXGrammar(Grammar): ...@@ -197,8 +197,9 @@ class LaTeXGrammar(Grammar):
BRACKETS = /[\[\]]/ # left or right square bracket: [ ] BRACKETS = /[\[\]]/ # left or right square bracket: [ ]
TEXTCHUNK = /[^\\%$&\{\}\[\]\s\n]+/ # some piece of text excluding whitespace, TEXTCHUNK = /[^\\%$&\{\}\[\]\s\n]+/ # some piece of text excluding whitespace,
# linefeed and special characters # linefeed and special characters
LF = !PARSEP /[ \t]*\n[ \t]*/ # linefeed but not an empty line LF = !GAP /[ \t]*\n[ \t]*/ # linefeed but not an empty line
PARSEP = /[ \t]*(?:\n[ \t]*)+\n[ \t]*/ # at least one empty line, i.e. PARSEP = { GAP }+ # paragraph separator
GAP = /[ \t]*(?:\n[ \t]*)+\n/~ # at least one empty line, i.e.
# [whitespace] linefeed [whitespace] linefeed # [whitespace] linefeed [whitespace] linefeed
LB = /\s*?\n|$/ # backwards line break for Lookbehind-Operator LB = /\s*?\n|$/ # backwards line break for Lookbehind-Operator
# beginning of text marker '$' added for test code # beginning of text marker '$' added for test code
...@@ -211,7 +212,7 @@ class LaTeXGrammar(Grammar): ...@@ -211,7 +212,7 @@ class LaTeXGrammar(Grammar):
block_of_paragraphs = Forward() block_of_paragraphs = Forward()
end_generic_block = Forward() end_generic_block = Forward()
text_element = Forward() text_element = Forward()
source_hash__ = "4e001b31490278efccfe43953bfdcf58" source_hash__ = "9cdeab7d908861b396d3667373fdcb9a"
parser_initialization__ = "upon instantiation" parser_initialization__ = "upon instantiation"
COMMENT__ = r'%.*(?:\n|$)' COMMENT__ = r'%.*(?:\n|$)'
WSP__ = mixin_comment(whitespace=r'[ \t]*(?:\n(?![ \t]*\n)[ \t]*)?', comment=r'%.*(?:\n|$)') WSP__ = mixin_comment(whitespace=r'[ \t]*(?:\n(?![ \t]*\n)[ \t]*)?', comment=r'%.*(?:\n|$)')
...@@ -220,8 +221,9 @@ class LaTeXGrammar(Grammar): ...@@ -220,8 +221,9 @@ class LaTeXGrammar(Grammar):
EOF = RegExp('(?!.)') EOF = RegExp('(?!.)')
BACKSLASH = RegExp('[\\\\]') BACKSLASH = RegExp('[\\\\]')
LB = RegExp('\\s*?\\n|$') LB = RegExp('\\s*?\\n|$')
PARSEP = RegExp('[ \\t]*(?:\\n[ \\t]*)+\\n[ \\t]*') GAP = RE('[ \\t]*(?:\\n[ \\t]*)+\\n')
LF = Series(NegativeLookahead(PARSEP), RegExp('[ \\t]*\\n[ \\t]*')) PARSEP = OneOrMore(GAP)
LF = Series(NegativeLookahead(GAP), RegExp('[ \\t]*\\n[ \\t]*'))
TEXTCHUNK = RegExp('[^\\\\%$&\\{\\}\\[\\]\\s\\n]+') TEXTCHUNK = RegExp('[^\\\\%$&\\{\\}\\[\\]\\s\\n]+')
BRACKETS = RegExp('[\\[\\]]') BRACKETS = RegExp('[\\[\\]]')
ESCAPED = RegExp('\\\\[%$&_/]') ESCAPED = RegExp('\\\\[%$&_/]')
...@@ -236,7 +238,7 @@ class LaTeXGrammar(Grammar): ...@@ -236,7 +238,7 @@ class LaTeXGrammar(Grammar):
block = Series(RegExp('{'), ZeroOrMore(text_element), Required(RegExp('}'))) block = Series(RegExp('{'), ZeroOrMore(text_element), Required(RegExp('}')))
config = Series(Token("["), cfgtext, Required(Token("]"))) config = Series(Token("["), cfgtext, Required(Token("]")))
caption = Series(Token("\\caption"), block) caption = Series(Token("\\caption"), block)
includegraphics = Series(Token("\\includegraphics"), config, block) includegraphics = Series(Token("\\includegraphics"), Optional(config), block)
footnote = Series(Token("\\footnote"), block_of_paragraphs) footnote = Series(Token("\\footnote"), block_of_paragraphs)
generic_command = Series(NegativeLookahead(no_command), CMDNAME, Optional(Series(Optional(Series(RE(''), config)), RE(''), block))) generic_command = Series(NegativeLookahead(no_command), CMDNAME, Optional(Series(Optional(Series(RE(''), config)), RE(''), block)))
known_command = Alternative(footnote, includegraphics, caption) known_command = Alternative(footnote, includegraphics, caption)
...@@ -324,7 +326,8 @@ def watch(node): ...@@ -324,7 +326,8 @@ def watch(node):
LaTeX_AST_transformation_table = { LaTeX_AST_transformation_table = {
# AST Transformations for the LaTeX-grammar # AST Transformations for the LaTeX-grammar
"+": remove_empty, "+": remove_children_if(lambda node: is_empty(node) or is_one_of(node, {'PARSEP'})),
# remove_empty,
"latexdoc": [], "latexdoc": [],
"preamble": [], "preamble": [],
"document": [], "document": [],
...@@ -383,6 +386,7 @@ LaTeX_AST_transformation_table = { ...@@ -383,6 +386,7 @@ LaTeX_AST_transformation_table = {
"TEXTCHUNK": [], "TEXTCHUNK": [],
"LF": [], "LF": [],
"PARSEP": replace_content(lambda node: '\n\n'), "PARSEP": replace_content(lambda node: '\n\n'),
"GAP": [],
"LB": [], "LB": [],
"BACKSLASH": [], "BACKSLASH": [],
"EOF": [], "EOF": [],
......
...@@ -96,16 +96,41 @@ ...@@ -96,16 +96,41 @@
\item Only that the bullets are numbers. \item Only that the bullets are numbers.
\end{enumerate} \end{enumerate}
2: \begin{enumerate} 2 : \begin{enumerate}
\item \begin{itemize} \item \begin{itemize}
\item Item-lists and \item Item-lists and
\item Enumeration-lists \item Enumeration-lists
\begin{enumerate} \begin{enumerate}
\item can be nested \item can be nested
\item arbitrarily \item arbitrarily
\end{enumerate} \end{enumerate}
\item Another item \item Another item
\end{itemize} \end{itemize}
\item Plain numerated item. \item Plain numerated item.
\end{enumerate} \end{enumerate}
3 : \begin{enumerate} % comment
% more comments and paragraph separators
% yet some more
\item %another comment
finally, the first item
% comment
\end{enumerate}
4 : \begin{enumerate}
\item An item
\begin{itemize}
\item with an enumeration
\end{itemize}
as a separate paragraph
\end{enumerate}
...@@ -49,8 +49,19 @@ ...@@ -49,8 +49,19 @@
The parser should accept this, too. The parser should accept this, too.
3 : Paragraphs can be delimited by % comment
3 : Sequences of paragraphs may % sequences of separators
% and comments
In the end such a sequence counts
% merely as one comment
4 : Sequences of paragraphs may
\begin{quotation} \begin{quotation}
include block environments include block environments
\end{quotation} \end{quotation}
......
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