diff options
author | Jim Pattee <unknown> | 2016-10-21 10:04:19 +1100 |
---|---|---|
committer | Jim Pattee <unknown> | 2016-10-21 10:04:19 +1100 |
commit | b63e93d4c0b26fe00ecede031ed709e644b2a304 (patch) | |
tree | 93864d83c52d09e47d2cf5fe6315ea5165293109 | |
parent | 4801e9a23c1bd7102b408d5590664c7844c42b46 (diff) | |
download | scintilla-mirror-b63e93d4c0b26fe00ecede031ed709e644b2a304.tar.gz |
Bug [#1872]. Fix style of references and keywords when followed by a comment.
-rw-r--r-- | doc/ScintillaHistory.html | 4 | ||||
-rw-r--r-- | lexers/LexYAML.cxx | 76 |
2 files changed, 51 insertions, 29 deletions
diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index ad70afba9..a03c60e0c 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -527,6 +527,10 @@ JSON folder fixed where it didn't resume folding with the correct fold level. </li> <li> + YAML lexer fixed style of references and keywords when followed by a comment. + <a href="http://sourceforge.net/p/scintilla/bugs/1872/">Bug #1872</a>. + </li> + <li> Margin click to select line now clears rectangular and additional selections. </li> <li> diff --git a/lexers/LexYAML.cxx b/lexers/LexYAML.cxx index e420d9d79..08c957cb7 100644 --- a/lexers/LexYAML.cxx +++ b/lexers/LexYAML.cxx @@ -49,10 +49,25 @@ static unsigned int SpaceCount(char* lineBuffer) { return static_cast<unsigned int>(headBuffer - lineBuffer); } -#define YAML_STATE_BITSIZE 16 +static bool KeywordAtChar(char* lineBuffer, char* startComment, const WordList &keywords) { + if (lineBuffer == NULL || startComment <= lineBuffer) + return false; + char* endValue = startComment - 1; + while (endValue >= lineBuffer && *endValue == ' ') + endValue--; + Sci_PositionU len = endValue - lineBuffer + 1; + char s[100]; + if (len > (sizeof(s) / sizeof(s[0]) - 1)) + return false; + strncpy(s, lineBuffer, len); + s[len] = '\0'; + return (keywords.InList(s)); +} + +#define YAML_STATE_BITSIZE 16 #define YAML_STATE_MASK (0xFFFF0000) #define YAML_STATE_DOCUMENT (1 << YAML_STATE_BITSIZE) -#define YAML_STATE_VALUE (2 << YAML_STATE_BITSIZE) +#define YAML_STATE_VALUE (2 << YAML_STATE_BITSIZE) #define YAML_STATE_COMMENT (3 << YAML_STATE_BITSIZE) #define YAML_STATE_TEXT_PARENT (4 << YAML_STATE_BITSIZE) #define YAML_STATE_TEXT (5 << YAML_STATE_BITSIZE) @@ -139,41 +154,44 @@ static void ColouriseYAMLLine( styler.ColourTo(endPos, SCE_YAML_COMMENT); return; } + Sci_PositionU startComment = i; + bInQuotes = false; + while (startComment < lengthLine) { // Comment must be space padded + if (lineBuffer[startComment] == '\'' || lineBuffer[startComment] == '\"') + bInQuotes = !bInQuotes; + if (lineBuffer[startComment] == '#' && isspacechar(lineBuffer[startComment - 1]) && !bInQuotes) + break; + startComment++; + } styler.SetLineState(currentLine, YAML_STATE_VALUE); if (lineBuffer[i] == '&' || lineBuffer[i] == '*') { - styler.ColourTo(endPos, SCE_YAML_REFERENCE); + styler.ColourTo(startLine + startComment - 1, SCE_YAML_REFERENCE); + if (startComment < lengthLine) + styler.ColourTo(endPos, SCE_YAML_COMMENT); return; } - if (keywords.InList(&lineBuffer[i])) { // Convertible value (true/false, etc.) - styler.ColourTo(endPos, SCE_YAML_KEYWORD); + if (KeywordAtChar(&lineBuffer[i], &lineBuffer[startComment], keywords)) { // Convertible value (true/false, etc.) + styler.ColourTo(startLine + startComment - 1, SCE_YAML_KEYWORD); + if (startComment < lengthLine) + styler.ColourTo(endPos, SCE_YAML_COMMENT); return; - } else { - Sci_PositionU startComment = i; - bInQuotes = false; - while (startComment < lengthLine) { // Comment must be space padded - if (lineBuffer[startComment] == '\'' || lineBuffer[startComment] == '\"') - bInQuotes = !bInQuotes; - if (lineBuffer[startComment] == '#' && isspacechar(lineBuffer[startComment - 1]) && !bInQuotes) - break; - startComment++; - } - Sci_PositionU i2 = i; - while ((i < startComment) && lineBuffer[i]) { - if (!(IsASCII(lineBuffer[i]) && isdigit(lineBuffer[i])) && lineBuffer[i] != '-' - && lineBuffer[i] != '.' && lineBuffer[i] != ',' && lineBuffer[i] != ' ') { - styler.ColourTo(startLine + startComment - 1, SCE_YAML_DEFAULT); - if (startComment < lengthLine) - styler.ColourTo(endPos, SCE_YAML_COMMENT); - return; - } - i++; - } - if (i > i2) { - styler.ColourTo(startLine + startComment - 1, SCE_YAML_NUMBER); + } + Sci_PositionU i2 = i; + while ((i < startComment) && lineBuffer[i]) { + if (!(IsASCII(lineBuffer[i]) && isdigit(lineBuffer[i])) && lineBuffer[i] != '-' + && lineBuffer[i] != '.' && lineBuffer[i] != ',' && lineBuffer[i] != ' ') { + styler.ColourTo(startLine + startComment - 1, SCE_YAML_DEFAULT); if (startComment < lengthLine) styler.ColourTo(endPos, SCE_YAML_COMMENT); return; } + i++; + } + if (i > i2) { + styler.ColourTo(startLine + startComment - 1, SCE_YAML_NUMBER); + if (startComment < lengthLine) + styler.ColourTo(endPos, SCE_YAML_COMMENT); + return; } break; // shouldn't get here, but just in case, the rest of the line is coloured the default } @@ -255,7 +273,7 @@ static void FoldYAMLDoc(Sci_PositionU startPos, Sci_Position length, int /*initS if (lineNext <= docLines) { // Information about next line is only available if not at end of document indentNext = styler.IndentAmount(lineNext, &spaceFlags, NULL); - } + } const int comment = foldComment && IsCommentLine(lineCurrent, styler); const int comment_start = (comment && !prevComment && (lineNext <= docLines) && IsCommentLine(lineNext, styler) && (lev > SC_FOLDLEVELBASE)); |