diff options
author | Eike Ziller <eike.ziller@qt.io> | 2017-05-05 20:41:43 +0200 |
---|---|---|
committer | Eike Ziller <eike.ziller@qt.io> | 2017-05-08 08:49:49 +0000 |
commit | ecbe001f2efb27607287ffdb23976babdc9a7228 (patch) | |
tree | 6d42f1c4e5361fce3b0ce86c9ca07a67f1d5483b | |
parent | fca108c35dd414b1d90eeb4b75f30292a2723f9b (diff) | |
download | qt-creator-ecbe001f2efb27607287ffdb23976babdc9a7228.tar.gz |
Get rid of special "EndOfBlock" format in python highlighter
Change-Id: Ie02d3ae02b2453b33a3c779307f6f44348e2d0cd
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
-rw-r--r-- | src/plugins/pythoneditor/pythonformattoken.h | 11 | ||||
-rw-r--r-- | src/plugins/pythoneditor/pythonhighlighter.cpp | 4 | ||||
-rw-r--r-- | src/plugins/pythoneditor/pythonscanner.cpp | 2 |
3 files changed, 9 insertions, 8 deletions
diff --git a/src/plugins/pythoneditor/pythonformattoken.h b/src/plugins/pythoneditor/pythonformattoken.h index 6f1da963b7..285fb548ac 100644 --- a/src/plugins/pythoneditor/pythonformattoken.h +++ b/src/plugins/pythoneditor/pythonformattoken.h @@ -42,8 +42,7 @@ enum Format { Format_Whitespace, Format_ImportedModule, - Format_FormatsAmount, - Format_EndOfBlock + Format_FormatsAmount }; class FormatToken @@ -55,15 +54,17 @@ public: : m_format(format), m_position(position), m_length(length) {} + bool isEndOfBlock() { return m_position == -1; } + Format format() const { return m_format; } int begin() const { return m_position; } int end() const { return m_position + m_length; } int length() const { return m_length; } private: - Format m_format; - int m_position; - int m_length; + Format m_format = Format_FormatsAmount; + int m_position = -1; + int m_length = -1; }; } // namespace Internal diff --git a/src/plugins/pythoneditor/pythonhighlighter.cpp b/src/plugins/pythoneditor/pythonhighlighter.cpp index fd3562f775..dcc5291b64 100644 --- a/src/plugins/pythoneditor/pythonhighlighter.cpp +++ b/src/plugins/pythoneditor/pythonhighlighter.cpp @@ -117,7 +117,7 @@ int PythonHighlighter::highlightLine(const QString &text, int initialState) FormatToken tk; bool hasOnlyWhitespace = true; - while ((tk = scanner.read()).format() != Format_EndOfBlock) { + while (!(tk = scanner.read()).isEndOfBlock()) { Format format = tk.format(); if (format == Format_Keyword) { QString value = scanner.value(tk); @@ -141,7 +141,7 @@ int PythonHighlighter::highlightLine(const QString &text, int initialState) void PythonHighlighter::highlightImport(Scanner &scanner) { FormatToken tk; - while ((tk = scanner.read()).format() != Format_EndOfBlock) { + while (!(tk = scanner.read()).isEndOfBlock()) { Format format = tk.format(); if (tk.format() == Format_Identifier) format = Format_ImportedModule; diff --git a/src/plugins/pythoneditor/pythonscanner.cpp b/src/plugins/pythoneditor/pythonscanner.cpp index 89ce77d332..cc75259903 100644 --- a/src/plugins/pythoneditor/pythonscanner.cpp +++ b/src/plugins/pythoneditor/pythonscanner.cpp @@ -50,7 +50,7 @@ FormatToken Scanner::read() { setAnchor(); if (isEnd()) - return FormatToken(Format_EndOfBlock, anchor(), 0); + return FormatToken(); State state; QChar saved; |