Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cobol lexer eol #284

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 52 additions & 44 deletions lexers/LexCOBOL.cxx
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry about the whitespace changes on the first commit! Recommend hiding whitespace to see the actual code changes for this styling on this one commit. The next commits clean up whitespace issues so you can turn on view whitespace to review those commits

Original file line number Diff line number Diff line change
Expand Up @@ -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<char>(tolower(styler[start + i]));
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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) {
Expand All @@ -261,41 +261,49 @@ 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);
}
}
} 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<Sci_PositionU>(startPos))))) {
ColourTo(styler, i-1, state);
state = SCE_C_DEFAULT;
(initStyle == SCE_C_COMMENTDOC) &&
(styler.GetStartSegment() == static_cast<Sci_PositionU>(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) {
if (ch == '"') {
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) {
Expand All @@ -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;
Expand Down Expand Up @@ -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);
5 changes: 4 additions & 1 deletion test/examples/cobol/AllStyles.cob
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -33,3 +33,6 @@

* SCE_C_OPERATOR=10
+

* SCE_C_STRINGEOL=12
.
5 changes: 4 additions & 1 deletion test/examples/cobol/AllStyles.cob.folded
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
5 changes: 4 additions & 1 deletion test/examples/cobol/AllStyles.cob.styled
Original file line number Diff line number Diff line change
@@ -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}
Expand Down Expand Up @@ -33,3 +33,6 @@

{2}* SCE_C_OPERATOR=10{0}
{10}+{0}

{2}* SCE_C_STRINGEOL=12{0}
{12}.{0}