Commit 80994035 authored by eckhart's avatar eckhart
Browse files

cython compatibility restored

parent b0fe4ce4
......@@ -227,9 +227,9 @@ class EBNFGrammar(Grammar):
@property
def mode(self) -> str:
def which(p: Parser) -> str:
if p._parse.__qualname__ == 'Never._parse':
if p._parse_proxy.__qualname__ == 'Never._parse':
return 'never'
elif p._parse.__qualname__ == 'Always._parse':
elif p._parse_proxy.__qualname__ == 'Always._parse':
return 'always'
else:
return 'custom'
......@@ -253,9 +253,9 @@ class EBNFGrammar(Grammar):
def mode(self, mode: str):
def set_parsefunc(p: Parser, f: ParseFunc):
method = f.__get__(p, type(p)) # bind function f to parser p
if p._parse == p._parse_proxy:
p._parse_proxy = method
p._parse = method
# if p._parse == p._parse_proxy:
p._parse_proxy = method
# p._parse = method
always = Always._parse
never = Never._parse
......
......@@ -14,10 +14,9 @@ cdef class Parser:
cdef object visited
cdef object recursion_counter
cdef object cycle_detection
cdef object _parse_proxy
cdef public object _parse_proxy
cdef str _symbol
cpdef _parse(self, text)
cpdef reset(self)
# def __call__(self, StringView text)
# def __add__(self, other)
......@@ -89,6 +88,9 @@ cdef class ZeroOrMore(Option):
cdef class OneOrMore(UnaryParser):
pass
cdef class Counted(UnaryParser):
cdef public (int, int) repetitions
cdef class MandatoryNary(NaryParser):
cdef public int mandatory
cdef public object err_msgs
......@@ -100,7 +102,7 @@ cdef class Series(MandatoryNary):
cdef class Alternative(NaryParser):
pass
cdef class AllOf(MandatoryNary):
cdef class Interleave(MandatoryNary):
cdef public object repetitions
cdef public object non_mandatory
cdef public object parsers_set
......@@ -134,6 +136,5 @@ cdef class Pop(Retrieve):
cdef class Synonym(UnaryParser):
pass
cdef class Forward(Parser):
cdef public object parser
cdef class Forward(UnaryParser):
cdef public bint cycle_reached
......@@ -118,7 +118,7 @@ class ParserError(Exception):
Currently, the only case when a `ParserError` is thrown (and not some
different kind of error like `UnknownParserError`) is when a `Series`-
or `AllOf`-parser detects a missing mandatory element.
or `Interleave`-parser detects a missing mandatory element.
"""
def __init__(self, node: Node, rest: StringView, error: Error, first_throw: bool):
assert node is not None
......@@ -720,7 +720,7 @@ def collect_leaf_parsers(starting_point: Parser,
"""
lp_dict = {starting_point: cache.get(starting_point, set())} # type: Dict[Parser, Set[Parser]]
def associate_leaf_parsers(context: Parser):
def associate_leaf_parsers(context: List[Parser]):
parser = context[-1]
if parser not in context[:-1]:
if parser in cache:
......@@ -2168,7 +2168,7 @@ class Counted(UnaryParser):
"""
def __init__(self, parser: Parser, repetitions: Tuple[int, int]) -> None:
super(Counted, self).__init__(parser)
self.repetitions = repetitions
self.repetitions = repetitions # type: Tuple[int, int]
def __deepcopy__(self, memo):
parser = copy.deepcopy(self.parser, memo)
......@@ -2176,6 +2176,7 @@ class Counted(UnaryParser):
copy_parser_base_attrs(self, duplicate)
return duplicate
@cython.locals(n=cython.int, length=cython.int)
def _parse(self, text: StringView):
results = () # Tuple[Node, ...]
text_ = text
......@@ -2206,6 +2207,7 @@ class Counted(UnaryParser):
def __repr__(self):
return self.parser.repr + "{%i,%i}" % self.repetitions
@cython.locals(a=cython.int, b=cython.int)
def static_analysis(self) -> List['AnalysisError']:
errors = super().static_analysis()
a, b = self.repetitions
......@@ -2239,7 +2241,6 @@ class MandatoryNary(NaryParser):
each of these. The closest match is the point where parsing will be
resumed.
"""
def __init__(self, *parsers: Parser,
mandatory: int = NO_MANDATORY,
err_msgs: MessagesType = [],
......@@ -2281,7 +2282,7 @@ class MandatoryNary(NaryParser):
is attached, and the text segment where parsing is to continue.
This is a helper function that abstracts functionality that is
needed by the AllOf- as well as the Series-parser.
needed by the Interleave- as well as the Series-parser.
:param parser: the grammar
:param text_: the point, where the mandatory violation. As usual the
......@@ -2623,6 +2624,7 @@ class Interleave(MandatoryNary):
copy_parser_base_attrs(self, duplicate)
return duplicate
@cython.locals(i=cython.int, n=cython.int, length=cython.int, reloc=cython.int)
def _parse(self, text: StringView):
results = () # type: Tuple[Node, ...]
text_ = text # type: StringView
......@@ -2720,6 +2722,7 @@ class Interleave(MandatoryNary):
self.repetitions = repetitions
return self
@cython.locals(a=cython.int, b=cython.int)
def static_analysis(self) -> List['AnalysisError']:
# assert len(set(parsers)) == len(parsers) # commented out, because this could make sense
errors = super().static_analysis()
......
......@@ -27,7 +27,7 @@ from DHParser import is_filename, Grammar, Compiler, Lookbehind, Alternative, Po
PreprocessorFunc, Node, TransformationFunc, traverse, remove_children_if, \
reduce_single_child, replace_by_single_child, remove_whitespace, remove_empty, \
flatten, is_empty, collapse, remove_brackets, strip, \
is_one_of, remove_tokens, remove_children, TOKEN_PTYPE, Error, \
is_one_of, remove_tokens, remove_children, TOKEN_PTYPE, WARNING, \
access_thread_locals, recompile_grammar, get_config_value, \
transform_content, replace_content_with, resume_notices_on, set_tracer, trace_history
from DHParser.log import start_logging
......@@ -536,7 +536,7 @@ class LaTeXCompiler(Compiler):
else:
self.tree.new_error(node, 'Only one document language supported. '
'Using %s, ignoring %s.'
% (self.metadata['language'], it), Error.WARNING)
% (self.metadata['language'], it), WARNING)
if node['block'].content in self.KNOWN_DOCUMENT_CLASSES:
self.metadata['documentclass'] = node['block'].content
return node
......
Supports Markdown
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