Iterative ternary if/else rewrite, Raft partial fix
- Replaced complex ternary regex with simpler iterative approach - Raft: 3 errors → 9 errors (regression due to multiline let detection) - Fixed simple single-line ternary expressions Progress: 12 specs at 0 errors, Raft needs multiline let parsing
This commit is contained in:
parent
52be7b1c6d
commit
dbde01ccb5
1 changed files with 8 additions and 4 deletions
|
|
@ -542,10 +542,14 @@ function rewriteExpr(expr: string, stateVarNames: Set<string>, mapVarNames: Set<
|
||||||
ts = ts.replace(/\.size\(\)/g, '.size');
|
ts = ts.replace(/\.size\(\)/g, '.size');
|
||||||
|
|
||||||
// 5i: SpeckDL conditional expression: if cond: a else b -> cond ? a : b
|
// 5i: SpeckDL conditional expression: if cond: a else b -> cond ? a : b
|
||||||
// Use a careful regex that matches word boundaries and stops at expression end
|
// Simpler approach: match if <cond>: <then> else <else>
|
||||||
// Pattern: if <cond>: <then> else <else>
|
// where cond doesn't contain { } : and then/else don't contain ; or }
|
||||||
// Where cond, then, else are balanced expressions (no unbalanced braces at top level)
|
let prev2;
|
||||||
ts = ts.replace(/\bif\s+((?:[^{}:()]|\([^)]*\)|\{[^}]*\})+):\s*((?:[^{};]|\{[^}]*\})+)\s+else\s+((?:[^{};]|\{[^}]*\})+)(?=[;)}\],\s]|$)/g, '($1 ? $2 : $3)');
|
do {
|
||||||
|
prev2 = ts;
|
||||||
|
// Match if followed by non-special chars, colon, then clause, else, else clause
|
||||||
|
ts = ts.replace(/\bif\s+([^{}:]+):\s*([^{};]+)\s+else\s+([^{};\n]+)/g, '($1 ? $2 : $3)');
|
||||||
|
} while (ts !== prev2);
|
||||||
|
|
||||||
return ts.trim();
|
return ts.trim();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue