2.12.2021, 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

Commit 3558cc35 authored by eckhart's avatar eckhart
Browse files

- compile.compile_source: removed unecessary error collecting calls

parent b30733c0
...@@ -249,19 +249,20 @@ def compile_source(source: str, ...@@ -249,19 +249,20 @@ def compile_source(source: str,
# only compile if there were no syntax errors, for otherwise it is # only compile if there were no syntax errors, for otherwise it is
# likely that error list gets littered with compile error messages # likely that error list gets littered with compile error messages
result = None result = None
efl = syntax_tree.error_flag # efl = syntax_tree.error_flag
messages = syntax_tree.collect_errors(clear_errors=True) # messages = syntax_tree.collect_errors(clear_errors=True)
if not is_error(efl): if not is_error(syntax_tree.error_flag):
transformer(syntax_tree) transformer(syntax_tree)
efl = max(efl, syntax_tree.error_flag) # efl = max(efl, syntax_tree.error_flag)
messages.extend(syntax_tree.collect_errors(clear_errors=True)) # messages.extend(syntax_tree.collect_errors(clear_errors=True))
if is_logging(): if is_logging():
log_ST(syntax_tree, log_file_name + '.ast') log_ST(syntax_tree, log_file_name + '.ast')
if not is_error(syntax_tree.error_flag): if not is_error(syntax_tree.error_flag):
result = compiler(syntax_tree) result = compiler(syntax_tree)
# print(syntax_tree.as_sxpr()) # print(syntax_tree.as_sxpr())
messages.extend(syntax_tree.collect_errors()) # messages.extend(syntax_tree.collect_errors())
syntax_tree.error_flag = max(syntax_tree.error_flag, efl) # syntax_tree.error_flag = max(syntax_tree.error_flag, efl)
messages = syntax_tree.collect_errors()
adjust_error_locations(messages, original_text, source_mapping) adjust_error_locations(messages, original_text, source_mapping)
return result, messages, syntax_tree return result, messages, syntax_tree
...@@ -84,10 +84,12 @@ class Error: ...@@ -84,10 +84,12 @@ class Error:
self.orig_pos = orig_pos self.orig_pos = orig_pos
self.line = line self.line = line
self.column = column self.column = column
self._node = node if node is not None and node._pos >= 0:
if node is not None:
assert self._pos < 0 or self._pos == node._pos assert self._pos < 0 or self._pos == node._pos
self._pos = node._pos self._pos = node._pos
self._node = None # if node is not needed, if pos has been set
else:
self._node = node
def __str__(self): def __str__(self):
prefix = '' prefix = ''
...@@ -102,12 +104,11 @@ class Error: ...@@ -102,12 +104,11 @@ class Error:
@property @property
def pos(self): def pos(self):
if self._pos < 0: if self._pos < 0:
assert self._node and self._node.pos >= 0 assert self._node and self._node.pos >= 0, "pos value not ready yet"
self._pos = self._node.pos # lazy evaluation of position self._pos = self._node.pos # lazy evaluation of position
self._node = None # forget node to allow GC to free memory self._node = None # forget node to allow GC to free memory
return self._pos return self._pos
@property @property
def severity(self): def severity(self):
"""Returns a string representation of the error level, e.g. "warning".""" """Returns a string representation of the error level, e.g. "warning"."""
......
...@@ -751,6 +751,8 @@ class RootNode(Node): ...@@ -751,6 +751,8 @@ class RootNode(Node):
# err.pos = node.pos # err.pos = node.pos
self.all_errors.sort(key=lambda e: e.pos) self.all_errors.sort(key=lambda e: e.pos)
errors = self.all_errors errors = self.all_errors
for error in self.all_errors:
_ = error.pos
if clear_errors: if clear_errors:
self.all_errors = [] self.all_errors = []
self.error_flag = 0 self.error_flag = 0
......
...@@ -106,7 +106,7 @@ Fail-test "10" ...@@ -106,7 +106,7 @@ Fail-test "10"
Error: Parser did not match! Invalid source file? Error: Parser did not match! Invalid source file?
Most advanced: None Most advanced: None
Last match: None; Last match: None;
Error: Capture-retrieve-stack not empty after end of parsing: defaultdict(<function Grammar._reset__.<locals>.<lambda> at 0x0000000003A93488>, {'NAME': ['generic']}) Error: Capture-retrieve-stack not empty after end of parsing: defaultdict(<function Grammar._reset__.<locals>.<lambda> at 0x7f2f0767de18>, {'NAME': ['generic']})
Fail-test "11" Fail-test "11"
-------------- --------------
...@@ -123,7 +123,7 @@ Error: Parser did not match! Invalid source file? ...@@ -123,7 +123,7 @@ Error: Parser did not match! Invalid source file?
Error: Parser did not match! Invalid source file? Error: Parser did not match! Invalid source file?
Most advanced: None Most advanced: None
Last match: None; Last match: None;
Error: Capture-retrieve-stack not empty after end of parsing: defaultdict(<function Grammar._reset__.<locals>.<lambda> at 0x0000000003A93598>, {'NAME': ['generic']}) Error: Capture-retrieve-stack not empty after end of parsing: defaultdict(<function Grammar._reset__.<locals>.<lambda> at 0x7f2f0767dd90>, {'NAME': ['generic']})
Fail-test "12" Fail-test "12"
-------------- --------------
...@@ -135,7 +135,7 @@ Fail-test "12" ...@@ -135,7 +135,7 @@ Fail-test "12"
### Messages: ### Messages:
Error: -&LB end_environment LFF expected; "\end{gener" found! Error: -&LB end_environment LFF expected; "\end{gener" found!
Error: Capture-retrieve-stack not empty after end of parsing: defaultdict(<function Grammar._reset__.<locals>.<lambda> at 0x0000000003A93488>, {'NAME': ['generic']}) Error: Capture-retrieve-stack not empty after end of parsing: defaultdict(<function Grammar._reset__.<locals>.<lambda> at 0x7f2f0767de18>, {'NAME': ['generic']})
Test of parser: "inline_environment" Test of parser: "inline_environment"
...@@ -215,7 +215,7 @@ Error: Parser did not match! Invalid source file? ...@@ -215,7 +215,7 @@ Error: Parser did not match! Invalid source file?
Error: Parser did not match! Invalid source file? Error: Parser did not match! Invalid source file?
Most advanced: None Most advanced: None
Last match: None; Last match: None;
Error: Capture-retrieve-stack not empty after end of parsing: defaultdict(<function Grammar._reset__.<locals>.<lambda> at 0x0000000003A93488>, {'NAME': ['generic']}) Error: Capture-retrieve-stack not empty after end of parsing: defaultdict(<function Grammar._reset__.<locals>.<lambda> at 0x7f2f0767de18>, {'NAME': ['generic']})
Test of parser: "itemize" Test of parser: "itemize"
......
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