Starting from 2021-07-01, all LRZ GitLab users will be required to explicitly accept the GitLab Terms of Service. Please see the detailed information at https://doku.lrz.de/display/PUBLIC/GitLab and make sure that your projects conform to the requirements.

Commit a5ef6415 authored by Eckhart Arnold's avatar Eckhart Arnold
Browse files

- full memoization ready; some optimizations

parent 1b34aa1d
...@@ -153,8 +153,9 @@ ZOMBIE_PARSER = ZombieParser() ...@@ -153,8 +153,9 @@ ZOMBIE_PARSER = ZombieParser()
# msg: str # msg: str
Error = NamedTuple('Error', [('pos', int), ('msg', str)]) Error = NamedTuple('Error', [('pos', int), ('msg', str)])
StrictResultType = Union[Tuple['Node', ...], str] ChildrenType = Tuple['Node', ...]
ResultType = Union[Tuple['Node', ...], 'Node', str, None] StrictResultType = Union[ChildrenType, str]
ResultType = Union[ChildrenType, 'Node', str, None]
class Node: class Node:
...@@ -204,7 +205,7 @@ class Node: ...@@ -204,7 +205,7 @@ class Node:
""" """
self._result = '' # type: StrictResultType self._result = '' # type: StrictResultType
self._errors = [] # type: List[str] self._errors = [] # type: List[str]
self._children = () # type: Tuple['Node', ...] self._children = () # type: ChildrenType
self.result = result self.result = result
self._len = len(self.result) if not self.children else \ self._len = len(self.result) if not self.children else \
sum(child._len for child in self.children) # type: int sum(child._len for child in self.children) # type: int
...@@ -254,11 +255,11 @@ class Node: ...@@ -254,11 +255,11 @@ class Node:
# or isinstance(result, Node) # or isinstance(result, Node)
# or isinstance(result, str)), str(result) # or isinstance(result, str)), str(result)
self._result = (result,) if isinstance(result, Node) else result or '' self._result = (result,) if isinstance(result, Node) else result or ''
self._children = cast(Tuple['Node', ...], self._result) \ self._children = cast(ChildrenType, self._result) \
if isinstance(self._result, tuple) else cast(Tuple['Node', ...], ()) if isinstance(self._result, tuple) else cast(ChildrenType, ())
@property @property
def children(self) -> Tuple['Node', ...]: def children(self) -> ChildrenType:
return self._children return self._children
@property @property
......
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