43 #include "private/qfunctions_p.h" 45 #ifndef QT_NO_SYNTAXHIGHLIGHTER 59 #define MAX_KEYWORD 63 144 const char *
const *start = &
keywords[0];
173 enum States { StateStandard, StateCommentStart1, StateCCommentStart2,
174 StateScriptCommentStart2, StateCComment, StateScriptComment, StateCCommentEnd1,
175 StateCCommentEnd2, StateStringStart, StateString, StateStringEnd,
176 StateString2Start, StateString2, StateString2End,
177 StateNumber, StatePreProcessor, NumStates };
180 enum Tokens { InputAlpha, InputNumber, InputAsterix, InputSlash, InputParen,
181 InputSpace, InputHash, InputQuotation, InputApostrophe, InputSep, NumTokens };
183 static uchar table[NumStates][NumTokens] = {
184 { StateStandard, StateNumber, StateStandard, StateCommentStart1, StateStandard, StateStandard, StatePreProcessor, StateStringStart, StateString2Start, StateStandard },
185 { StateStandard, StateNumber, StateCCommentStart2, StateScriptCommentStart2, StateStandard, StateStandard, StatePreProcessor, StateStringStart, StateString2Start, StateStandard },
186 { StateCComment, StateCComment, StateCCommentEnd1, StateCComment, StateCComment, StateCComment, StateCComment, StateCComment, StateCComment, StateCComment },
187 { StateScriptComment, StateScriptComment, StateScriptComment, StateScriptComment, StateScriptComment, StateScriptComment, StateScriptComment, StateScriptComment, StateScriptComment, StateScriptComment },
188 { StateCComment, StateCComment, StateCCommentEnd1, StateCComment, StateCComment, StateCComment, StateCComment, StateCComment, StateCComment, StateCComment },
189 { StateScriptComment, StateScriptComment, StateScriptComment, StateScriptComment, StateScriptComment, StateScriptComment, StateScriptComment, StateScriptComment, StateScriptComment, StateScriptComment },
190 { StateCComment, StateCComment, StateCCommentEnd1, StateCCommentEnd2, StateCComment, StateCComment, StateCComment, StateCComment, StateCComment, StateCComment },
191 { StateStandard, StateNumber, StateStandard, StateCommentStart1, StateStandard, StateStandard, StatePreProcessor, StateStringStart, StateString2Start, StateStandard },
192 { StateString, StateString, StateString, StateString, StateString, StateString, StateString, StateStringEnd, StateString, StateString },
193 { StateString, StateString, StateString, StateString, StateString, StateString, StateString, StateStringEnd, StateString, StateString },
194 { StateStandard, StateStandard, StateStandard, StateCommentStart1, StateStandard, StateStandard, StatePreProcessor, StateStringStart, StateString2Start, StateStandard },
195 { StateString2, StateString2, StateString2, StateString2, StateString2, StateString2, StateString2, StateString2, StateString2End, StateString2 },
196 { StateString2, StateString2, StateString2, StateString2, StateString2, StateString2, StateString2, StateString2, StateString2End, StateString2 },
197 { StateStandard, StateStandard, StateStandard, StateCommentStart1, StateStandard, StateStandard, StatePreProcessor, StateStringStart, StateString2Start, StateStandard },
198 { StateNumber, StateNumber, StateStandard, StateCommentStart1, StateStandard, StateStandard, StatePreProcessor, StateStringStart, StateString2Start, StateStandard },
199 { StatePreProcessor, StateStandard, StateStandard, StateCommentStart1, StateStandard, StateStandard, StatePreProcessor, StateStringStart, StateString2Start, StateStandard }
207 int state = StateStandard;
210 if (previousState != -1) {
211 state = previousState & 0xff;
212 braceDepth = previousState >> 8;
218 TextEditDocumentLayout::clearParentheses(
currentBlock());
223 Parentheses parentheses;
224 parentheses.reserve(20);
228 bool lastWasBackSlash =
false;
229 bool makeLastStandard =
false;
231 static const QString alphabeth =
QLatin1String(
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
234 bool questionMark =
false;
237 int firstNonSpace = -1;
242 if (lastWasBackSlash) {
247 input = InputAsterix;
260 case StatePreProcessor:
261 case StateCCommentEnd2:
262 case StateCCommentEnd1:
263 case StateString2End:
272 if (--braceDepth < 0)
280 case StatePreProcessor:
281 case StateCCommentEnd2:
282 case StateCCommentEnd1:
283 case StateString2End:
295 input = InputQuotation;
298 input = InputApostrophe;
303 case '1':
case '2':
case '3':
case '4':
case '5':
304 case '6':
case '7':
case '8':
case '9':
case '0':
310 if (input == InputAlpha && numbers.
contains(lastChar))
319 if (state == StateStandard && !questionMark && lastChar != colon) {
321 if (nextChar != colon)
322 for (
int j = 0; j < i; ++j) {
323 if (
format(j) == emptyFormat )
339 if (input != InputSpace && firstNonSpace < 0)
342 lastWasBackSlash = !lastWasBackSlash && c ==
QLatin1Char(
'\\');
344 if (input == InputAlpha)
347 state = table[state][input];
350 case StateStandard: {
352 if (makeLastStandard)
354 makeLastStandard =
false;
355 if (input != InputAlpha) {
360 case StateCommentStart1:
361 if (makeLastStandard)
363 makeLastStandard =
true;
366 case StateCCommentStart2:
368 makeLastStandard =
false;
372 case StateScriptCommentStart2:
374 makeLastStandard =
false;
378 if (makeLastStandard)
380 makeLastStandard =
false;
384 case StateScriptComment:
385 if (makeLastStandard)
387 makeLastStandard =
false;
391 case StateCCommentEnd1:
392 if (makeLastStandard)
394 makeLastStandard =
false;
398 case StateCCommentEnd2:
399 if (makeLastStandard)
401 makeLastStandard =
false;
406 case StateStringStart:
407 if (makeLastStandard)
409 makeLastStandard =
false;
414 if (makeLastStandard)
416 makeLastStandard =
false;
421 if (makeLastStandard)
423 makeLastStandard =
false;
427 case StateString2Start:
428 if (makeLastStandard)
430 makeLastStandard =
false;
435 if (makeLastStandard)
437 makeLastStandard =
false;
441 case StateString2End:
442 if (makeLastStandard)
444 makeLastStandard =
false;
449 if (makeLastStandard)
451 makeLastStandard =
false;
455 case StatePreProcessor:
456 if (makeLastStandard)
458 makeLastStandard =
false;
469 userData->setHasClosingCollapse(
false);
470 userData->setCollapseMode(TextBlockUserData::NoCollapse);
472 int collapse = Parenthesis::collapseAtPos(parentheses);
474 if (collapse == firstNonSpace)
475 TextEditDocumentLayout::userData(
currentBlock())->setCollapseMode(TextBlockUserData::CollapseThis);
477 TextEditDocumentLayout::userData(
currentBlock())->setCollapseMode(TextBlockUserData::CollapseAfter);
479 if (Parenthesis::hasClosingCollapse(parentheses)) {
480 TextEditDocumentLayout::userData(
currentBlock())->setHasClosingCollapse(
true);
492 case StateCCommentEnd1:
493 case StateCCommentStart2:
494 state = StateCComment;
501 state = StateStandard;
504 state = StateStandard;
507 state = StateStandard;
512 TextEditDocumentLayout::setParentheses(
currentBlock(), parentheses);
536 #endif // QT_NO_SYNTAXHIGHLIGHTER QBool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
bool isLetter() const
Returns true if the character is a letter (Letter_* categories); otherwise returns false...
void setFontItalic(bool italic)
If italic is true, sets the text format's font to be italic; otherwise the font will be non-italic...
The QTextCharFormat class provides formatting information for characters in a QTextDocument.
#define QT_END_NAMESPACE
This macro expands to.
const QChar at(int i) const
Returns the character at the given index position in the string.
int length() const
Returns the number of characters in this string.
QObjectUserData * userData(uint id) const
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void setFormat(int start, int count, const QTextCharFormat &format)
This function is applied to the syntax highlighter's current text block (i.e.
Q_OUTOFLINE_TEMPLATE RandomAccessIterator qBinaryFind(RandomAccessIterator begin, RandomAccessIterator end, const T &value)
QScriptSyntaxHighlighter(QTextDocument *document=0)
~QScriptSyntaxHighlighter()
The QString class provides a Unicode character string.
The QChar class provides a 16-bit Unicode character.
int previousBlockState() const
Returns the end state of the text block previous to the syntax highlighter's current block...
void reserve(int size)
Attempts to allocate memory for at least size characters.
KeywordHelper(const QString &word)
#define QT_BEGIN_NAMESPACE
This macro expands to.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
#define Q_STATIC_GLOBAL_OPERATOR
static bool isKeyword(const QString &word)
QTextBlock currentBlock() const
Returns the current text block.
void highlightWord(int currentPos, const QString &buffer)
bool isUpper() const
Returns true if the character is an uppercase letter, i.
char toAscii() const
Returns the character value of the QChar obtained using the current codec used to read C strings...
void setCurrentBlockState(int newState)
Sets the state of the current text block to newState.
void highlightBlock(const QString &text)
Highlights the given text block.
The QSyntaxHighlighter class allows you to define syntax highlighting rules, and in addition you can ...
static const char *const keywords[MAX_KEYWORD]
Q_STATIC_GLOBAL_OPERATOR bool operator<(const KeywordHelper &helper, const char *kw)
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...
void setForeground(const QBrush &brush)
Sets the foreground brush to the specified brush.
QTextCharFormat m_formats[NumScriptFormats]
QTextCharFormat format(int pos) const
Returns the format at position inside the syntax highlighter's current text block.
static const KeyPair *const end
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.