Commit ba910eb5 authored by di68kap's avatar di68kap

- Codemap aus dem Installationsscript entfernt (wg. Fehlermeldungen auf Nutzerrechnern)

parent 9e71a764
...@@ -102,7 +102,8 @@ class Compiler: ...@@ -102,7 +102,8 @@ class Compiler:
context: A list of parent nodes that ends with the currently context: A list of parent nodes that ends with the currently
compiled node. compiled node.
tree: The root of the abstract syntax tree. tree: The root of the abstract syntax tree.
source: The source code. finalizers: A stack of tuples (function, parameters) that will be
called in reverse order after compilation.
_dirty_flag: A flag indicating that the compiler has already been _dirty_flag: A flag indicating that the compiler has already been
called at least once and that therefore all compilation called at least once and that therefore all compilation
...@@ -120,12 +121,28 @@ class Compiler: ...@@ -120,12 +121,28 @@ class Compiler:
def reset(self): def reset(self):
# self.source = '' # self.source = ''
self.finlizers = [] # type: List[Callable, Tuple]
self.tree = ROOTNODE_PLACEHOLDER # type: RootNode self.tree = ROOTNODE_PLACEHOLDER # type: RootNode
self.context = [] # type: List[Node] self.context = [] # type: List[Node]
self._None_check = True # type: bool self._None_check = True # type: bool
self._dirty_flag = False self._dirty_flag = False
self._debug = get_config_value('debug') # type: bool self._debug = get_config_value('debug') # type: bool
self._debug_already_compiled = set() # type: Set[Node] self._debug_already_compiled = set() # type: Set[Node]
self.finalizers = [] # type: List[Callable, Tuple]
def prepare(self) -> None:
"""
A preparation method that will be called after everything else has
been initialized and immediately before compilation starts. This method
can be overwritten in order to implement preparation tasks.
"""
pass
def finalize(self) -> None:
"""
A finalization method that is called after compilation has finished and
after all tasks from the finalizers stack have been executed
"""
def __call__(self, root: RootNode) -> Any: def __call__(self, root: RootNode) -> Any:
""" """
...@@ -141,7 +158,11 @@ class Compiler: ...@@ -141,7 +158,11 @@ class Compiler:
self._dirty_flag = True self._dirty_flag = True
self.tree = root # type: RootNode self.tree = root # type: RootNode
# self.source = source # type: str # self.source = source # type: str
self.prepare()
result = self.compile(root) result = self.compile(root)
while self.finalizers:
task, parameters = self.finalizers.pop()
task(*parameters)
return result return result
# Obsolete, because never used... # Obsolete, because never used...
......
...@@ -502,6 +502,7 @@ class Node: # (collections.abc.Sized): Base class omitted for cython-compatibil ...@@ -502,6 +502,7 @@ class Node: # (collections.abc.Sized): Base class omitted for cython-compatibil
Node: All nodes which have a given tag name. Node: All nodes which have a given tag name.
Raises: Raises:
KeyError: if no matching child was found. KeyError: if no matching child was found.
IndexError: if key was an integer index that did not exist
ValueError: if the __getitem__ has been called on a leaf node. ValueError: if the __getitem__ has been called on a leaf node.
""" """
if self.children: if self.children:
...@@ -513,7 +514,7 @@ class Node: # (collections.abc.Sized): Base class omitted for cython-compatibil ...@@ -513,7 +514,7 @@ class Node: # (collections.abc.Sized): Base class omitted for cython-compatibil
if mf(child): if mf(child):
return child return child
raise KeyError(str(key)) raise KeyError(str(key))
raise ValueError('Leave nodes have no children that can be indexed!') raise ValueError('Leaf-nodes have no children that can be indexed!')
def __contains__(self, what: CriteriaType) -> bool: def __contains__(self, what: CriteriaType) -> bool:
""" """
...@@ -533,7 +534,7 @@ class Node: # (collections.abc.Sized): Base class omitted for cython-compatibil ...@@ -533,7 +534,7 @@ class Node: # (collections.abc.Sized): Base class omitted for cython-compatibil
if mf(child): if mf(child):
return True return True
return False return False
raise ValueError('Leave node cannot contain other nodes') raise ValueError('Leaf-node cannot contain other nodes')
def index(self, what: CriteriaType, start: int = 0, stop: int = sys.maxsize) -> int: def index(self, what: CriteriaType, start: int = 0, stop: int = sys.maxsize) -> int:
""" """
...@@ -546,6 +547,7 @@ class Node: # (collections.abc.Sized): Base class omitted for cython-compatibil ...@@ -546,6 +547,7 @@ class Node: # (collections.abc.Sized): Base class omitted for cython-compatibil
:param start: the first index to start searching. :param start: the first index to start searching.
:param stop: the last index that shall be searched :param stop: the last index that shall be searched
:return: the index of the first child with the given tag name. :return: the index of the first child with the given tag name.
:raises: ValueError, if no child matching the criterion `what` was found.
""" """
assert 0 <= start < stop assert 0 <= start < stop
i = start i = start
......
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