Showing the changes to interface/src/ScriptHighlighting.cpp (1 of 8 files). Show all
Unified · Split
| @@ -22,6 +22,7 @@ ScriptHighlighting::ScriptHighlighting(QTextDocument* parent) : · 21 unmodified lines | ||
| 22 | 22 | _numberRegex = QRegExp("[0-9]+(\\.[0-9]+){0,1}"); |
| 23 | 23 | _singleLineComment = QRegExp("//[^\n]*"); |
| 24 | 24 | _truefalseRegex = QRegExp("\\b(true|false)\\b"); |
| 25 | + _alphacharRegex = QRegExp("[A-Za-z]"); | |
| 25 | 26 | } |
| 26 | 27 | |
| 27 | 28 | void ScriptHighlighting::highlightBlock(const QString& text) { |
| @@ -60,7 +61,19 @@ void ScriptHighlighting::formatComments(const QString& text) { · 32 unmodified lines | ||
| 60 | 61 | int index = _singleLineComment.indexIn(text); |
| 61 | 62 | while (index >= 0) { |
| 62 | 63 | int length = _singleLineComment.matchedLength(); |
| 63 | − setFormat(index, length, Qt::lightGray); | |
| 64 | + int quoted_index = _qoutedTextRegex.indexIn(text); | |
| 65 | + bool valid = true; | |
| 66 | + while (quoted_index >= 0 && valid) { | |
| 67 | + int quoted_length = _qoutedTextRegex.matchedLength(); | |
| 68 | + if (quoted_index <= index && index <= (quoted_index + quoted_length)) { | |
| 69 | + valid = false; | |
| 70 | + } | |
| 71 | + quoted_index = _qoutedTextRegex.indexIn(text, quoted_index + quoted_length); | |
| 72 | + } | |
| 73 | + | |
| 74 | + if (valid) { | |
| 75 | + setFormat(index, length, Qt::lightGray); | |
| 76 | + } | |
| 64 | 77 | index = _singleLineComment.indexIn(text, index + length); |
| 65 | 78 | } |
| 66 | 79 | } |
| @@ -78,7 +91,9 @@ void ScriptHighlighting::formatNumbers(const QString& text){ · 11 unmodified lines | ||
| 78 | 91 | int index = _numberRegex.indexIn(text); |
| 79 | 92 | while (index >= 0) { |
| 80 | 93 | int length = _numberRegex.matchedLength(); |
| 81 | − setFormat(index, length, Qt::green); | |
| 94 | + if (index == 0 || _alphacharRegex.indexIn(text, index - 1) != (index - 1)) { | |
| 95 | + setFormat(index, length, Qt::green); | |
| 96 | + } | |
| 82 | 97 | index = _numberRegex.indexIn(text, index + length); |
| 83 | 98 | } |
| 84 | 99 | } |