Commit 03d7fcec authored by di68kap's avatar di68kap
Browse files

preprocess.py: Refactoring

parent d63e24d4
......@@ -164,10 +164,11 @@ href = "\href{" urlstring "}" block
block = "{" _block_content §`}`
_block_content = { (block_environment | text_element | paragraph) [_PARSEP|S] }
# text = CHARS { (S | trennung) CHARS }
# text = LINE { (S | trennung) LINE }
text = TEXT { (S | trennung) TEXT }
trennung = `\-`
# text = CHARS { (S | special) CHARS }
# text = LINE { (S | special) LINE }
text = TEXT { (S | special) TEXT }
special = `\-` | /\\/ esc_char
esc_char = `,`
no_command = "\begin{" | "\end" | BACKSLASH structural
blockcmd = BACKSLASH ( ( "begin{" | "end{" )
......
......@@ -95,7 +95,7 @@ class LaTeXGrammar(Grammar):
paragraph = Forward()
param_block = Forward()
text_element = Forward()
source_hash__ = "c73ecd46ffeee31f3ed6a42cd981c3b0"
source_hash__ = "d553c458ce956b89cbccdbe24495dac8"
disposable__ = re.compile('_WSPC$|_GAP$|_LB$|_PARSEP$|_LETTERS$|_NAME$|INTEGER$|FRAC$|_QUALIFIED$|TEXT_NOPAR$|TEXT$|_block_content$|PATH$|PATHSEP$|HASH$|COLON$|TAG$|block_environment$|known_environment$|text_element$|line_element$|inline_environment$|known_inline_env$|info_block$|begin_inline_env$|end_inline_env$|command$|known_command$')
static_analysis_pending__ = [] # type: List[bool]
parser_initialization__ = ["upon instantiation"]
......@@ -141,7 +141,7 @@ class LaTeXGrammar(Grammar):
TXTCOMMAND = RegExp('\\\\text\\w+')
CMDNAME = Series(RegExp('\\\\(?:(?![\\d_])\\w)+'), dwsp__)
WARN_Komma = Series(Text(","), dwsp__)
trennung = Text("\\-")
esc_char = Text(",")
number = Series(INTEGER, Option(FRAC))
magnitude = Series(number, Option(UNIT))
info_value = Series(TEXT_NOPAR, ZeroOrMore(Series(S, TEXT_NOPAR)))
......@@ -155,10 +155,11 @@ class LaTeXGrammar(Grammar):
parameters = Series(Alternative(association, flag), ZeroOrMore(Series(Series(Drop(Text(",")), dwsp__), Alternative(association, flag))), Option(WARN_Komma))
sequence = Series(Option(_WSPC), OneOrMore(Series(Alternative(paragraph, block_environment), Option(Alternative(_PARSEP, S)))))
block_of_paragraphs = Series(Series(Drop(Text("{")), dwsp__), Option(sequence), Series(Drop(Text("}")), dwsp__), mandatory=2)
text = Series(TEXT, ZeroOrMore(Series(Alternative(S, trennung), TEXT)))
special = Alternative(Drop(Text("\\-")), Series(Drop(RegExp('\\\\')), esc_char))
structural = Alternative(Series(Drop(Text("subsection")), dwsp__), Series(Drop(Text("section")), dwsp__), Series(Drop(Text("chapter")), dwsp__), Series(Drop(Text("subsubsection")), dwsp__), Series(Drop(Text("paragraph")), dwsp__), Series(Drop(Text("subparagraph")), dwsp__), Series(Drop(Text("item")), dwsp__))
begin_environment = Series(Drop(RegExp('\\\\begin{')), NAME, Drop(RegExp('}')), mandatory=1)
no_command = Alternative(Series(Drop(Text("\\begin{")), dwsp__), Series(Drop(Text("\\end")), dwsp__), Series(BACKSLASH, structural))
text = Series(TEXT, ZeroOrMore(Series(Alternative(S, special), TEXT)))
cfg_text = ZeroOrMore(Alternative(Series(dwsp__, text), CMDNAME, SPECIAL))
config = Series(Series(Drop(Text("[")), dwsp__), Alternative(Series(parameters, Lookahead(Series(Drop(Text("]")), dwsp__))), cfg_text), Series(Drop(Text("]")), dwsp__), mandatory=1)
_block_content = ZeroOrMore(Series(Alternative(block_environment, text_element, paragraph), Option(Alternative(_PARSEP, S))))
......@@ -247,7 +248,6 @@ class LaTeXGrammar(Grammar):
_raw_grammar = ThreadLocalSingletonFactory(LaTeXGrammar, ident=1)
def get_grammar() -> LaTeXGrammar:
grammar = _raw_grammar()
if get_config_value('resume_notices'):
......@@ -255,8 +255,7 @@ def get_grammar() -> LaTeXGrammar:
elif get_config_value('history_tracking'):
set_tracer(grammar, trace_history)
return grammar
def parse_LaTeX(document, start_parser = "root_parser__", *, complete_match=True):
return get_grammar()(document, start_parser, complete_match)
......@@ -382,7 +381,6 @@ LaTeX_AST_transformation_table = {
"block": [flatten, reduce_single_child],
"flag": [reduce_single_child],
"text": collapse,
"trennung": replace_content_with(''),
"no_command, blockcmd": [],
"structural": [],
"CMDNAME": [remove_whitespace, reduce_single_child],
......
[match:command]
[match:special]
M1: "\-"
M2: "\,"
M1: \label{name}
M2: \ref{name}
M3: \pageref{name}
M4: \url{https://publikationen.badw.de}
M5: \href{https://publikationen.badw.de}{BAdW}
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