Implemented FunctionParser
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from core.concept import CC, Concept, ConceptParts, DoNotResolve
|
||||
from core.concept import CC, Concept, ConceptParts, DoNotResolve, CIO
|
||||
from core.tokenizer import Tokenizer, TokenKind, Token
|
||||
from parsers.BaseNodeParser import scnode, utnode, cnode, SCWC, CNC, short_cnode, SourceCodeWithConceptNode, CN, UTN, \
|
||||
SCN
|
||||
@@ -13,7 +13,7 @@ def _index(tokens, expr, index):
|
||||
:param index:
|
||||
:return:
|
||||
"""
|
||||
expected = [token.value for token in Tokenizer(expr) if token.type != TokenKind.EOF]
|
||||
expected = [token.str_value for token in Tokenizer(expr) if token.type != TokenKind.EOF]
|
||||
for i in range(0, len(tokens) - len(expected) + 1):
|
||||
for j in range(len(expected)):
|
||||
if tokens[i + j] != expected[j]:
|
||||
@@ -74,6 +74,14 @@ def get_node(
|
||||
if isinstance(sub_expr, (scnode, utnode, DoNotResolve)):
|
||||
return sub_expr
|
||||
|
||||
if isinstance(sub_expr, CIO):
|
||||
sub_expr.set_concept(concepts_map[sub_expr.concept_name])
|
||||
if sub_expr.source:
|
||||
node = get_node(concepts_map, expression_as_tokens, sub_expr.source, sya=sya)
|
||||
sub_expr.start = node.start
|
||||
sub_expr.end = node.end
|
||||
return sub_expr
|
||||
|
||||
if isinstance(sub_expr, cnode):
|
||||
# for cnode, map the concept key to the one from concepts_maps if needed
|
||||
if sub_expr.concept_key.startswith("#"):
|
||||
@@ -192,7 +200,7 @@ def compute_expected_array(concepts_map, expression, expected, sya=False, init_e
|
||||
:param exclude_body: do not include ConceptParts.BODY in comparison
|
||||
:return:
|
||||
"""
|
||||
expression_as_tokens = [token.value for token in Tokenizer(expression) if token.type != TokenKind.EOF]
|
||||
expression_as_tokens = [token.str_value for token in Tokenizer(expression) if token.type != TokenKind.EOF]
|
||||
return [get_node(
|
||||
concepts_map,
|
||||
expression_as_tokens,
|
||||
|
||||
Reference in New Issue
Block a user