Working on #48 : Refactored FunctionParser, introducting ExpressionParser
This commit is contained in:
+7
-2
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user