fixed #18 : I can evaluate concept

This commit is contained in:
2023-06-01 22:08:34 +02:00
parent 09a0246420
commit 62391f786e
25 changed files with 1503 additions and 314 deletions
+9 -10
View File
@@ -1,4 +1,5 @@
from dataclasses import dataclass
from dataclasses import dataclass, field
from typing import Any
from common.global_symbols import NotFound, NotInit
@@ -60,13 +61,13 @@ class ConceptRuntimeInfo:
They are related to the instance of the concept
"""
is_evaluated: bool = False # True is the concept is evaluated by sheerka.eval_concept()
need_validation: bool = True # True if the properties of the concept need to be validated
recognized_by: str = None # RECOGNIZED_BY_ID, RECOGNIZED_BY_NAME, RECOGNIZED_BY_KEY (from Sheerka.py)
error: Any = None # when failed to evaluate the concept
info: dict = field(default_factory=dict) # give context of why 'where' or 'pre' constraints fail
def copy(self):
return ConceptRuntimeInfo(self.is_evaluated,
self.need_validation,
self.recognized_by)
self.error,
self.info)
class Concept:
@@ -79,21 +80,19 @@ class Concept:
def __init__(self, metadata: ConceptMetadata):
self._metadata: ConceptMetadata = metadata
self._compiled = {} # cached ast for the where, pre, post and body parts and variables
self._compiled_context_hints = {} # context hints to use when evaluating compiled
self._bnf = None # compiled bnf expression
self._runtime_info = ConceptRuntimeInfo() # runtime settings for the concept
self._all_attrs = None
def __repr__(self):
text = f"({self._metadata.id}){self._metadata.name}"
text = f"(Concept {self._metadata.name}#{self._metadata.id}"
if self._metadata.pre:
text += f", #pre={self._metadata.pre}"
for attr in [attr for attr in self.all_attrs() if not attr.startswith("#")]:
text += f", {attr}={self.get_value(attr)}"
return text
return text + ")"
def __eq__(self, other):
# I don't want this test to be part of the recursion
@@ -116,7 +115,7 @@ class Concept:
return True
# 1. in order for two concepts to be equal, they must have the same definition
# 2. They must have the same properties and variables
# 2. They must have the same variables
if left.get_definition_digest() != right.get_definition_digest():
return False