Remove some duplicated tokens

main
Micke Nordin 6 months ago
parent 0317cb731b
commit fb12a4006a
Signed by: micke
GPG Key ID: 0DA0A7A5708FE257
  1. 24
      parser.py

@ -150,6 +150,14 @@ def collapse_tokens(uncollapsed_tokens: list) -> list:
usefull_tokens.sort(key=operator.itemgetter('line_number'))
return usefull_tokens
def remove_token(removable: dict, tokens: list) -> list:
for index in range(0,len(tokens)):
token = tokens[index]
if token == removable:
del tokens[index]
break
return tokens
collapsed_tokens = collapse_tokens(tokens)
for index in range(0, len(collapsed_tokens)):
@ -159,4 +167,20 @@ for index in range(0, len(collapsed_tokens)):
collapsed_tokens[index]['function'] = function.pop()
params = coaless_tokens(token['params'], token['line_number'],collapsed_tokens.copy(), "variable_declaration")
collapsed_tokens[index]['params'] = params
minus = 0
for index in range(0, len(collapsed_tokens)):
token = collapsed_tokens[index - minus].copy()
if token['variant'] == 'function_declaration':
for part in token['body']:
collapsed_tokens = remove_token(part,collapsed_tokens.copy())
minus = minus + 1
if token['variant'] == 'function_call':
for part in token['function']['body']:
collapsed_tokens = remove_token(part,collapsed_tokens.copy())
minus = minus + 1
collapsed_tokens = remove_token(token['function'],collapsed_tokens.copy())
minus = minus + 1
print(json.dumps(collapsed_tokens))

Loading…
Cancel
Save