Added basic implementation for Python code evaluation

This commit is contained in:
2019-11-07 17:18:07 +01:00
parent b818c992ec
commit 448ebc696a
18 changed files with 501 additions and 156 deletions
+18 -4
View File
@@ -31,15 +31,29 @@ class UnexpectedTokenErrorNode(DefaultParserErrorNode):
expected_tokens: list
def __post_init__(self):
log.debug("UnexpectedToken : " + self.message)
log.debug("-> UnexpectedTokenErrorNode: " + self.message)
@dataclass()
class SyntaxErrorNode(DefaultParserErrorNode):
"""
The input is recognized, but there is a syntax error
"""
message: str
def __post_init__(self):
log.debug("SyntaxError : " + self.message)
log.debug("-> SyntaxErrorNode: " + self.message)
@dataclass()
class CannotHandleErrorNode(DefaultParserErrorNode):
"""
The input is not recognized
"""
text: str
def __post_init__(self):
log.debug("-> CannotHandleErrorNode: " + self.text)
@dataclass()
@@ -134,7 +148,7 @@ class BinaryNode(DefaultParserNode):
class DefaultParser(BaseParser):
def __init__(self, text, sub_parser):
BaseParser.__init__(self, "Default", text)
BaseParser.__init__(self, "DefaultParser", text)
self.sub_parser = sub_parser
self.lexer = Tokenizer(text)
self.lexer_iter = iter(Tokenizer(text))
@@ -237,7 +251,7 @@ class DefaultParser(BaseParser):
self.next_token()
return self.parse_def_concept()
else:
return self.parse_expression()
return self.add_error(CannotHandleErrorNode([], self.text))
def parse_def_concept(self):
"""
+4
View File
@@ -12,6 +12,8 @@ class PythonErrorNode(ErrorNode):
source: str
exception: Exception
def __post_init__(self):
log.debug("-> PythonErrorNode: " + str(self.exception))
@dataclass()
class PythonNode(Node):
@@ -41,6 +43,8 @@ class PythonParser(BaseParser):
error_node = PythonErrorNode(self.text, error)
self.error_sink.append(error_node)
return error_node
log.debug("Recognized python code.")
return PythonNode(self.text, tree)
def try_parse_expression(self):