void Indenter::parsePreviousLine(
        const TextEditor::TabSettings &settings,
        const QString &previousLine,
        const QTextBlock &previousBlock,
        int &indentation) const
{
    // TODO: replace this dirty code with true AST-based indentation
    Internal::Scanner sc(previousLine.constData(), previousLine.length());
    for (;;)
    {
        Internal::FormatToken tk = sc.read();
        if (tk.format() == Internal::Format_KEYWORD) {
            QString value = sc.value(tk);

            if (JUMP_STATEMENTS_SET.contains(value)) {
                indentation = qMax<int>(0, indentation - TAB_SIZE);
            } else if (BACKSTEP_KEYWORDS_SET.contains(value)) {
                indentation = qMax<int>(0, indentation - TAB_SIZE);
                settings.reindentLine(previousBlock, -TAB_SIZE);
            }
        }
        if (tk.format() != Internal::Format_WHITESPACE) {
            break;
        }
    }
}
Exemplo n.º 2
0
/// @return negative indent diff if previous line breaks control flow branch
int PythonIndenter::getIndentDiff(const QString &previousLine) const
{
    Internal::Scanner sc(previousLine.constData(), previousLine.length());
    forever {
        Internal::FormatToken tk = sc.read();
        if ((tk.format() == Internal::Format_Keyword) && m_jumpKeywords.contains(sc.value(tk)))
            return -TAB_SIZE;
        if (tk.format() != Internal::Format_Whitespace)
            break;
    }
    return 0;
}