Working on #48 : Refactored FunctionParser, introducting ExpressionParser

This commit is contained in:
2021-03-10 11:46:39 +01:00
parent 07f0d3670d
commit 966a1ed814
11 changed files with 239 additions and 67 deletions
+7 -2
View File
@@ -545,16 +545,21 @@ def decode_concept(text, wrapper="C"):
return None, None
def tokens_index(tokens, sub_tokens, skip=0):
def tokens_index(tokens, sub_tokens, skip=0, start_from_end=False):
"""
Index of the sub tokens in tokens
:param tokens: tokens
:param sub_tokens: sub tokens to search
:param skip: number of found to skip
:param start_from_end: start by the end
:return:
"""
expected = [token.value for token in sub_tokens if token.type != TokenKind.EOF]
for i in range(0, len(tokens) - len(expected) + 1):
indexes = range(0, len(tokens) - len(expected) + 1)
if start_from_end:
indexes = reversed(indexes)
for i in indexes:
for j in range(len(expected)):
if tokens[i + j].value != expected[j]:
break