I can now use keyword in concept definition and parsing

This commit is contained in:
2020-05-22 15:46:04 +02:00
parent 37d3d16e21
commit 3ce6ce2a76
14 changed files with 127 additions and 45 deletions
+6 -15
View File
@@ -131,15 +131,15 @@ class SyaConceptParserHelper:
# True if the next token is the one that is expected
# Or if the next token is a whitespace and the expected one is the one after
# (whitespace are sometimes not mandatory)
return token.str_value == self.expected[0].str_value or \
self.expected[0].type == TokenKind.WHITESPACE and token.str_value == self.expected[1].str_value
return token.strip_quote == self.expected[0].strip_quote or \
self.expected[0].type == TokenKind.WHITESPACE and token.strip_quote == self.expected[1].strip_quote
def is_expected(self, token):
if self.is_matched() or token.type == TokenKind.WHITESPACE:
return False
for expected in self.expected:
if expected.type != TokenKind.VAR_DEF and expected.str_value == token.str_value:
if expected.type != TokenKind.VAR_DEF and expected.strip_quote == token.strip_quote:
return True
return False
@@ -154,7 +154,7 @@ class SyaConceptParserHelper:
:return:
"""
# No check, as it is used only after is_expected() or is_next()
while self.expected[0].str_value != until_token.str_value:
while self.expected[0].strip_quote != until_token.strip_quote:
del self.expected[0]
del self.expected[0]
@@ -193,15 +193,6 @@ class SyaConceptParserHelper:
self.concept = self.concept.concept
return self
# @staticmethod
# def _get_token_value(token):
# if token.type == TokenKind.STRING:
# return token.value[1:-1]
# elif token.type == TokenKind.KEYWORD:
# return token.value.value
# else:
# return token.value
def clone(self):
clone = SyaConceptParserHelper(self.concept, self.start, self.end)
clone.expected = self.expected[:]
@@ -296,7 +287,7 @@ class InFixToPostFix:
if item.expected[0].type == TokenKind.VAR_DEF:
item.error = "Not enough suffix parameters"
else:
item.error = f"token '{item.expected[0].str_value}' not found"
item.error = f"token '{item.expected[0].strip_quote}' not found"
if isinstance(item, SyaConceptParserHelper) and item.potential_pos != -1:
self.out.insert(item.potential_pos, item)
@@ -431,7 +422,7 @@ class InFixToPostFix:
while len(current_concept.expected) > 0 and current_concept.expected[0].type == TokenKind.VAR_DEF:
# eat everything that was expected
if len(self.parameters_list) == 0:
current_concept.error = f"Failed to match parameter '{current_concept.expected[0].str_value}'"
current_concept.error = f"Failed to match parameter '{current_concept.expected[0].strip_quote}'"
return
del self.parameters_list[0]
del current_concept.expected[0]