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 syntax and wrap strings #229
Comments
Not sure if your display is right. "AND" plus "TO" are keywords and shown in blue. But in this context, it is part of the text string, and should be in same color as first / previous line, all of that line in purple. Last line is again treated as text value. |
I'm not a COBOL programmer though some searching gave me some hints. IMO with this issue, end the string at newline so the style does not continue into the next line. The next continued line will be ok. I looked at some other issues to build a house of cards and see if the house topples over. Seems ok. diff --git a/lexers/LexCOBOL.cxx b/lexers/LexCOBOL.cxx
index 39682f55..a93955f0 100644
--- a/lexers/LexCOBOL.cxx
+++ b/lexers/LexCOBOL.cxx
@@ -95,7 +95,7 @@ static int classifyWordCOBOL(Sci_PositionU start, Sci_PositionU end, /*WordList
s[1] = '\0';
getRange(start, end, styler, s, sizeof(s));
- char chAttr = SCE_C_IDENTIFIER;
+ int chAttr = SCE_C_IDENTIFIER;
if (isdigit(s[0]) || (s[0] == '.') || (s[0] == 'v')) {
chAttr = SCE_C_NUMBER;
char *p = s + 1;
@@ -107,7 +107,7 @@ static int classifyWordCOBOL(Sci_PositionU start, Sci_PositionU end, /*WordList
++p;
}
}
- else {
+ if (chAttr == SCE_C_IDENTIFIER) {
if (a_keywords.InList(s)) {
chAttr = SCE_C_WORD;
}
@@ -211,7 +211,7 @@ static void ColouriseCOBOLDoc(Sci_PositionU startPos, Sci_Position length, int i
if (isCOBOLwordstart(ch) || (ch == '$' && IsASCII(chNext) && isalpha(chNext))) {
ColourTo(styler, i-1, state);
state = SCE_C_IDENTIFIER;
- } else if (column == 6 && ch == '*') {
+ } else if (column == 6 && (ch == '*' || ch == '/')) {
// Cobol comment line: asterisk in column 7.
ColourTo(styler, i-1, state);
state = SCE_C_COMMENTLINE;
@@ -255,7 +255,9 @@ static void ColouriseCOBOLDoc(Sci_PositionU startPos, Sci_Position length, int i
state = SCE_C_DEFAULT;
chNext = styler.SafeGetCharAt(i + 1);
- if (ch == '"') {
+ if (column == 6 && (ch == '*' || ch == '/')) {
+ state = SCE_C_COMMENTLINE;
+ } else if (ch == '"') {
state = SCE_C_STRING;
} else if (ch == '\'') {
state = SCE_C_CHARACTER;
@@ -292,6 +294,9 @@ static void ColouriseCOBOLDoc(Sci_PositionU startPos, Sci_Position length, int i
if (ch == '"') {
ColourTo(styler, i, state);
state = SCE_C_DEFAULT;
+ } else if (ch == '\r' || ch == '\n') {
+ ColourTo(styler, i-1, state);
+ state = SCE_C_DEFAULT;
}
} else if (state == SCE_C_CHARACTER) {
if (ch == '\'') {
I could split up the fixes into individual fixes if preferred, if the code is regarded as ok as I'm not experienced with COBOL. The folding is off in SciTE.properties as testlexers.exe would crash (Exception Code: 40000015) with the cobol test file (original or patched lexer). IDK why, maybe fold code has issue or the GCC compiler is at fault. Folding works in compiled Sc1. Just noticed, test file should state that |
It makes future maintenance easier when the purpose and scope of each fix can be seen in separate commits. I added a basic test file with a86f236. |
@nyamatongwe thanks, I have pulled down the changes. I will break the fixes up so can be committed separately. Should be able to start with this issue first. I will create an issue for keywords starting with I am not aware of any other COBOL lexer issues so hopefully will all be good. Oh, except for the folding crash by TestLexers.exe, still IDK. Fix for only this issue: |
I found another with |
I have done nothing with I see it
The CR is before Line tested to update to Line 282 in a86f236
The |
Committed the changes.
There are several indications of a dialect such as a '?' in column 1 indicating pre-processor. This lexer arrived with lexers for TAL and TACL languages associated with Tandem computers. |
I cannot validate In my previous comment ended with:
Correction... I should have specified
Line 274 in 70dff47
|
Added 2a90020 to style both \r and \n the same for Also fixed up indentation to only use spaces with b729628 and fixed some Cppcheck scope can be decreased warnings with 4af9e3e. |
Sorry, I found another issue with comments on COBOL, sorry for realizing it last week.
A star / asterisk in column 7 indicates that whatever is in the line is all commented. If there are something in column 1 to 5 it is treated correctly. However, when column 6 also got any text in it, then the line is not treated as a comment. |
See #231. |
Thank you, #229 Tested and works as expected. |
COBOL allows long text variables to be split over two or more lines. Note, this is not related to how Notepad++ wrap lines.
Example
It uses a “-” sign in column 7 to indicate a continuation. Note that the first line does not end with a quote to indicate end of the string. COBOL will take all the text up and including column 72 and concatenate that with the rest from the following line. There is no rule on where the opening quote on the second line should be. Also this can extend to a third line or more, although that is not very common, example
In COBOL column 1 to 6 is line numbers or can be used to mark changes. It is ignored during compile time.
Notepad++ get confused from the continuation and will show all the following lines as part of the string.
The text was updated successfully, but these errors were encountered: