Fixed SyaNodeParser false positive recognition issue
This commit is contained in:
@@ -53,9 +53,6 @@ class UnrecognizedTokensNode(LexerNode):
|
||||
self.is_frozen = False
|
||||
self.parenthesis_count = 0
|
||||
|
||||
def has_open_paren(self):
|
||||
return self.parenthesis_count > 0
|
||||
|
||||
def add_token(self, token, pos):
|
||||
if self.is_frozen:
|
||||
raise Exception("The node is frozen")
|
||||
@@ -78,6 +75,21 @@ class UnrecognizedTokensNode(LexerNode):
|
||||
|
||||
return self
|
||||
|
||||
def pop(self, token_kind):
|
||||
if self.is_frozen:
|
||||
raise Exception("The node is frozen")
|
||||
|
||||
if len(self.tokens) > 0 and self.tokens[-1].type == token_kind:
|
||||
self.tokens.pop()
|
||||
if len(self.tokens) == 0:
|
||||
self.reset()
|
||||
else:
|
||||
self.end -= 1
|
||||
|
||||
|
||||
def has_open_paren(self):
|
||||
return self.parenthesis_count > 0
|
||||
|
||||
def not_whitespace(self):
|
||||
return not self.is_whitespace()
|
||||
|
||||
@@ -90,6 +102,11 @@ class UnrecognizedTokensNode(LexerNode):
|
||||
def is_empty(self):
|
||||
return len(self.tokens) == 0
|
||||
|
||||
def last_token_type(self):
|
||||
if len(self.tokens) == 0:
|
||||
return None
|
||||
return self.tokens[-1].type
|
||||
|
||||
def __eq__(self, other):
|
||||
if isinstance(other, utnode):
|
||||
return self.start == other.start and \
|
||||
@@ -676,15 +693,6 @@ class BaseNodeParser(BaseParser):
|
||||
|
||||
return custom_concepts if custom else None
|
||||
|
||||
@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
|
||||
|
||||
@staticmethod
|
||||
def get_concepts_by_first_keyword(context, concepts, use_sheerka=False):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user