Skip to content

Commit 481688f

Browse files
committed
fix: inline comments shouldn't be analysed while preprocessing
Signed-off-by: Aman Prashant <[email protected]>
1 parent f1abef6 commit 481688f

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

server/engine/src/main/java/org/eclipse/lsp/cobol/core/preprocessor/delegates/rewriter/CobolLineIndicatorProcessorImpl.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class CobolLineIndicatorProcessorImpl implements CobolLineReWriter {
3838
private static final String EMPTY_STRING = "";
3939
private static final String DOUBLE_QUOTE_LITERAL = "\"([^\"]|\"\"|'')*+\"";
4040
private static final String SINGLE_QUOTE_LITERAL = "'([^']|''|\"\")*+'";
41-
private static final Pattern FLOATING_COMMENT_LINE =
41+
public static final Pattern FLOATING_COMMENT_LINE =
4242
Pattern.compile("(?<validText>.*?)(?<floatingComment>\\*> .+)?");
4343

4444
/**

server/engine/src/main/java/org/eclipse/lsp/cobol/core/preprocessor/delegates/transformer/ContinuationLineTransformation.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@
3232
import java.util.ArrayList;
3333
import java.util.List;
3434
import java.util.Objects;
35+
import java.util.regex.Matcher;
3536
import java.util.regex.Pattern;
3637
import java.util.stream.Stream;
3738

3839
import static java.util.Optional.ofNullable;
3940
import static org.eclipse.lsp.cobol.common.error.ErrorSeverity.ERROR;
41+
import static org.eclipse.lsp.cobol.core.preprocessor.delegates.rewriter.CobolLineIndicatorProcessorImpl.FLOATING_COMMENT_LINE;
4042

4143
/**
4244
* Process continuation lines. Any sentence, entry, clause, or phrase that requires more than one
@@ -60,7 +62,8 @@ public ContinuationLineTransformation(MessageService messageService) {
6062
}
6163

6264
@Override
63-
public ResultWithErrors<List<CobolLine>> transformLines(
65+
public ResultWithErrors<List<CobolLine>>
66+
transformLines(
6467
String documentURI, List<CobolLine> lines) {
6568
List<CobolLine> result = new ArrayList<>();
6669
List<SyntaxError> errors = new ArrayList<>();
@@ -212,7 +215,10 @@ private boolean checkIfLineHasUnclosedString(CobolLine cobolLine) {
212215
return false;
213216
}
214217

215-
String cobolLineToCheck = cobolLine.getContentAreaA() + cobolLine.getContentAreaB();
218+
Matcher floatingCommentMatcher = FLOATING_COMMENT_LINE.matcher(cobolLine.getContentArea());
219+
String cobolLineToCheck = floatingCommentMatcher.matches()
220+
? floatingCommentMatcher.group("validText")
221+
: cobolLine.getContentArea();
216222
String startChar = findQuoteOpeningChar(cobolLineToCheck);
217223

218224
if (startChar == null) return false;

server/engine/src/test/java/org/eclipse/lsp/cobol/usecases/TestInlineCommentWithOnlyCommentTag.java

+15
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ public class TestInlineCommentWithOnlyCommentTag {
3838
+ " 77 {$*VARNAME} USAGE INDEX.\n"
3939
+ " PROCEDURE DIVISION.\n";
4040

41+
public static final String TEXT3 =
42+
" IDENTIFICATION DIVISION.\n"
43+
+ " PROGRAM-ID. MIN.\n"
44+
+ " DATA DIVISION.\n"
45+
+ " WORKING-STORAGE SECTION.\n"
46+
+ " 01 {$*ABC} PIC X. \n"
47+
+ " PROCEDURE DIVISION. \n"
48+
+ " DISPLAY \"TEST IN PROGRESS\" *> COMMENT '\n"
49+
+ " ADD 0 TO {$ABC}.\n";
50+
4151
@Test
4252
void testNoErrorWhenCommentTagNotFollowedByText() {
4353
UseCaseEngine.runTest(TEXT, ImmutableList.of(), ImmutableMap.of());
@@ -47,4 +57,9 @@ void testNoErrorWhenCommentTagNotFollowedByText() {
4757
void testNoErrorWhenCommentTagisFollowedByTextWithoutSpace() {
4858
UseCaseEngine.runTest(TEXT2, ImmutableList.of(), ImmutableMap.of());
4959
}
60+
61+
@Test
62+
void testFloatingCommentDoNotFlagErrorWhenCommentsHaveUnBalancedQuotes() {
63+
UseCaseEngine.runTest(TEXT3, ImmutableList.of(), ImmutableMap.of());
64+
}
5065
}

0 commit comments

Comments
 (0)