First but not optimized version of AstFormatDict

This commit is contained in:
2020-11-24 13:43:04 +01:00
parent ab30ab3345
commit cac732bd93
21 changed files with 898 additions and 217 deletions
+5
View File
@@ -129,12 +129,14 @@ class DefConceptEvaluator(OneReturnValueEvaluator):
This function can only be a draft, as there may be tons of different situations
I guess that it can only be complete when will we have access to Sheerka memory
"""
debugger = context.get_debugger(DefConceptEvaluator.NAME, "get_variables")
#
# Case of NameNode
#
if isinstance(ret_value, NameNode):
names = [str(t.value) for t in ret_value.tokens if t.type in (
TokenKind.IDENTIFIER, TokenKind.STRING, TokenKind.KEYWORD)]
debugger.debug_var("names", names, hint="from NameNode")
return set(filter(lambda x: x in concept_name and context.sheerka.not_is_variable(x), names))
#
@@ -143,6 +145,7 @@ class DefConceptEvaluator(OneReturnValueEvaluator):
if isinstance(ret_value.value, ParserResultConcept) and isinstance(ret_value.value.value, ParsingExpression):
visitor = ConceptOrRuleNameVisitor()
visitor.visit(ret_value.value.value)
debugger.debug_var("names", visitor.names, hint="from BNF")
return set(visitor.names)
#
@@ -152,6 +155,7 @@ class DefConceptEvaluator(OneReturnValueEvaluator):
if len(concept_name) > 1:
visitor = UnreferencedVariablesVisitor(context)
names = visitor.get_names(python_node.ast_)
debugger.debug_var("names", names, hint="from python node")
return set(filter(lambda x: x in concept_name and context.sheerka.not_is_variable(x), names))
else:
return set()
@@ -168,6 +172,7 @@ class DefConceptEvaluator(OneReturnValueEvaluator):
for identifier in [i for i in concept_name if str(i).isalnum()]:
if identifier in tokens:
variables.add(identifier)
debugger.debug_var("names", variables, hint="from concept")
return variables
return set()
+9 -3
View File
@@ -92,6 +92,9 @@ class PythonEvaluator(OneReturnValueEvaluator):
debugger = context.get_debugger(PythonEvaluator.NAME, "eval")
debugger.debug_entering(node=node)
exception_debugger = context.get_debugger("Exceptions", PythonEvaluator.NAME + ".eval")
get_trace_back = context.debug_enabled or exception_debugger.is_enabled()
context.log(f"Evaluating python node {node}.", self.name)
# If we evaluate a Concept metadata which is NOT the body ex (pre, post, where...)
@@ -136,9 +139,12 @@ class PythonEvaluator(OneReturnValueEvaluator):
except Exception as ex:
if concepts_entries is None:
concepts_entries = self.get_concepts_entries_from_globals(my_globals)
errors.append(PythonEvalError(ex,
traceback.format_exc() if context.debug_enabled else None,
self.get_concepts_values_from_globals(globals_, concepts_entries)))
eval_error = PythonEvalError(ex,
traceback.format_exc() if get_trace_back else None,
self.get_concepts_values_from_globals(globals_, concepts_entries))
errors.append(eval_error)
exception_debugger.debug_var("exception", eval_error.error, is_error=True)
exception_debugger.debug_var("trace", eval_error.traceback, is_error=True)
if evaluated == NotInit:
if len(errors) == 1: