update: pushed more readable tokens
This commit is contained in:
parent
06c2d19097
commit
285104a19a
6 changed files with 199 additions and 239 deletions
20
parser/token.py/concat.py
Normal file
20
parser/token.py/concat.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
from ttoken import *
|
||||
|
||||
def concat(tokens: list[Token]):
|
||||
i = 0
|
||||
out = []
|
||||
while i < len(tokens):
|
||||
tok = tokens[i]
|
||||
if tok.is_word():
|
||||
word = Token(TokenType.WORD, subtokens=[])
|
||||
word.subtokens.append(tok)
|
||||
j = 1
|
||||
while i + j < len(tokens) and (tokens[i + j]).is_word():
|
||||
word.subtokens.append(tokens[i + j])
|
||||
j += 1
|
||||
i += j
|
||||
out.append(word)
|
||||
else:
|
||||
out.append(tok)
|
||||
i += 1
|
||||
return out
|
||||
Loading…
Add table
Add a link
Reference in a new issue