forked from qt-creator/qt-creator
Get rid of special "EndOfBlock" format in python highlighter
Change-Id: Ie02d3ae02b2453b33a3c779307f6f44348e2d0cd Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
@@ -42,8 +42,7 @@ enum Format {
|
|||||||
Format_Whitespace,
|
Format_Whitespace,
|
||||||
Format_ImportedModule,
|
Format_ImportedModule,
|
||||||
|
|
||||||
Format_FormatsAmount,
|
Format_FormatsAmount
|
||||||
Format_EndOfBlock
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class FormatToken
|
class FormatToken
|
||||||
@@ -55,15 +54,17 @@ public:
|
|||||||
: m_format(format), m_position(position), m_length(length)
|
: m_format(format), m_position(position), m_length(length)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
bool isEndOfBlock() { return m_position == -1; }
|
||||||
|
|
||||||
Format format() const { return m_format; }
|
Format format() const { return m_format; }
|
||||||
int begin() const { return m_position; }
|
int begin() const { return m_position; }
|
||||||
int end() const { return m_position + m_length; }
|
int end() const { return m_position + m_length; }
|
||||||
int length() const { return m_length; }
|
int length() const { return m_length; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Format m_format;
|
Format m_format = Format_FormatsAmount;
|
||||||
int m_position;
|
int m_position = -1;
|
||||||
int m_length;
|
int m_length = -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ int PythonHighlighter::highlightLine(const QString &text, int initialState)
|
|||||||
|
|
||||||
FormatToken tk;
|
FormatToken tk;
|
||||||
bool hasOnlyWhitespace = true;
|
bool hasOnlyWhitespace = true;
|
||||||
while ((tk = scanner.read()).format() != Format_EndOfBlock) {
|
while (!(tk = scanner.read()).isEndOfBlock()) {
|
||||||
Format format = tk.format();
|
Format format = tk.format();
|
||||||
if (format == Format_Keyword) {
|
if (format == Format_Keyword) {
|
||||||
QString value = scanner.value(tk);
|
QString value = scanner.value(tk);
|
||||||
@@ -141,7 +141,7 @@ int PythonHighlighter::highlightLine(const QString &text, int initialState)
|
|||||||
void PythonHighlighter::highlightImport(Scanner &scanner)
|
void PythonHighlighter::highlightImport(Scanner &scanner)
|
||||||
{
|
{
|
||||||
FormatToken tk;
|
FormatToken tk;
|
||||||
while ((tk = scanner.read()).format() != Format_EndOfBlock) {
|
while (!(tk = scanner.read()).isEndOfBlock()) {
|
||||||
Format format = tk.format();
|
Format format = tk.format();
|
||||||
if (tk.format() == Format_Identifier)
|
if (tk.format() == Format_Identifier)
|
||||||
format = Format_ImportedModule;
|
format = Format_ImportedModule;
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ FormatToken Scanner::read()
|
|||||||
{
|
{
|
||||||
setAnchor();
|
setAnchor();
|
||||||
if (isEnd())
|
if (isEnd())
|
||||||
return FormatToken(Format_EndOfBlock, anchor(), 0);
|
return FormatToken();
|
||||||
|
|
||||||
State state;
|
State state;
|
||||||
QChar saved;
|
QChar saved;
|
||||||
|
|||||||
Reference in New Issue
Block a user