Skip to content

Commit 637612b

Browse files
committed
Change the logic of compiler directives preprocessor to move line content to be processed by grammar istead of removing it #116
1 parent 90eab03 commit 637612b

File tree

3 files changed

+39
-28
lines changed

3 files changed

+39
-28
lines changed

com.ca.lsp.cobol/lsp-core-cobol-parser/src/main/java/com/ca/lsp/core/cobol/preprocessor/impl/CobolPreprocessorImpl.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
import com.ca.lsp.core.cobol.preprocessor.sub.line.rewriter.impl.CobolInlineCommentEntriesNormalizerImpl;
3434
import com.ca.lsp.core.cobol.preprocessor.sub.line.rewriter.impl.CobolLineIndicatorProcessorImpl;
3535
import com.ca.lsp.core.cobol.preprocessor.sub.line.transformer.CobolLinesTransformation;
36-
import com.ca.lsp.core.cobol.preprocessor.sub.line.transformer.CobolUnsupportedFeaturesIgnorerImpl;
36+
import com.ca.lsp.core.cobol.preprocessor.sub.line.transformer.CobolCompilerDirectives;
3737
import com.ca.lsp.core.cobol.preprocessor.sub.line.transformer.ContinuationLineTransformation;
3838
import com.ca.lsp.core.cobol.preprocessor.sub.line.writer.CobolLineWriter;
3939
import com.ca.lsp.core.cobol.preprocessor.sub.line.writer.impl.CobolLineWriterImpl;
@@ -140,7 +140,7 @@ private CobolLineIndicatorProcessor createLineIndicatorProcessor() {
140140
}
141141

142142
private CobolLinesTransformation createUnsupportedFeaturesProcessor() {
143-
return new CobolUnsupportedFeaturesIgnorerImpl(listener);
143+
return new CobolCompilerDirectives(listener);
144144
}
145145

146146
private CobolLinesTransformation createContinuationLineProcessor(String documentURI) {
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,37 @@
1313
*/
1414
package com.ca.lsp.core.cobol.preprocessor.sub.line.transformer;
1515

16+
import com.ca.lsp.core.cobol.parser.listener.PreprocessorListener;
17+
import com.ca.lsp.core.cobol.preprocessor.sub.CobolLine;
18+
1619
import java.util.List;
1720
import java.util.regex.Matcher;
1821
import java.util.regex.Pattern;
1922

20-
import com.ca.lsp.core.cobol.parser.listener.PreprocessorListener;
21-
import com.ca.lsp.core.cobol.preprocessor.sub.CobolLine;
22-
2323
/**
24-
* Preprocessor which removes lines that contains unsupported features
24+
* This preprocessor transforms the lines containing the compiler directives is order to make them
25+
* processable with grammar.
26+
*
27+
* The CBL (PROCESS) statement can be preceded by a sequence number in columns 1 through 6. The
28+
* first character of the sequence number must be numeric, and CBL or PROCESS can begin in column 8
29+
* or after; if a sequence number is not specified, CBL or PROCESS can begin in column 1 or after.
30+
*
31+
* The CBL (PROCESS) statement must end before or at column 72, and options cannot be continued
32+
* across multiple CBL (PROCESS) statements. However, you can use more than one CBL (PROCESS)
33+
* statement. Multiple CBL (PROCESS) statements must follow one another with no intervening
34+
* statements of any other type.
35+
*
36+
* The CBL (PROCESS) statement must be placed before any comment lines or other
37+
* compiler-directing statements.
2538
*/
26-
public class CobolUnsupportedFeaturesIgnorerImpl implements CobolLinesTransformation {
39+
public class CobolCompilerDirectives implements CobolLinesTransformation {
2740

2841
private static final Pattern COMPILER_DIRECTIVE_LINE =
29-
Pattern.compile("(\\d.{0,6} +|\\s*)(CBL|PROCESS) .+");
42+
Pattern.compile("(?i)(\\d.{0,6} +|\\s*)(CBL|PROCESS) .+");
3043

3144
private PreprocessorListener listener;
3245

33-
public CobolUnsupportedFeaturesIgnorerImpl(PreprocessorListener listener) {
46+
public CobolCompilerDirectives(PreprocessorListener listener) {
3447
this.listener = listener;
3548
}
3649

@@ -44,7 +57,10 @@ private List<CobolLine> removeLinesWithCompilerDirectives(List<CobolLine> lines)
4457
CobolLine line = lines.get(i);
4558
Matcher matcher = COMPILER_DIRECTIVE_LINE.matcher(line.toString());
4659
if (matcher.matches()) {
47-
lines.set(i, CobolLine.copyCobolLineWithEmptyContent(line));
60+
String content =
61+
line.serializeWithoutCommentArea().replaceAll("(?i)^.*(CBL|PROCESS)", " CBL");
62+
lines.set(i, CobolLine.copyCobolLineWithContentArea(content, line));
63+
4864
listener.unregisterError(i + 1);
4965
} else break;
5066
}

com.ca.lsp.cobol/lsp-service-cobol/src/test/java/com/ca/lsp/cobol/usecases/TestNoErrorOnCompilerDirectives.java

+13-18
Original file line numberDiff line numberDiff line change
@@ -45,30 +45,27 @@ public TestNoErrorOnCompilerDirectives() {
4545
super(null);
4646
}
4747

48-
private static final String CBL_WITHOUT_NUMBERS =
49-
" CBL DIR1,DIR2,DIR3,DIR4,DIR5,DIR6,DIR7,DIR8\r\n";
48+
private static final String CBL_WITHOUT_NUMBERS = " cbl LIB,QUOTE,NODYNAM,TEST(SEP)\r\n";
5049

51-
private static final String CBL_WITH_NUMBER =
52-
"012345 CBL DIR1,DIR2,DIR3,DIR4,DIR5,DIR6,DIR7,DIR8\r\n";
50+
private static final String CBL_WITH_NUMBER = "012345 CBL DATA(24),RMODE(24),NODYNAM\r\n";
5351

54-
private static final String PROCESS_WITHOUT_NUMBER =
55-
"PROCESS DIR1,DIR2,DIR3,DIR4,DIR5,DIR6,DIR7,DIR8\r\n";
52+
private static final String PROCESS_WITHOUT_NUMBER = "PROCESS DATA(24),RMODE(24),NODYNAM\r\n";
5653

57-
private static final String PROCESS_WITH_NUMBER =
58-
"012345 PROCESS DIR1,DIR2,DIR3,DIR4,DIR5,DIR6,DIR7,DIR8\r\n";
54+
private static final String PROCESS_WITH_NUMBER = "012345 PROCESS DATA(24),RMODE(24),NODYNAM\r\n";
5955

60-
private static final String PROCESS_WITHOUT_NUMBER_TYPO =
61-
"PROESS DIR1,DIR2,DIR3,DIR4,DIR5,DIR6,DIR7,DIR8\r\n";
56+
private static final String PROCESS_WITHOUT_NUMBER_TYPO = "PROESS DATA(24),RMODE(24),NODYNAM\r\n";
6257

6358
private static final String PROCESS_WITH_NUMBER_TYPO =
64-
"012345 PROESS DIR1,DIR2,DIR3,DIR4,DIR5,DIR6,DIR7,DIR8\r\n";
59+
"012345 PROESS DATA(24),RMODE(24),NODYNAM\r\n";
6560

6661
private static final String FOLLOWING_TEXT =
6762
"000000 Identification DIVISION. 23323232\r\n"
6863
+ "002800 Program-ID. 23323232\r\n"
6964
+ "002800 HELLOWORLD. 23323232\r\n"
7065
+ "024200 PROCEDURE DIVISION . CM1014.2\r\n";
7166

67+
private static final String COMMENT = " * Comment\r\n";
68+
7269
@Test
7370
public void testCorrectText() {
7471
setText("" + FOLLOWING_TEXT);
@@ -99,7 +96,6 @@ public void testProcessWithNumbers() {
9996
super.test();
10097
}
10198

102-
@Ignore("Feature is not yet supported")
10399
@Test
104100
public void testProcessWithoutNumbersWithTypo() {
105101
TestLanguageClient client =
@@ -109,11 +105,10 @@ public void testProcessWithoutNumbersWithTypo() {
109105

110106
Range range = retrieveRange(client);
111107

112-
assertEquals(1, range.getStart().getLine());
108+
assertEquals(0, range.getStart().getLine());
113109
assertEquals(7, range.getStart().getCharacter());
114110
}
115111

116-
@Ignore("Feature is not yet supported")
117112
@Test
118113
public void testProcessWithNumbersWithTypo() {
119114
TestLanguageClient client =
@@ -123,20 +118,20 @@ public void testProcessWithNumbersWithTypo() {
123118

124119
Range range = retrieveRange(client);
125120

126-
assertEquals(1, range.getStart().getLine());
121+
assertEquals(0, range.getStart().getLine());
127122
assertEquals(7, range.getStart().getCharacter());
128123
}
129124

130-
@Ignore("Feature is not yet supported")
125+
@Ignore("Not yet implemented")
131126
@Test
132127
public void testLinesBeforeCblNotAllowed() {
133-
TestLanguageClient client = startServerAndRunValidation(FOLLOWING_TEXT + CBL_WITH_NUMBER);
128+
TestLanguageClient client = startServerAndRunValidation(COMMENT + CBL_WITH_NUMBER);
134129

135130
waitForDiagnostics(client);
136131

137132
Range range = retrieveRange(client);
138133

139-
assertEquals(4, range.getStart().getLine());
134+
assertEquals(1, range.getStart().getLine());
140135
assertEquals(7, range.getStart().getCharacter());
141136
}
142137

0 commit comments

Comments
 (0)