Added RET keyword
This commit is contained in:
@@ -15,7 +15,7 @@ from parsers.PythonParser import PythonParser, PythonNode
|
||||
from tests.TestUsingMemoryBasedSheerka import TestUsingMemoryBasedSheerka
|
||||
|
||||
|
||||
def get_def_concept(name, where=None, pre=None, post=None, body=None, definition=None, bnf_def=None):
|
||||
def get_def_concept(name, where=None, pre=None, post=None, body=None, definition=None, bnf_def=None, ret=None):
|
||||
def_concept = DefConceptNode([], name=NameNode(list(Tokenizer(name))))
|
||||
|
||||
if body:
|
||||
@@ -26,6 +26,8 @@ def get_def_concept(name, where=None, pre=None, post=None, body=None, definition
|
||||
def_concept.pre = get_concept_part(pre)
|
||||
if post:
|
||||
def_concept.post = get_concept_part(post)
|
||||
if ret:
|
||||
def_concept.ret = get_concept_part(ret)
|
||||
if bnf_def:
|
||||
def_concept.definition = ReturnValueConcept(
|
||||
"parsers.Bnf",
|
||||
@@ -75,6 +77,9 @@ def get_concept_part(part):
|
||||
|
||||
@dataclass
|
||||
class PN:
|
||||
"""
|
||||
Python Node
|
||||
"""
|
||||
source: str # parser result source
|
||||
mode: str # compilation mode
|
||||
|
||||
@@ -110,21 +115,23 @@ class TestDefaultParser(TestUsingMemoryBasedSheerka):
|
||||
assert node == expected
|
||||
|
||||
def test_i_can_parse_complex_def_concept_statement(self):
|
||||
text = """def concept a plus b
|
||||
text = """def concept a mult b
|
||||
where a,b
|
||||
pre isinstance(a, int) and isinstance(b, float)
|
||||
post isinstance(res, int)
|
||||
as res = a + b
|
||||
"""
|
||||
pre isinstance(b, int)
|
||||
post isinstance(res, a)
|
||||
as res = a * b
|
||||
ret a if isinstance(a, Concept) else self
|
||||
"""
|
||||
sheerka, context, parser = self.init_parser()
|
||||
res = parser.parse(context, ParserInput(text))
|
||||
return_value = res.value
|
||||
expected_concept = get_def_concept(
|
||||
name="a plus b",
|
||||
name="a mult b",
|
||||
where="a,b\n",
|
||||
pre="isinstance(a, int) and isinstance(b, float)\n",
|
||||
post="isinstance(res, int)\n",
|
||||
body=PN("res = a + b\n ", "exec")
|
||||
pre="isinstance(b, int)\n",
|
||||
post="isinstance(res, a)\n",
|
||||
body=PN("res = a * b\n", "exec"),
|
||||
ret="a if isinstance(a, Concept) else self\n"
|
||||
)
|
||||
|
||||
assert res.status
|
||||
|
||||
Reference in New Issue
Block a user