Commit da3181ba authored by eckhart's avatar eckhart

- corrected a few static type errors

parent 99ab9629
......@@ -320,7 +320,7 @@ def load_compiler_suite(compiler_suite: str) -> \
else:
# assume source is an ebnf grammar. Is there really any reasonable application case for this?
with logging(False):
compiler_py, messages, _ = compile_source(source, None, get_ebnf_grammar(),
compiler_py, messages, n = compile_source(source, None, get_ebnf_grammar(),
get_ebnf_transformer(), get_ebnf_compiler())
if has_errors(messages):
raise GrammarError(only_errors(messages), source)
......@@ -352,7 +352,7 @@ def is_outdated(compiler_suite: str, grammar_source: str) -> bool:
True, if ``compiler_suite`` seems to be out of date.
"""
try:
_, grammar, _, _ = load_compiler_suite(compiler_suite)
n1, grammar, n2, n3 = load_compiler_suite(compiler_suite)
return grammar_changed(grammar(), grammar_source)
except ValueError:
return True
......
......@@ -1842,23 +1842,33 @@ class NegativeLookahead(Lookahead):
class Lookbehind(FlowOperator):
"""
Matches, if the contained parser would match backwards. Requires
the contained parser to be a RegExp-parser.
the contained parser to be a RegExp, Re, PlainText or Token parser.
"""
def __init__(self, parser: Parser, name: str = '') -> None:
p = parser
while isinstance(p, Synonym):
p = p.parser
assert isinstance(p, RegExp), str(type(p))
self.regexp = cast(RE, p).main.regexp if isinstance(p, RE) else p.regexp
assert isinstance(p, RegExp) or isinstance(p, PlainText) or isinstance(p, RE), str(type(p))
self.regexp = None
self.text = None
if isinstance(p, RE):
if isinstance(cast(RE, p).main, RegExp):
self.regexp = cast(RegExp, cast(RE, p).main).regexp
else: # p.main is of type PlainText
self.text = cast(PlainText, cast(RE, p).main).text
elif isinstance(p, RegExp):
self.regexp = cast(RegExp, p).regexp
else: # p is of type PlainText
self.text = cast(PlainText, p).text
super().__init__(parser, name)
def __call__(self, text: StringView) -> Tuple[Optional[Node], StringView]:
# backwards_text = self.grammar.document__[-len(text) - 1::-1]
backwards_text = self.grammar.reversed__[len(text):]
if self.sign(backwards_text.match(self.regexp)):
return Node(self, ''), text
else:
return None, text
if self.regexp is None: # assert self.text is not None
does_match = backwards_text[:len(self.text)] == self.text
else: # assert self.regexp is not None
does_match = backwards_text.match(self.regexp)
return (Node(self, ''), text) if self.sign(does_match) else (None, text)
def __repr__(self):
return '-&' + self.parser.repr
......
......@@ -352,7 +352,7 @@ class Node(collections.abc.Sized):
"""
if self.children:
return "".join(child.content for child in self.children)
return self._result
return cast(str, self._result)
@property
......
......@@ -653,7 +653,7 @@ def rstrip(context: List[Node], condition: Callable = is_expendable):
@transformation_factory(Callable)
def strip(context: List[Node], condition: Callable = is_expendable) -> str:
def strip(context: List[Node], condition: Callable = is_expendable):
"""Removes leading and trailing child-nodes that fulfill a given condition."""
lstrip(context, condition)
rstrip(context, condition)
......
0
\documentclass[12pt, english, a4paper]{article}
\begin{document}
......
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