Fixed #49 : ExpressionParser: Implement ExpressionParser
This commit is contained in:
@@ -8,13 +8,14 @@ from core.concept import Concept, ConceptParts, DoNotResolve, AllConceptParts
|
||||
from core.rule import Rule
|
||||
from core.tokenizer import Tokenizer, TokenKind, Token
|
||||
from core.utils import get_text_from_tokens, tokens_index, str_concept
|
||||
from parsers.BaseExpressionParser import NameExprNode, AndNode, OrNode, NotNode, VariableNode, ComparisonNode, \
|
||||
ComparisonType, \
|
||||
FunctionParameter
|
||||
from parsers.BaseNodeParser import UnrecognizedTokensNode, SourceCodeNode, RuleNode, ConceptNode, \
|
||||
SourceCodeWithConceptNode
|
||||
from parsers.FunctionParser import FunctionNode
|
||||
from parsers.PythonParser import PythonNode
|
||||
from parsers.SyaNodeParser import SyaConceptParserHelper
|
||||
from parsers.BaseExpressionParser import NameExprNode, AndNode, OrNode, NotNode, VariableNode, ComparisonNode, ComparisonType, \
|
||||
FunctionParameter
|
||||
from sheerkarete.common import V
|
||||
from sheerkarete.conditions import Condition, AndConditions
|
||||
|
||||
@@ -1304,17 +1305,22 @@ def get_rete_conditions(*conditions_as_string):
|
||||
"identifier|__name__|'True'" -> Condition(identifier, '__name__', 'True') # the string 'True'
|
||||
"identifier|__name__|True" -> Condition(identifier, '__name__', True) # the bool True
|
||||
"""
|
||||
|
||||
def get_value(obj):
|
||||
if obj.startswith("#"):
|
||||
return V(obj[1:])
|
||||
if obj.startswith("'"):
|
||||
return obj[1:-1]
|
||||
if obj in ("True", "False"):
|
||||
return obj == "True"
|
||||
return int(obj)
|
||||
|
||||
res = []
|
||||
for as_string in conditions_as_string:
|
||||
identifier, attribute, value = as_string.split("|")
|
||||
if identifier.startswith("#"):
|
||||
identifier = V(identifier[1:])
|
||||
if value.startswith("'"):
|
||||
value = value[1:-1]
|
||||
elif value in ("True", "False"):
|
||||
value = (value == "True")
|
||||
else:
|
||||
value = int(value)
|
||||
parts = as_string.split("|")
|
||||
identifier = get_value(parts[0])
|
||||
attribute = parts[1]
|
||||
value = get_value(parts[2])
|
||||
|
||||
res.append(Condition(identifier, attribute, value))
|
||||
return AndConditions(res)
|
||||
|
||||
Reference in New Issue
Block a user