|
|
|
@ -58,7 +58,7 @@ def coaless_tokens(identifiers, line_number, usefull_tokens, variant) -> list:
|
|
|
|
|
def collapse_tokens(uncollapsed_tokens: list) -> list:
|
|
|
|
|
usefull_tokens = list()
|
|
|
|
|
in_block = False
|
|
|
|
|
block = str()
|
|
|
|
|
block = ""
|
|
|
|
|
block_index = -1
|
|
|
|
|
block_lineno = -1
|
|
|
|
|
for index in range(0, len(uncollapsed_tokens)):
|
|
|
|
@ -68,13 +68,20 @@ def collapse_tokens(uncollapsed_tokens: list) -> list:
|
|
|
|
|
in_block = True
|
|
|
|
|
block_lineno = token['line_number']
|
|
|
|
|
if token['variant'] == 'end_block':
|
|
|
|
|
in_block = False
|
|
|
|
|
compare_lineno = block_lineno + 1
|
|
|
|
|
block_lineno = token['line_number']
|
|
|
|
|
# Do we need to append new lines
|
|
|
|
|
for i in range (compare_lineno, block_lineno):
|
|
|
|
|
block = block + "\n"
|
|
|
|
|
|
|
|
|
|
name = "multiline"
|
|
|
|
|
maybe_variable = peek(block_index - 2, uncollapsed_tokens)
|
|
|
|
|
if maybe_variable['variant'] == 'signifier':
|
|
|
|
|
name = maybe_variable['value']
|
|
|
|
|
usefull_token = { "variant": "variable_declaration", "signifier": name, "type": "string", "line_number": maybe_variable['line_number'], "expression": block }
|
|
|
|
|
usefull_tokens.append(usefull_token)
|
|
|
|
|
# Reset for next multiline
|
|
|
|
|
in_block = False
|
|
|
|
|
block = str()
|
|
|
|
|
block_index = -1
|
|
|
|
|
block_lineno = -1
|
|
|
|
@ -82,22 +89,19 @@ def collapse_tokens(uncollapsed_tokens: list) -> list:
|
|
|
|
|
# This is a declaration
|
|
|
|
|
if token['variant'] == 'syntax_error':
|
|
|
|
|
if in_block:
|
|
|
|
|
old_lineno = block_lineno
|
|
|
|
|
compare_lineno = block_lineno + 1
|
|
|
|
|
block_lineno = token['line_number']
|
|
|
|
|
if block:
|
|
|
|
|
for i in range (old_lineno, block_lineno -1):
|
|
|
|
|
# This is if we don't have a block allready
|
|
|
|
|
if block == "":
|
|
|
|
|
# Do we need to prepend empty lines?
|
|
|
|
|
for i in range (compare_lineno, block_lineno):
|
|
|
|
|
block = block + "\n"
|
|
|
|
|
block = block + token['value']
|
|
|
|
|
block = block + token['value'] + "\n"
|
|
|
|
|
else:
|
|
|
|
|
if old_lineno +1 != block_lineno:
|
|
|
|
|
for i in range (old_lineno, block_lineno -1):
|
|
|
|
|
block = block + "\n"
|
|
|
|
|
else:
|
|
|
|
|
# and if we do
|
|
|
|
|
for i in range (compare_lineno, block_lineno):
|
|
|
|
|
block = block + "\n"
|
|
|
|
|
|
|
|
|
|
block = block + token['value']
|
|
|
|
|
for i in range (old_lineno, block_lineno -1):
|
|
|
|
|
block = block + "\n"
|
|
|
|
|
block = block + token['value'] + "\n"
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
usefull_token = token
|
|
|
|
|