diff options
author | Neil <nyamatongwe@gmail.com> | 2014-04-03 11:33:39 +1100 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2014-04-03 11:33:39 +1100 |
commit | 6c0a10ab46985f928778700524e0ba6c6974a976 (patch) | |
tree | e47554a9b13a1efa90598c0c839da0e5f5d1f9f4 /lexers/LexCPP.cxx | |
parent | 7cfe73301530d1ea6b803fa3d6691464f35f2da7 (diff) | |
download | scintilla-mirror-6c0a10ab46985f928778700524e0ba6c6974a976.tar.gz |
C++ lexer can highlight task marker keywords in comments as SCE_C_TASKMARKER.
From nkmathew.
Diffstat (limited to 'lexers/LexCPP.cxx')
-rw-r--r-- | lexers/LexCPP.cxx | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/lexers/LexCPP.cxx b/lexers/LexCPP.cxx index 76a47e058..a78e72e2b 100644 --- a/lexers/LexCPP.cxx +++ b/lexers/LexCPP.cxx @@ -83,6 +83,30 @@ static bool followsReturnKeyword(StyleContext &sc, LexAccessor &styler) { return !*s; } +static void highlightTaskMarker(StyleContext &sc, LexAccessor &styler, + int activity, WordList &markerList, bool caseSensitive){ + if ((isoperator(sc.chPrev) || IsASpace(sc.chPrev)) && markerList.Length()) { + char marker[50]; + int currPos = (int) sc.currentPos; + int i = 0; + while (i < 50) { + char ch = styler.SafeGetCharAt(currPos + i); + if (IsASpace(ch) || isoperator(ch)) { + break; + } + if (caseSensitive) + marker[i] = ch; + else + marker[i] = tolower(ch); + i++; + } + marker[i] = '\0'; + if (markerList.InList(marker)) { + sc.SetState(SCE_C_TASKMARKER|activity); + } + } +} + static std::string GetRestOfLine(LexAccessor &styler, int start, bool allowSpace) { std::string restOfLine; int i =0; @@ -249,6 +273,7 @@ static const char *const cppWordLists[] = { "Documentation comment keywords", "Global classes and typedefs", "Preprocessor definitions", + "Task marker and error marker keywords", 0, }; @@ -328,6 +353,7 @@ class LexerCPP : public ILexerWithSubStyles { WordList keywords3; WordList keywords4; WordList ppDefinitions; + WordList markerList; std::map<std::string, std::string> preprocessorDefinitionsStart; OptionsCPP options; OptionSetCPP osCPP; @@ -452,6 +478,9 @@ int SCI_METHOD LexerCPP::WordListSet(int n, const char *wl) { case 4: wordListN = &ppDefinitions; break; + case 5: + wordListN = &markerList; + break; } int firstModification = -1; if (wordListN) { @@ -511,6 +540,7 @@ void SCI_METHOD LexerCPP::Lex(unsigned int startPos, int length, int initStyle, int visibleChars = 0; bool lastWordWasUUID = false; int styleBeforeDCKeyword = SCE_C_DEFAULT; + int styleBeforeTaskMarker = SCE_C_DEFAULT; bool continuationLine = false; bool isIncludePreprocessor = false; bool isStringInPreprocessor = false; @@ -725,6 +755,9 @@ void SCI_METHOD LexerCPP::Lex(unsigned int startPos, int length, int initStyle, if (sc.Match('*', '/')) { sc.Forward(); sc.ForwardSetState(SCE_C_DEFAULT|activitySet); + } else { + styleBeforeTaskMarker = SCE_C_COMMENT; + highlightTaskMarker(sc, styler, activitySet, markerList, caseSensitive); } break; case SCE_C_COMMENTDOC: @@ -742,6 +775,9 @@ void SCI_METHOD LexerCPP::Lex(unsigned int startPos, int length, int initStyle, case SCE_C_COMMENTLINE: if (sc.atLineStart && !continuationLine) { sc.SetState(SCE_C_DEFAULT|activitySet); + } else { + styleBeforeTaskMarker = SCE_C_COMMENTLINE; + highlightTaskMarker(sc, styler, activitySet, markerList, caseSensitive); } break; case SCE_C_COMMENTLINEDOC: @@ -880,6 +916,12 @@ void SCI_METHOD LexerCPP::Lex(unsigned int startPos, int length, int initStyle, if (sc.atLineEnd || sc.ch == ')') { sc.SetState(SCE_C_DEFAULT|activitySet); } + break; + case SCE_C_TASKMARKER: + if (isoperator(sc.ch) || IsASpace(sc.ch)) { + sc.SetState(styleBeforeTaskMarker|activitySet); + styleBeforeTaskMarker = SCE_C_DEFAULT; + } } if (sc.atLineEnd && !atLineEndBeforeSwitch) { |