Commit edb48e86 authored by di68kap's avatar di68kap

Merge remote-tracking branch 'origin/development' into development

parents 58fae0e2 ba910eb5
......@@ -102,7 +102,8 @@ class Compiler:
context: A list of parent nodes that ends with the currently
compiled node.
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
called at least once and that therefore all compilation
......@@ -120,12 +121,28 @@ class Compiler:
def reset(self):
# self.source = ''
self.finlizers = [] # type: List[Callable, Tuple]
self.tree = ROOTNODE_PLACEHOLDER # type: RootNode
self.context = [] # type: List[Node]
self._None_check = True # type: bool
self._dirty_flag = False
self._debug = get_config_value('debug') # type: bool
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.
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:
......@@ -141,7 +158,11 @@ class Compiler:
self._dirty_flag = True
self.tree = root # type: RootNode
# self.source = source # type: str
result = self.compile(root)
while self.finalizers:
task, parameters = self.finalizers.pop()
return result
# Obsolete, because never used...
......@@ -502,6 +502,7 @@ class Node: # ( Base class omitted for cython-compatibil
Node: All nodes which have a given tag name.
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.
if self.children:
......@@ -513,7 +514,7 @@ class Node: # ( Base class omitted for cython-compatibil
if mf(child):
return child
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:
......@@ -533,7 +534,7 @@ class Node: # ( Base class omitted for cython-compatibil
if mf(child):
return True
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:
......@@ -546,6 +547,7 @@ class Node: # ( Base class omitted for cython-compatibil
:param start: the first index to start searching.
:param stop: the last index that shall be searched
: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
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