ScintillaOrg / lexilla

A library of language lexers for use with Scintilla
https://www.scintilla.org/Lexilla.html
Other
163 stars 59 forks source link

Pep701 fstrings #209

Closed jpe closed 8 months ago

jpe commented 9 months ago

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.

zufuliu commented 9 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:

nyamatongwe commented 8 months ago

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.

zufuliu commented 8 months ago

The type and loop changes looks non-functionality change for me: