Skip to content

Commit 478f377

Browse files
committed
fix: show no error for inline comment with just comment tag
Signed-off-by: Aman Prashant <[email protected]>
1 parent 26d02ab commit 478f377

File tree

3 files changed

+54
-4
lines changed

3 files changed

+54
-4
lines changed

server/engine/src/main/antlr4/org/eclipse/lsp/cobol/core/parser/TechnicalLexer.g4

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ ASTERISKCHAR : '*';
2323
DOUBLEASTERISKCHAR : '**';
2424
COLONCHAR : ':';
2525
COMMACHAR : ',';
26-
COMMENTTAG : '*>';
26+
COMMENTTAG : '*>' -> channel(COMMENTS);
2727
DOLLARCHAR : '$';
2828
DOUBLEQUOTE : '"';
2929
DOUBLEEQUALCHAR : '==';
@@ -77,7 +77,7 @@ HEX_NUMBERS : HEXNUMBER;
7777

7878
// whitespace, line breaks, comments, ...
7979
NEWLINE : '\r'? '\n' -> channel(HIDDEN);
80-
COMMENTLINE : COMMENTTAG WS ~('\n' | '\r')* -> channel(COMMENTS);
80+
COMMENTLINE : COMMENTTAG ~('\n' | '\r')* -> channel(COMMENTS);
8181
WS : [ \t\f]+ -> channel(HIDDEN);
8282
COMPILERLINE : DOUBLEMORETHANCHAR ~('\n' | '\r')* -> channel(HIDDEN);
8383

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (c) 2023 Broadcom.
3+
* The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
4+
*
5+
* This program and the accompanying materials are made
6+
* available under the terms of the Eclipse Public License 2.0
7+
* which is available at https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* Broadcom, Inc. - initial API and implementation
13+
*
14+
*/
15+
16+
package org.eclipse.lsp.cobol.usecases;
17+
18+
import com.google.common.collect.ImmutableList;
19+
import com.google.common.collect.ImmutableMap;
20+
import org.eclipse.lsp.cobol.test.engine.UseCaseEngine;
21+
import org.junit.jupiter.api.Test;
22+
23+
/** Tests inline comment with just the comment tag doesn't throw error. */
24+
public class TestInlineCommentWithOnlyCommentTag {
25+
private static final String TEXT =
26+
" IDENTIFICATION DIVISION.\n"
27+
+ " PROGRAM-ID. TEST1.\n"
28+
+ " DATA DIVISION.\n"
29+
+ " WORKING-STORAGE SECTION. *>\n"
30+
+ " 77 {$*VARNAME} USAGE INDEX.\n"
31+
+ " PROCEDURE DIVISION.\n";
32+
33+
private static final String TEXT2 =
34+
" IDENTIFICATION DIVISION.\n"
35+
+ " PROGRAM-ID. TEST1.\n"
36+
+ " DATA DIVISION.\n"
37+
+ " WORKING-STORAGE SECTION. *>no space after tag\n"
38+
+ " 77 {$*VARNAME} USAGE INDEX.\n"
39+
+ " PROCEDURE DIVISION.\n";
40+
41+
@Test
42+
void testNoErrorWhenCommentTagNotFollowedByText() {
43+
UseCaseEngine.runTest(TEXT, ImmutableList.of(), ImmutableMap.of());
44+
}
45+
46+
@Test
47+
void testNoErrorWhenCommentTagisFollowedByTextWithoutSpace() {
48+
UseCaseEngine.runTest(TEXT2, ImmutableList.of(), ImmutableMap.of());
49+
}
50+
}

server/parser/src/main/antlr4/org/eclipse/lsp/cobol/core/parser/TechnicalLexer.g4

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ ASTERISKCHAR : '*';
2323
DOUBLEASTERISKCHAR : '**';
2424
COLONCHAR : ':';
2525
COMMACHAR : ',';
26-
COMMENTTAG : '*>';
26+
COMMENTTAG : '*>' -> channel(COMMENTS);
2727
DOLLARCHAR : '$';
2828
DOUBLEMORETHANCHAR : '>>';
2929

@@ -65,7 +65,7 @@ HEX_NUMBERS : HEXNUMBER;
6565

6666
// whitespace, line breaks, comments, ...
6767
NEWLINE : '\r'? '\n' -> channel(HIDDEN);
68-
COMMENTLINE : COMMENTTAG WS ~('\n' | '\r')* -> channel(COMMENTS);
68+
COMMENTLINE : COMMENTTAG ~('\n' | '\r')* -> channel(COMMENTS);
6969
WS : [ \t\f]+ -> channel(HIDDEN);
7070
COMPILERLINE : DOUBLEMORETHANCHAR ~('\n' | '\r')* -> channel(HIDDEN);
7171

0 commit comments

Comments
 (0)