Closed jpe closed 8 months ago
How about merge the for and while loop as:
if (!options.pep701StringsF) {
// Find the deepest single quote state because that string will end; no \ continuation in f-string
for (size_t i = 0; i < fstringStateStack.size(); i++) {
if (IsPySingleQuoteStringState(fstringStateStack[i].state)) {
sc.SetState(fstringStateStack[i].state);
while (fstringStateStack.size() > i) {
PopFromStateStack(fstringStateStack, currentFStringExp);
}
break;
}
}
}
this would avoid some lint warnings:
long
is always 32 bit on Windows, use size_t
avoided truncate warning and extra cast.i
can be reduced, and deepestSingleStateIndex
can be removed (or can be changed to size_t
and npos
).Committed da28b2c which is similar to 5f81ddb but with stringsF
corrected to pep701StringsF
in DefineProperty
and with declarations of deepestSingleStateIndex
and i
moved inside if
to avoid warnings.
Did not (yet) commit type and loop change as it isn't trivial and I didn't find a good test case. It seems that the stack popping only occurs when there are erroneous outstanding quoted strings being forcibly ended.
The type and loop changes looks non-functionality change for me:
i
is only used inside the for loop.if (deepestSingleStateIndex != -1)
is only true when the for loop breaks.
These changes add support for PEP 701 f-strings by bypassing the logic that would terminate an f-string if the starting quote was seen. The pre-PEP 701 behavior is kept as an option, though I don't have any plans to use the pre-PEP 701 and would be +0 on removing the old behavior.