diff --git a/lexers/LexCOBOL.cxx b/lexers/LexCOBOL.cxx index c52f0c27a..baa2ebfb1 100644 --- a/lexers/LexCOBOL.cxx +++ b/lexers/LexCOBOL.cxx @@ -38,38 +38,34 @@ using namespace Lexilla; #define IN_FLAGS 0xF #define NOT_HEADER 0x10 -inline bool isCOBOLoperator(char ch) - { +inline bool isCOBOLoperator(char ch) { return isoperator(ch); - } +} -inline bool isCOBOLwordchar(char ch) - { +inline bool isCOBOLwordchar(char ch) { return IsASCII(ch) && (isalnum(ch) || ch == '-'); - } +} -inline bool isCOBOLwordstart(char ch) - { +inline bool isCOBOLwordstart(char ch) { return IsASCII(ch) && isalnum(ch); - } +} -static int CountBits(int nBits) - { +static int CountBits(int nBits) { int count = 0; for (int i = 0; i < 32; ++i) - { + { count += nBits & 1; nBits >>= 1; - } - return count; } + return count; +} static void getRange(Sci_PositionU start, - Sci_PositionU end, - Accessor &styler, - char *s, - Sci_PositionU len) { + Sci_PositionU end, + Accessor &styler, + char *s, + Sci_PositionU len) { Sci_PositionU i = 0; while ((i < end - start + 1) && (i < len-1)) { s[i] = static_cast(tolower(styler[start + i])); @@ -144,7 +140,7 @@ static int classifyWordCOBOL(Sci_PositionU start, Sci_PositionU end, /*WordList } static void ColouriseCOBOLDoc(Sci_PositionU startPos, Sci_Position length, int initStyle, WordList *keywordlists[], - Accessor &styler) { + Accessor &styler) { styler.StartAt(startPos); @@ -209,39 +205,43 @@ static void ColouriseCOBOLDoc(Sci_PositionU startPos, Sci_Position length, int i if (state == SCE_C_DEFAULT) { if (isCOBOLwordstart(ch) || (ch == '$' && IsASCII(chNext) && isalpha(chNext))) { - ColourTo(styler, i-1, state); + ColourTo(styler, i - 1, state); state = SCE_C_IDENTIFIER; } else if (column == 6 && (ch == '*' || ch == '/')) { - // Cobol comment line: asterisk in column 7. - ColourTo(styler, i-1, state); + // Cobol comment line: asterisk in column 7. + ColourTo(styler, i - 1, state); state = SCE_C_COMMENTLINE; } else if (ch == '*' && chNext == '>') { - // Cobol inline comment: asterisk, followed by greater than. - ColourTo(styler, i-1, state); + // Cobol inline comment: asterisk, followed by greater than. + ColourTo(styler, i - 1, state); state = SCE_C_COMMENTLINE; } else if (column == 0 && ch == '*' && chNext != '*') { - ColourTo(styler, i-1, state); + ColourTo(styler, i - 1, state); state = SCE_C_COMMENTLINE; } else if (column == 0 && ch == '/' && chNext != '*') { - ColourTo(styler, i-1, state); + ColourTo(styler, i - 1, state); state = SCE_C_COMMENTLINE; } else if (column == 0 && ch == '*' && chNext == '*') { - ColourTo(styler, i-1, state); + ColourTo(styler, i - 1, state); state = SCE_C_COMMENTDOC; } else if (column == 0 && ch == '/' && chNext == '*') { - ColourTo(styler, i-1, state); + ColourTo(styler, i - 1, state); state = SCE_C_COMMENTDOC; } else if (ch == '"') { - ColourTo(styler, i-1, state); + ColourTo(styler, i - 1, state); state = SCE_C_STRING; } else if (ch == '\'') { - ColourTo(styler, i-1, state); + ColourTo(styler, i - 1, state); state = SCE_C_CHARACTER; } else if (ch == '?' && column == 0) { - ColourTo(styler, i-1, state); + ColourTo(styler, i - 1, state); state = SCE_C_PREPROCESSOR; + // eod of paragraph terminator + } else if (ch == '.' && (chNext == ' ' || chNext == '\r' || chNext == '\n')) { + ColourTo(styler, i - 1, state); + ColourTo(styler, i, SCE_C_STRINGEOL); } else if (isCOBOLoperator(ch)) { - ColourTo(styler, i-1, state); + ColourTo(styler, i - 1, state); ColourTo(styler, i, SCE_C_OPERATOR); } } else if (state == SCE_C_IDENTIFIER) { @@ -261,6 +261,10 @@ static void ColouriseCOBOLDoc(Sci_PositionU startPos, Sci_Position length, int i state = SCE_C_STRING; } else if (ch == '\'') { state = SCE_C_CHARACTER; + // eod of paragraph terminator + } else if (ch == '.' && (chNext == ' ' || chNext == '\r' || chNext == '\n')) { + ColourTo(styler, i - 1, state); + ColourTo(styler, i, SCE_C_STRINGEOL); } else if (isCOBOLoperator(ch)) { ColourTo(styler, i, SCE_C_OPERATOR); } @@ -268,26 +272,30 @@ static void ColouriseCOBOLDoc(Sci_PositionU startPos, Sci_Position length, int i } else { if (state == SCE_C_PREPROCESSOR) { if ((ch == '\r' || ch == '\n') && !(chPrev == '\\' || chPrev == '\r')) { - ColourTo(styler, i-1, state); + ColourTo(styler, i - 1, state); state = SCE_C_DEFAULT; + // eod of paragraph terminator + } else if (ch == '.' && (chNext == ' ' || chNext == '\r' || chNext == '\n')) { + ColourTo(styler, i - 1, state); + ColourTo(styler, i, SCE_C_STRINGEOL); } } else if (state == SCE_C_COMMENT) { if (ch == '\r' || ch == '\n') { - ColourTo(styler, i-1, state); + ColourTo(styler, i - 1, state); state = SCE_C_DEFAULT; } } else if (state == SCE_C_COMMENTDOC) { if (ch == '\r' || ch == '\n') { if (((i > styler.GetStartSegment() + 2) || ( - (initStyle == SCE_C_COMMENTDOC) && - (styler.GetStartSegment() == static_cast(startPos))))) { - ColourTo(styler, i-1, state); - state = SCE_C_DEFAULT; + (initStyle == SCE_C_COMMENTDOC) && + (styler.GetStartSegment() == static_cast(startPos))))) { + ColourTo(styler, i - 1, state); + state = SCE_C_DEFAULT; } } } else if (state == SCE_C_COMMENTLINE) { if (ch == '\r' || ch == '\n') { - ColourTo(styler, i-1, state); + ColourTo(styler, i - 1, state); state = SCE_C_DEFAULT; } } else if (state == SCE_C_STRING) { @@ -295,7 +303,7 @@ static void ColouriseCOBOLDoc(Sci_PositionU startPos, Sci_Position length, int i ColourTo(styler, i, state); state = SCE_C_DEFAULT; } else if (ch == '\r' || ch == '\n') { - ColourTo(styler, i-1, state); + ColourTo(styler, i - 1, state); state = SCE_C_DEFAULT; } } else if (state == SCE_C_CHARACTER) { @@ -308,15 +316,15 @@ static void ColouriseCOBOLDoc(Sci_PositionU startPos, Sci_Position length, int i chPrev = ch; bNewLine = bSetNewLine; if (bNewLine) - { + { bAarea = false; - } + } } ColourTo(styler, lengthDoc - 1, state); } static void FoldCOBOLDoc(Sci_PositionU startPos, Sci_Position length, int, WordList *[], - Accessor &styler) { + Accessor &styler) { bool foldCompact = styler.GetPropertyInt("fold.compact", 1) != 0; Sci_PositionU endPos = startPos + length; int visibleChars = 0; @@ -384,4 +392,4 @@ static const char * const COBOLWordListDesc[] = { 0 }; -extern const LexerModule lmCOBOL(SCLEX_COBOL, ColouriseCOBOLDoc, "COBOL", FoldCOBOLDoc, COBOLWordListDesc); +extern const LexerModule lmCOBOL(SCLEX_COBOL, ColouriseCOBOLDoc, "COBOL", FoldCOBOLDoc, COBOLWordListDesc); \ No newline at end of file diff --git a/test/examples/cobol/AllStyles.cob b/test/examples/cobol/AllStyles.cob index 412aa1713..65beb3d3f 100644 --- a/test/examples/cobol/AllStyles.cob +++ b/test/examples/cobol/AllStyles.cob @@ -1,4 +1,4 @@ - * Enumerate all styles: 0, 2 to 11, 16 + * Enumerate all styles: 0, 2 to 12, 16 * SCE_C_COMMENTLINE=2 * SCE_C_DEFAULT=0 @@ -33,3 +33,6 @@ * SCE_C_OPERATOR=10 + + + * SCE_C_STRINGEOL=12 + . diff --git a/test/examples/cobol/AllStyles.cob.folded b/test/examples/cobol/AllStyles.cob.folded index 08efc3400..145e735d4 100644 --- a/test/examples/cobol/AllStyles.cob.folded +++ b/test/examples/cobol/AllStyles.cob.folded @@ -1,4 +1,4 @@ - 0 400 0 * Enumerate all styles: 0, 2 to 11, 16 + 0 400 0 * Enumerate all styles: 0, 2 to 12, 16 0 400 0 * SCE_C_COMMENTLINE=2 0 400 0 0 400 0 * SCE_C_DEFAULT=0 @@ -33,4 +33,7 @@ 0 400 0 0 400 0 * SCE_C_OPERATOR=10 0 400 0 + + 0 400 0 + 0 400 0 * SCE_C_STRINGEOL=12 + 0 400 0 . 0 400 0 \ No newline at end of file diff --git a/test/examples/cobol/AllStyles.cob.styled b/test/examples/cobol/AllStyles.cob.styled index 187950e0e..90d278ff1 100644 --- a/test/examples/cobol/AllStyles.cob.styled +++ b/test/examples/cobol/AllStyles.cob.styled @@ -1,4 +1,4 @@ -{0} {2}* Enumerate all styles: 0, 2 to 11, 16{0} +{0} {2}* Enumerate all styles: 0, 2 to 12, 16{0} {2}* SCE_C_COMMENTLINE=2{0} {2}* SCE_C_DEFAULT=0{0} @@ -33,3 +33,6 @@ {2}* SCE_C_OPERATOR=10{0} {10}+{0} + + {2}* SCE_C_STRINGEOL=12{0} + {12}.{0}