Skip to content

Commit 4bfa36c

Browse files
libretroadminLibretroAdmin
authored andcommitted
tools/settings_migrate_group: join backslash-continued guard lines
A conditional split across physical lines with a continuation was captured as its first line only, truncating the condition and leaking the backslash into the flattened guard expression - the window-position table sits under exactly such a two-line guard. Both the enclosing walker and the body scanner now join continuations before classification.
1 parent 08f90f7 commit 4bfa36c

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

tools/settings_migrate_group.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,18 @@ def guard_at(text, pos):
8080
for gl in re.finditer(r'^[ \t]*#(if\w*[^\n]*|else|endif)', text[:pos], re.M):
8181
s = gl.group(1)
8282
if s.startswith('if'):
83-
stack.append('#' + s.strip())
83+
_full, _e = s, gl.end()
84+
while _full.rstrip().endswith('\\'):
85+
_nl = text.find('\n', _e)
86+
if _nl < 0:
87+
break
88+
_nl2 = text.find('\n', _nl + 1)
89+
_cont = text[_nl + 1:(_nl2 if _nl2 >= 0 else len(text))]
90+
_full = _full.rstrip().rstrip('\\').rstrip() + ' ' + _cont.strip()
91+
if _nl2 < 0:
92+
break
93+
_e = _nl2
94+
stack.append('#' + _full.strip())
8495
elif s.startswith('else') and stack:
8596
stack[-1] = _negate_guard(stack[-1])
8697
elif s.startswith('endif') and stack:
@@ -92,6 +103,7 @@ def guard_of(text, pat):
92103

93104
table_guard = tuple(guard_at(ms, tm.start()))
94105
guards = {}
106+
_cont_prev = None
95107
body = tm.group(1)
96108
# Depth-aware: record the FULL stack of enclosing #if guards for each row.
97109
# A flat "#if ... #endif" regex (non-greedy) stops at the first #endif and
@@ -103,7 +115,16 @@ def guard_of(text, pat):
103115
gstack = []
104116
for ln in body.split('\n'):
105117
s = ln.strip()
118+
if _cont_prev is not None:
119+
_joined = _cont_prev.rstrip('\\').rstrip() + ' ' + s
120+
_cont_prev = _joined if s.endswith('\\') else None
121+
if _cont_prev is None:
122+
gstack.append(_joined)
123+
continue
106124
if s.startswith('#if'):
125+
if s.endswith('\\'):
126+
_cont_prev = s
127+
continue
107128
gstack.append(s)
108129
elif s.startswith('#endif'):
109130
if gstack:

0 commit comments

Comments
 (0)