Refactored Caching, Refactored BnfNodeParser, Introduced Sphinx
This commit is contained in:
@@ -1,15 +1,14 @@
|
||||
import ast
|
||||
import copy
|
||||
import traceback
|
||||
from enum import Enum
|
||||
|
||||
import core.ast.nodes
|
||||
import core.utils
|
||||
from core.ast.visitors import UnreferencedNamesVisitor
|
||||
from core.builtin_concepts import BuiltinConcepts, ParserResultConcept
|
||||
from core.concept import ConceptParts, Concept
|
||||
from evaluators.BaseEvaluator import OneReturnValueEvaluator
|
||||
from parsers.PythonParser import PythonNode
|
||||
import ast
|
||||
import core.ast.nodes
|
||||
import core.utils
|
||||
|
||||
|
||||
class PythonEvaluator(OneReturnValueEvaluator):
|
||||
@@ -36,7 +35,7 @@ class PythonEvaluator(OneReturnValueEvaluator):
|
||||
|
||||
# Do not evaluate if the ast refers to a concept (leave it to ConceptEvaluator)
|
||||
if isinstance(node.ast_, ast.Expression) and isinstance(node.ast_.body, ast.Name):
|
||||
c = context.sheerka.get(node.ast_.body.id)
|
||||
c = context.sheerka.get_by_key(node.ast_.body.id)
|
||||
if not context.sheerka.isinstance(c, BuiltinConcepts.UNKNOWN_CONCEPT):
|
||||
context.log("It's a simple concept. Not for me.", self.name)
|
||||
not_for_me = context.sheerka.new(BuiltinConcepts.NOT_FOR_ME, body=node)
|
||||
@@ -69,7 +68,6 @@ class PythonEvaluator(OneReturnValueEvaluator):
|
||||
"sheerka": context.sheerka,
|
||||
"desc": context.sheerka.dump_handler.dump_desc,
|
||||
"concepts": context.sheerka.dump_handler.dump_concepts,
|
||||
"definitions": context.sheerka.dump_handler.dump_definitions,
|
||||
"history": context.sheerka.dump_handler.dump_history,
|
||||
"state": context.sheerka.dump_handler.dump_state,
|
||||
"Concept": core.concept.Concept
|
||||
@@ -77,11 +75,12 @@ class PythonEvaluator(OneReturnValueEvaluator):
|
||||
if context.obj:
|
||||
context.log(f"Concept '{context.obj}' is in context. Adding it and its properties to locals.", self.name)
|
||||
|
||||
for prop_name, prop_value in context.obj.props.items():
|
||||
if isinstance(prop_value.value, Concept):
|
||||
my_locals[prop_name] = context.sheerka.value(prop_value.value)
|
||||
for prop_name in context.obj.variables():
|
||||
prop_value = context.obj.get_value(prop_name)
|
||||
if isinstance(prop_value, Concept):
|
||||
my_locals[prop_name] = context.sheerka.objvalue(prop_value)
|
||||
else:
|
||||
my_locals[prop_name] = prop_value.value
|
||||
my_locals[prop_name] = prop_value
|
||||
|
||||
my_locals["self"] = context.obj.body
|
||||
|
||||
@@ -118,7 +117,7 @@ class PythonEvaluator(OneReturnValueEvaluator):
|
||||
sub_context.add_values(return_values=evaluated)
|
||||
|
||||
if evaluated.key == concept.key:
|
||||
my_locals[name] = evaluated if return_concept else context.sheerka.value(evaluated)
|
||||
my_locals[name] = evaluated if return_concept else context.sheerka.objvalue(evaluated)
|
||||
|
||||
if self.locals: # when exta values are given. Add them
|
||||
my_locals.update(self.locals)
|
||||
@@ -142,7 +141,6 @@ class PythonEvaluator(OneReturnValueEvaluator):
|
||||
else:
|
||||
return to_resolve, None, False
|
||||
|
||||
|
||||
@staticmethod
|
||||
def expr_to_expression(expr):
|
||||
expr.lineno = 0
|
||||
|
||||
Reference in New Issue
Block a user