Fixed #55 : DefConceptParser: failed to recognize concept

Fixed #62 : DefConceptParser: parsing error
Fixed #64 : DefConceptParser: Failed to parse when too many concept keyword
Fixed #65 : DefConceptParser : Add auto_eval keyword
Fixed #66 : DefConceptParser : Add def_var keyword
Fixed #67 : Add get_errors()
This commit is contained in:
2021-04-13 15:15:17 +02:00
parent 81e67147e9
commit bef5f3208c
17 changed files with 838 additions and 235 deletions
+75 -1
View File
@@ -12,7 +12,7 @@ from parsers.BaseParser import UnexpectedEofParsingError
from parsers.BnfDefinitionParser import BnfDefinitionParser
from parsers.BnfNodeParser import OrderedChoice, ConceptExpression, StrMatch, Sequence, RegExMatch, OneOrMore, \
VariableExpression
from parsers.DefConceptParser import DefConceptParser, NameNode, SyntaxErrorNode
from parsers.DefConceptParser import DefConceptParser, NameNode, SyntaxErrorNode, CannotHandleParsingError
from parsers.DefConceptParser import UnexpectedTokenParsingError, DefConceptNode
from parsers.FunctionParser import FunctionParser
from parsers.PythonParser import PythonParser, PythonNode
@@ -636,3 +636,77 @@ from give me the date !
assert res.value.source == text
assert isinstance(res.value, ParserResultConcept)
assert node == expected
def test_i_can_parse_when_multiple_keyword_and_no_ambiguity(self):
sheerka, context, parser, *concepts = self.init_parser()
res = parser.parse(context, ParserInput("def concept x is a concept"))
assert res.status
@pytest.mark.parametrize("text, expected", [
("def concept foo auto_eval True", True),
("def concept foo auto_eval true", True),
("def concept foo auto_eval False", False),
("def concept foo auto_eval false", False),
])
def test_i_can_parse_auto_eval(self, text, expected):
sheerka, context, parser, *concepts = self.init_parser()
res = parser.parse(context, ParserInput(text))
def_concept_node = res.value.value
assert res.status
assert res.who == parser.name
assert res.value.source == text
assert isinstance(res.value, ParserResultConcept)
assert def_concept_node.auto_eval == expected
@pytest.mark.parametrize("text", [
"def concept foo auto_eval",
"def concept foo auto_eval as 1"
])
def test_i_cannot_parse_when_missing_auto_eval_value(self, text):
sheerka, context, parser, *concepts = self.init_parser()
res = parser.parse(context, ParserInput(text))
assert not res.status
assert sheerka.isinstance(res.value, BuiltinConcepts.ERROR)
assert sheerka.has_error(res, __type="SyntaxErrorNode", message="Empty 'auto_eval' declaration.")
def test_i_cannot_parse_when_wrong_auto_eval_value(self):
sheerka, context, parser, *concepts = self.init_parser()
text = "def concept foo auto_eval wrong_value"
res = parser.parse(context, ParserInput(text))
assert not res.status
assert sheerka.isinstance(res.value, BuiltinConcepts.ERROR)
assert isinstance(res.value.body[0], CannotHandleParsingError)
@pytest.mark.parametrize("text, expected", [
("def concept foo def_var var", ["var"]),
("def concept foo def_var var1 def_var var2", ["var1", "var2"]),
("def concept foo def_var var1 def_var long var name def_var var2", ["var1", "long var name", "var2"]),
])
def test_i_can_parse_variable_definition(self, text, expected):
sheerka, context, parser, *concepts = self.init_parser()
res = parser.parse(context, ParserInput(text))
def_concept_node = res.value.value
assert res.status
assert res.who == parser.name
assert res.value.source == text
assert isinstance(res.value, ParserResultConcept)
assert def_concept_node.variables == expected
@pytest.mark.parametrize("text", [
"def concept foo def_var",
"def concept foo def_var as 1"
])
def test_i_cannot_parse_variable_definition_when_missing_value(self, text):
sheerka, context, parser, *concepts = self.init_parser()
res = parser.parse(context, ParserInput(text))
assert not res.status
assert sheerka.isinstance(res.value, BuiltinConcepts.ERROR)
assert sheerka.has_error(res, __type="SyntaxErrorNode", message="Empty 'def_var' declaration.")