Implemented FunctionParser
This commit is contained in:
@@ -31,9 +31,9 @@ def get_input_nodes_from(my_concepts_map, full_expr, *args):
|
||||
|
||||
if isinstance(n, SCWC):
|
||||
n.first = _get_real_node(n.first)
|
||||
n.last = _get_real_node(n.first)
|
||||
n.last = _get_real_node(n.last)
|
||||
n.content = tuple(_get_real_node(nn) for nn in n.content)
|
||||
return SourceCodeWithConceptNode(n.first, n.last, list(n.content))
|
||||
return SourceCodeWithConceptNode(n.first, n.last, list(n.content)).pseudo_fix_source()
|
||||
|
||||
if isinstance(n, (UnrecognizedTokensNode, ConceptNode, SourceCodeNode, SourceCodeWithConceptNode)):
|
||||
return n
|
||||
@@ -254,6 +254,7 @@ class TestUnrecognizedNodeParser(TestUsingMemoryBasedSheerka):
|
||||
|
||||
assert res.status
|
||||
assert sheerka.isinstance(parser_result, BuiltinConcepts.PARSER_RESULT)
|
||||
assert parser_result.source == expression
|
||||
assert len(actual_nodes) == 1
|
||||
assert actual_nodes[0] == scnode(0, 4, expression)
|
||||
|
||||
@@ -270,6 +271,7 @@ class TestUnrecognizedNodeParser(TestUsingMemoryBasedSheerka):
|
||||
|
||||
assert not res.status
|
||||
assert sheerka.isinstance(parser_result, BuiltinConcepts.PARSER_RESULT)
|
||||
assert parser_result.source == expression
|
||||
assert len(actual_nodes) == 1
|
||||
assert actual_nodes[0] == nodes[0]
|
||||
|
||||
@@ -287,6 +289,7 @@ class TestUnrecognizedNodeParser(TestUsingMemoryBasedSheerka):
|
||||
|
||||
assert res.status
|
||||
assert sheerka.isinstance(parser_result, BuiltinConcepts.PARSER_RESULT)
|
||||
assert parser_result.source == expression
|
||||
assert len(actual_nodes) == 1
|
||||
expected_array = compute_expected_array(
|
||||
concepts_map,
|
||||
@@ -306,6 +309,7 @@ class TestUnrecognizedNodeParser(TestUsingMemoryBasedSheerka):
|
||||
|
||||
assert res.status
|
||||
assert sheerka.isinstance(parser_result, BuiltinConcepts.PARSER_RESULT)
|
||||
assert parser_result.source == expression
|
||||
assert len(actual_nodes) == 1
|
||||
|
||||
expected_array = compute_expected_array(
|
||||
@@ -328,8 +332,9 @@ class TestUnrecognizedNodeParser(TestUsingMemoryBasedSheerka):
|
||||
parser_result = res.body
|
||||
actual_nodes = res.body.body
|
||||
|
||||
assert not res.status # status is False to let PythonWithConceptParser validate the code
|
||||
assert not res.status # status is False to let PythonWithConceptParser validate the code
|
||||
assert sheerka.isinstance(parser_result, BuiltinConcepts.PARSER_RESULT)
|
||||
assert parser_result.source == expression
|
||||
assert len(actual_nodes) == 1
|
||||
assert actual_nodes[0].nodes[0].concept.metadata.is_evaluated # 'a plus b' is recognized as concept definition
|
||||
|
||||
@@ -348,9 +353,37 @@ class TestUnrecognizedNodeParser(TestUsingMemoryBasedSheerka):
|
||||
|
||||
assert not res.status # status is False to let PythonWithConceptParser validate the code
|
||||
assert sheerka.isinstance(parser_result, BuiltinConcepts.PARSER_RESULT)
|
||||
assert parser_result.source == expression
|
||||
assert len(actual_nodes) == 1
|
||||
assert not actual_nodes[0].nodes[0].concept.metadata.is_evaluated # 'a plus b' need to be evaluated
|
||||
|
||||
def test_i_can_parse_unrecognized_sya_concept_that_references_source_code(self):
|
||||
sheerka, context, parser = self.init_parser()
|
||||
|
||||
expression = "hello get_user_name(twenty one)"
|
||||
tmp_node = CNC("hello_sya",
|
||||
source="hello get_user_name(twenty one)",
|
||||
a=SCWC("get_user_name(", ")", CNC("twenties", source="twenty one", unit="one")))
|
||||
nodes = get_input_nodes_from(concepts_map, expression, tmp_node)
|
||||
parser_input = ParserResultConcept("parsers.xxx", source=expression, value=nodes)
|
||||
|
||||
res = parser.parse(context, parser_input)
|
||||
parser_result = res.body
|
||||
actual_nodes = res.body.body
|
||||
|
||||
assert res.status
|
||||
assert sheerka.isinstance(parser_result, BuiltinConcepts.PARSER_RESULT)
|
||||
assert parser_result.source == expression
|
||||
assert len(actual_nodes) == 1
|
||||
|
||||
expected_array = compute_expected_array(
|
||||
concepts_map,
|
||||
expression, [CN("hello_sya", source="hello get_user_name(twenty one)")],
|
||||
exclude_body=True)
|
||||
assert actual_nodes == expected_array
|
||||
assert isinstance(actual_nodes[0].concept.compiled["a"], list)
|
||||
assert sheerka.isinstance(actual_nodes[0].concept.compiled["a"][0], BuiltinConcepts.RETURN_VALUE)
|
||||
|
||||
def test_i_can_parse_sequences(self):
|
||||
sheerka, context, parser = self.init_parser()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user