Changeset View
Changeset View
Standalone View
Standalone View
src/highlighter.cpp
Show First 20 Lines • Show All 76 Lines • ▼ Show 20 Line(s) | |||||
77 | 77 | | |||
78 | Token* Highlighter::checkOrApplyHighlighting(const QString& text, int cursorIndex) | 78 | Token* Highlighter::checkOrApplyHighlighting(const QString& text, int cursorIndex) | ||
79 | { | 79 | { | ||
80 | tokenizer->initialize(text); | 80 | tokenizer->initialize(text); | ||
81 | Token* token = tokenizer->getToken(); | 81 | Token* token = tokenizer->getToken(); | ||
82 | QTextCharFormat* format; | 82 | QTextCharFormat* format; | ||
83 | while (token->type() != Token::EndOfInput) { | 83 | while (token->type() != Token::EndOfInput) { | ||
84 | format = tokenToFormat(token); | 84 | format = tokenToFormat(token); | ||
85 | if (format != 0) { | 85 | if (format) { | ||
86 | if (cursorIndex == -1) // does not return, but keeps running | 86 | if (cursorIndex == -1) // does not return, but keeps running | ||
87 | setFormat(token->startCol() - 1, token->endCol() - token->startCol(), *format); | 87 | setFormat(token->startCol() - 1, token->endCol() - token->startCol(), *format); | ||
88 | else if (cursorIndex >= token->startCol() && cursorIndex <= token->endCol()) | 88 | else if (cursorIndex >= token->startCol() && cursorIndex <= token->endCol()) | ||
89 | return token; // returns, one shot only | 89 | return token; // returns, one shot only | ||
90 | } | 90 | } | ||
91 | delete token; | 91 | delete token; | ||
92 | token = tokenizer->getToken(); | 92 | token = tokenizer->getToken(); | ||
93 | } | 93 | } | ||
94 | delete token; | 94 | delete token; | ||
95 | return 0; | 95 | return nullptr; | ||
96 | } | 96 | } | ||
97 | 97 | | |||
98 | QTextCharFormat* Highlighter::tokenToFormat(Token* token) | 98 | QTextCharFormat* Highlighter::tokenToFormat(Token* token) | ||
99 | { | 99 | { | ||
100 | switch (token->category()) { | 100 | switch (token->category()) { | ||
101 | case Token::VariableCategory: return &variableFormat; | 101 | case Token::VariableCategory: return &variableFormat; | ||
102 | case Token::TrueFalseCategory: return &trueFalseFormat; | 102 | case Token::TrueFalseCategory: return &trueFalseFormat; | ||
103 | case Token::NumberCategory: return &numberFormat; | 103 | case Token::NumberCategory: return &numberFormat; | ||
104 | case Token::CommentCategory: return &commentFormat; | 104 | case Token::CommentCategory: return &commentFormat; | ||
105 | case Token::StringCategory: return &stringFormat; | 105 | case Token::StringCategory: return &stringFormat; | ||
106 | case Token::ScopeCategory: return &scopeFormat; | 106 | case Token::ScopeCategory: return &scopeFormat; | ||
107 | case Token::CommandCategory: return &otherCommandFormat; | 107 | case Token::CommandCategory: return &otherCommandFormat; | ||
108 | case Token::ControllerCommandCategory: return &controllerCommandFormat; | 108 | case Token::ControllerCommandCategory: return &controllerCommandFormat; | ||
109 | case Token::LearnCommandCategory: return &learnCommandFormat; | 109 | case Token::LearnCommandCategory: return &learnCommandFormat; | ||
110 | case Token::ExpressionCategory: return &expressionFormat; | 110 | case Token::ExpressionCategory: return &expressionFormat; | ||
111 | case Token::BooleanOperatorCategory: return &booleanOperatorFormat; | 111 | case Token::BooleanOperatorCategory: return &booleanOperatorFormat; | ||
112 | case Token::MathOperatorCategory: return &mathOperatorFormat; | 112 | case Token::MathOperatorCategory: return &mathOperatorFormat; | ||
113 | case Token::AssignmentCategory: return &assignmentFormat; | 113 | case Token::AssignmentCategory: return &assignmentFormat; | ||
114 | 114 | | |||
115 | // do nothing with these... | 115 | // do nothing with these... | ||
116 | case Token::ParenthesisCategory: return 0; | 116 | case Token::ParenthesisCategory: return nullptr; | ||
117 | case Token::FunctionCallCategory: return 0; | 117 | case Token::FunctionCallCategory: return nullptr; | ||
118 | case Token::ArgumentSeparatorCategory: return 0; | 118 | case Token::ArgumentSeparatorCategory: return nullptr; | ||
119 | } | 119 | } | ||
120 | return 0; | 120 | return nullptr; | ||
121 | } | 121 | } |