Prettier '!sd.]' fix

This commit is contained in:
Dusk 2024-02-24 17:57:20 +01:00
parent 657b81ac94
commit 5dac9d1dfb
1 changed files with 22 additions and 10 deletions

View File

@ -167,16 +167,28 @@ def fix_common_displaced_commands(line: str) -> str:
# '!sd。」'
if len(tokens) > 3 and \
tokens[-3].token == '!sd' and \
tokens[-2].token in ['。」','','','、」'] and \
tokens[-1].type == scripter.TokenType.COMMAND:
# Prepend to end
quot = tokens.pop(-2).token
excl = tokens.pop(-2).token
tokens[-1].token = excl + tokens[-1].token
tokens[-2].token += quot
if (
len(tokens) > 3
and tokens[-3].token == '!sd'
and tokens[-2].token in [ # quot
'。」',
'',
'',
'、」',
]
and tokens[-1].type == scripter.TokenType.COMMAND # final
):
# Get the final symbols
# [text][command]<[text][command]>
quot = tokens[-2].token
final = tokens[-1].token
# Append them to the previous ones (-3 and -4)
# <[text+text][command+command]>[text][command]
tokens[-4].token += quot
tokens[-3].token += final
# Trim the leftovers
# [text+text][command+command]<>
tokens = tokens[:-2]
for t in tokens: