Commit cafc209b authored by di68kap's avatar di68kap
Browse files

- DHParser submodule: bugfix. length values for later added children

parent b3997558
......@@ -445,7 +445,6 @@ def log_ST(syntax_tree, log_file_name):
with open(path, "w", encoding="utf-8") as f:
LOG_SIZE_THRESHOLD = 10000 # maximum number of history records to log
LOG_TAIL_THRESHOLD = 500 # maximum number of history recors for "tail log"
......@@ -262,7 +262,8 @@ class Parser:
def __call__(self: 'Parser', text: StringView) -> Tuple[Optional[Node], StringView]:
"""Applies the parser to the given text. This is a wrapper method that adds
the business intelligence that is common to all parsers. The actual parsing is
done in the overridden method `_parse()`.
done in the overridden method `_parse()`. This wrapper-method can be thought of
as a "parser guard", because it guards the parsing process.
def get_error_node_id(error_node: Node, root_node: RootNode) -> int:
if error_node:
......@@ -715,8 +716,7 @@ class Grammar:
moving_forward__: This flag indicates that the parsing process is currently
moving forward . It is needed to reduce noise in history recording
and should not be considered as having a valid value if history
recording is turned off! (See :func:`add_parser_guard` and its local
function :func:`guarded_call`)
recording is turned off! (See :func:`Parser.__call__`)
recursion_locations__: Stores the locations where left recursion was
detected. Needed to provide minimal memoization for the left
......@@ -217,7 +217,7 @@ class Node: # ( Base class omitted for cython-compatibil
self._result = result # type: StrictResultType # cast(StrictResultType, result)
self.children = NO_CHILDREN # type: ChildrenType
self.result = result
self.tag_name = tag_name # type: str
def __deepcopy__(self, memo):
......@@ -316,16 +316,7 @@ class Node: # ( Base class omitted for cython-compatibil
return self._result
def result(self, result: ResultType):
# # made obsolete by static type checking with mypy
# assert ((isinstance(result, tuple) and all(isinstance(child, Node) for child in result))
# or isinstance(result, Node)
# or isinstance(result, str)
# or isinstance(result, StringView)), "%s (%s)" % (str(result), str(type(result)))
# Possible optimization: Do not allow single nodes as argument:
# assert not isinstance(result, Node)
# self._content = None
def __set_result(self, result: ResultType):
if isinstance(result, Node):
self.children = (result,)
self._result = self.children
......@@ -337,6 +328,17 @@ class Node: # ( Base class omitted for cython-compatibil
self.children = NO_CHILDREN
self._result = result # cast(StrictResultType, result)
def result(self, result: ResultType):
# fix position values for children that are added after the parsing process
if self._pos >= 0 and self.children:
p = self._pos
for child in self.children:
if child._pos < 0:
p = child._pos + len(child)
def _content(self) -> List[str]:
Returns string content as list of string fragments
......@@ -380,7 +382,7 @@ class Node: # ( Base class omitted for cython-compatibil
def with_pos(self, pos: int) -> 'Node':
Initialize position value. Usually, the parser guard
(`parsers.add_parser_guard()`) takes care of assigning the
(`parse.Parser.__call__`) takes care of assigning the
position in the document to newly created nodes. However,
when Nodes are created outside the reach of the parser
guard, their document-position must be assigned manually.
......@@ -393,6 +395,7 @@ class Node: # ( Base class omitted for cython-compatibil
# % (self._pos, pos, repr(self)))
if pos != self._pos >= 0:
raise AssertionError("Position value cannot be reassigned to a different value!")
assert pos >= 0, "Negative value %i not allowed!"
if self._pos < 0:
self._pos = pos
# recursively adjust pos-values of all children
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