Fixed some bugs

This commit is contained in:
2020-08-27 18:54:28 +02:00
parent 351c16f946
commit 37cd3ed757
27 changed files with 685 additions and 189 deletions
+26 -7
View File
@@ -125,6 +125,11 @@ class SyaConceptParserHelper:
return len(self.concept.concept.metadata.variables) == 0 and len(self.expected) == 0
def is_next(self, token):
"""
To match long named concepts
:param token:
:return:
"""
if self.is_matched() or len(self.expected) == 0:
return False
@@ -294,8 +299,9 @@ class InFixToPostFix:
else:
self.out.append(item)
# put the item to the list of awaiting parameters
self.parameters_list.append(item)
# put the item to the list of awaiting parameters only if it's not the end of function marker
if item != ")":
self.parameters_list.append(item)
if len(self._concepts()) > 0:
# try to predict the final position of the current concept
@@ -339,9 +345,18 @@ class InFixToPostFix:
self.unrecognized_tokens.add_token(token, parser_helper.start + i)
def get_errors(self):
def has_error(item):
if isinstance(item, SyaConceptParserHelper) and item.error:
return True
if isinstance(item, SourceCodeWithConceptNode):
for n in item.nodes:
if hasattr(n, "error") and n.error:
return True
return False
res = []
res.extend(self.errors)
res.extend([item for item in self.out if isinstance(item, SyaConceptParserHelper) and item.error])
res.extend([item for item in self.out if has_error(item)])
return res
def lock(self):
@@ -367,8 +382,8 @@ class InFixToPostFix:
if len(self.parameters_list) > parser_helper.expected_parameters_before_first_token:
# There are more parameters than needed by the new concept
# The others are either
# - parameters for the previous concept (if any)
# These others parameters are either
# - parameters for the previous suffixed concept (if any)
# - concepts on their own
# - syntax error
# In all the cases, the only thing that matter is to pop what is expected by the new concept
@@ -461,7 +476,7 @@ class InFixToPostFix:
"""
The unrecognized ends with an lpar '('
It means that its a function like foo(something)
The problem is that we need to know if there are other conceps before the function
The problem is that we need to know if there are other concepts before the function
ex : suffix one function(x)
suffix and one are not / may not be part of the name of the function
@@ -585,7 +600,7 @@ class InFixToPostFix:
del (current_concept.expected[0])
else:
# error
# We are not parsing the concept we tought we were parsing.
# We are not parsing the concept we thought we were parsing.
# Transform the eaten tokens into unrecognized
# and discard the current SyaConceptParserHelper
# TODO: manage the pending LPAR, RPAR ?
@@ -697,6 +712,10 @@ class InFixToPostFix:
for to_out in parsing_res.to_out:
instance._put_to_out(to_out)
# make sure to pop the current concept
if self._stack_isinstance(SyaConceptParserHelper):
self.pop_stack_to_out()
instance._put_to_out(")") # mark where the function should end
instance.stack.append(parsing_res.function)
instance.unrecognized_tokens = UnrecognizedTokensNode(-1, -1, []) # reset unrecognized