From 5dac9d1dfb6f73a34a05116cf01924883eebf3dd Mon Sep 17 00:00:00 2001 From: dusk Date: Sat, 24 Feb 2024 17:57:20 +0100 Subject: [PATCH] Prettier '!sd.]' fix --- src/fix.py | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/src/fix.py b/src/fix.py index b2a28c1..a1923c6 100644 --- a/src/fix.py +++ b/src/fix.py @@ -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: