From 854a8fb247b5cb06e9f55408e1801ce8b2436fb0 Mon Sep 17 00:00:00 2001 From: Max Lindqvist Date: Thu, 23 Oct 2025 11:54:25 +0200 Subject: [PATCH 1/2] Ignore commented lines in remove_pre_ampersands --- fprettify/__init__.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/fprettify/__init__.py b/fprettify/__init__.py index d6450a3..a4f3996 100644 --- a/fprettify/__init__.py +++ b/fprettify/__init__.py @@ -1806,13 +1806,15 @@ def remove_pre_ampersands(lines, is_special, filename, line_nr): match = re.search(SOL_STR + r'(&\s*)', line) if match: pre_ampersand.append(match.group(1)) - # amount of whitespace before ampersand of previous line: - m = re.search(r'(\s*)&[\s]*(?:!.*)?$', lines[pos - 1]) - if not m: - raise FprettifyParseException( - "Bad continuation line format", filename, line_nr) - sep = len(m.group(1)) + # find the previous non-comment line + _pos = pos - 1 + while _pos >= 0 and lines[_pos].lstrip().startswith('!'): + _pos -= 1 + _pos = max(_pos, 0) # ensure non-negative index + + m = re.search(r'(\s*)&[\s]*(?:!.*)?$', lines[_pos]) + sep = len(m.group(1)) ampersand_sep.append(sep) else: pre_ampersand.append('') From 761f329d06a4df73ec141b2edfd905c27190b723 Mon Sep 17 00:00:00 2001 From: Max Lindqvist Date: Thu, 23 Oct 2025 11:56:56 +0200 Subject: [PATCH 2/2] Use raw string --- fprettify/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fprettify/__init__.py b/fprettify/__init__.py index a4f3996..f2f492f 100644 --- a/fprettify/__init__.py +++ b/fprettify/__init__.py @@ -269,7 +269,7 @@ def split(self, line): LR_OPS_RE = [REL_OP_RE, LOG_OP_RE, plusminus_parser(PLUSMINUS_RE), MULTDIV_RE, PRINT_RE] USE_RE = re.compile( - SOL_STR + "USE(\s+|(,.+?)?::\s*)\w+?((,.+?=>.+?)+|,\s*only\s*:.+?)?$" + EOL_STR, RE_FLAGS) + SOL_STR + r"USE(\s+|(,.+?)?::\s*)\w+?((,.+?=>.+?)+|,\s*only\s*:.+?)?$" + EOL_STR, RE_FLAGS) # markups to deactivate formatter NO_ALIGN_RE = re.compile(SOL_STR + r"&\s*[^\s*]+")