Refactored Caching, Refactored BnfNodeParser, Introduced Sphinx
This commit is contained in:
@@ -79,18 +79,18 @@ class AddConceptEvaluator(OneReturnValueEvaluator):
|
||||
continue
|
||||
|
||||
# try to find what can be a property
|
||||
for p in self.get_props(sheerka, part_ret_val, name_to_use):
|
||||
for p in self.get_variables(sheerka, part_ret_val, name_to_use):
|
||||
props_found.add(p)
|
||||
|
||||
# add props by order of appearance when possible
|
||||
# add variables by order of appearance when possible
|
||||
for token in def_concept_node.name.tokens:
|
||||
if token.value in props_found:
|
||||
concept.def_prop(token.value, None)
|
||||
concept.def_var(token.value, None)
|
||||
|
||||
# add the remaining properties
|
||||
for p in props_found:
|
||||
if p not in concept.props:
|
||||
concept.def_prop(p, None)
|
||||
if p not in concept.values:
|
||||
concept.def_var(p, None)
|
||||
|
||||
# initialize the key
|
||||
key_source = def_concept_node.definition.tokens if \
|
||||
@@ -105,7 +105,7 @@ class AddConceptEvaluator(OneReturnValueEvaluator):
|
||||
|
||||
ret = sheerka.create_new_concept(context, concept)
|
||||
if not ret.status:
|
||||
error_cause = sheerka.value(ret.body)
|
||||
error_cause = sheerka.objvalue(ret.body)
|
||||
context.log(f"Failed to add concept '{concept.name}'. Reason: {error_cause}", self.name)
|
||||
return sheerka.ret(self.name, ret.status, ret.value, parents=[return_value])
|
||||
|
||||
@@ -115,7 +115,7 @@ class AddConceptEvaluator(OneReturnValueEvaluator):
|
||||
return [part.value for part in core.utils.strip_tokens(source.tokens, True)]
|
||||
|
||||
@staticmethod
|
||||
def get_props(sheerka, ret_value, concept_name):
|
||||
def get_variables(sheerka, ret_value, concept_name):
|
||||
"""
|
||||
Try to find out the variables
|
||||
This function can only be a draft, as there may be tons of different situations
|
||||
@@ -146,7 +146,7 @@ class AddConceptEvaluator(OneReturnValueEvaluator):
|
||||
# case of concept
|
||||
#
|
||||
if isinstance(ret_value.value, ParserResultConcept) and isinstance(ret_value.value.value, Concept):
|
||||
return list(ret_value.value.value.props.keys())
|
||||
return list(ret_value.value.value.values.keys())
|
||||
|
||||
#
|
||||
# case of BNF
|
||||
|
||||
@@ -64,7 +64,7 @@ class AddConceptInSetEvaluator(OneReturnValueEvaluator):
|
||||
|
||||
res = sheerka.set_isa(context, concept, concept_set)
|
||||
if not res.status:
|
||||
context.log(f"Failed. Reason: {sheerka.value(res.body)}.", self.name)
|
||||
context.log(f"Failed. Reason: {sheerka.objvalue(res.body)}.", self.name)
|
||||
else:
|
||||
context.log(f"Concept added.", self.name)
|
||||
|
||||
|
||||
@@ -41,8 +41,8 @@ class ConceptEvaluator(OneReturnValueEvaluator):
|
||||
# Why ?
|
||||
# If we evaluate Concept("foo", body="a").set_prop("a", "'property_a'")
|
||||
# The body should be 'property_a', and not a concept called 'a'
|
||||
if context.obj and concept.name in context.obj.props:
|
||||
value = context.obj.props[concept.name].value
|
||||
if context.obj and concept.name in context.obj.values:
|
||||
value = context.obj.get_value(concept.name)
|
||||
context.log(f"{concept.name} is a property. Returning value '{value}'.", self.name)
|
||||
|
||||
return sheerka.ret(self.name, True, value, parents=[return_value])
|
||||
|
||||
@@ -31,7 +31,7 @@ class PrepareEvalEvaluator(OneReturnValueEvaluator):
|
||||
|
||||
new_text_to_parse = sheerka.ret(
|
||||
self.name,
|
||||
True, sheerka.new(BuiltinConcepts.USER_INPUT, body=self.text[5:], user_name=context.event.user))
|
||||
True, sheerka.new(BuiltinConcepts.USER_INPUT, body=self.text[5:], user_name=context.event.user_id))
|
||||
|
||||
context.global_hints.add(BuiltinConcepts.EVAL_BODY_REQUESTED)
|
||||
context.global_hints.add(BuiltinConcepts.CONCEPT_VALUE_REQUESTED)
|
||||
|
||||
@@ -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