Skip to content

Commit 274ce6d

Browse files
committed
fix: all tokens are passed and matched for embedded language (CICS and SQL)
Signed-off-by: Aman Prashant <[email protected]>
1 parent f8e4f54 commit 274ce6d

File tree

7 files changed

+90
-11
lines changed

7 files changed

+90
-11
lines changed

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

-1
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,6 @@ GETMAIN : G E T M A I N;
300300
GETNEXT : G E T N E X T;
301301
GMMI : G M M I;
302302
GROUPID : G R O U P I D;
303-
GTEC : G T E C;
304303
GTEQ : G T E Q;
305304
HANDLE : H A N D L E;
306305
HEAD : H E A D;

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
parser grammar CICSParser;
1515
options {tokenVocab = CICSLexer; superClass = MessageServiceParser;}
1616

17-
allCicsRules: cics_send | cics_receive | cics_add | cics_address | cics_allocate | cics_asktime | cics_assign | cics_bif |
17+
allCicsRules: (cics_send | cics_receive | cics_add | cics_address | cics_allocate | cics_asktime | cics_assign | cics_bif |
1818
cics_build | cics_cancel | cics_change | cics_change_task | cics_check | cics_connect | cics_converttime |
1919
cics_define | cics_delay | cics_delete | cics_deleteq | cics_deq | cics_document | cics_dump | cics_endbr |
2020
cics_endbrowse | cics_enq | cics_enter | cics_extract | cics_force | cics_formattime | cics_free |
@@ -26,7 +26,7 @@ allCicsRules: cics_send | cics_receive | cics_add | cics_address | cics_allocate
2626
cics_soapfault | cics_spoolclose | cics_spoolopen | cics_spoolread | cics_spoolwrite | cics_start |
2727
cics_startbr | cics_startbrowse | cics_suspend | cics_syncpoint | cics_test | cics_transform | cics_unlock |
2828
cics_update | cics_verify | cics_wait | cics_waitcics | cics_web | cics_write | cics_writeq | cics_wsacontext |
29-
cics_wsaepr | cics_xctl | cics_converse | cics_abend | cics_acquire | cics_exci_link
29+
cics_wsaepr | cics_xctl | cics_converse | cics_abend | cics_acquire | cics_exci_link) EOF
3030
;
3131

3232
/** RECEIVE: */
@@ -550,7 +550,7 @@ cics_query_security: SECURITY (RESTYPE cics_data_value | RESCLASS cics_data_valu
550550
cics_read: READ (cics_file_name | UNCOMMITTED | CONSISTENT | REPEATABLE | UPDATE | TOKEN cics_data_area |
551551
INTO cics_data_area | SET cics_ref | RIDFLD cics_data_area | KEYLENGTH cics_data_value | GENERIC |
552552
SYSID cics_data_area LENGTH cics_data_area | LENGTH cics_data_area | DEBKEY | DEBREC | RBA | RBN |
553-
XRBA | EQUAL | GTEC | NOSUSPEND | cics_resp)+;
553+
XRBA | EQUAL | GTEQ | NOSUSPEND | cics_resp)+;
554554

555555
/** READNEXT | READPREV*/
556556
cics_readnext: (READNEXT | READPREV | cics_file_name | cics_into | UNCOMMITTED | CONSISTENT | REPETABLE |
@@ -817,7 +817,7 @@ cics_write_reply: REPLY cics_data_area (MAXLENGTH cics_data_value | REPLYLENGTH
817817

818818
/** WRITEQ TD/TS */
819819
cics_writeq: WRITEQ (cics_writeq_td | cics_writeq_ts);
820-
cics_writeq_td: TD (QUEUE cics_name | FROM cics_data_area | LENGTH cics_data_value | SYSID cics_data_area)+;
820+
cics_writeq_td: TD (QUEUE cics_name | FROM cics_data_area | LENGTH cics_data_value | SYSID cics_data_area | cics_resp)+;
821821
cics_writeq_ts: TS? (QUEUE cics_name | QNAME cics_name | FROM cics_data_area | LENGTH cics_data_value |
822822
NUMITEMS cics_data_area | ITEM cics_data_area | REWRITE | SYSID cics_data_area | AUXILIARY | MAIN | NOSUSPEND | cics_resp)+;
823823

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ parser grammar Db2SqlParser;
1616
options {tokenVocab = Db2SqlLexer; superClass = MessageServiceParser;}
1717

1818
/*Allowable SQL statements for COBOL program specific dvisions or sections*/
19-
dataDivisionRules: (dbs_declare_variable | rulesAllowedInDataDivision | rulesAllowedInWorkingStorageAndLinkageSection)+;
19+
dataDivisionRules: (dbs_declare_variable | rulesAllowedInDataDivision | rulesAllowedInWorkingStorageAndLinkageSection)+ EOF;
2020

2121
procedureDivisionRules: ((dbs_allocate | dbs_alter | dbs_associate | dbs_call | dbs_close | dbs_comment | dbs_commit |
2222
dbs_connect | dbs_create | dbs_declare | dbs_declare_cursor | dbs_declare_table | dbs_delete | dbs_describe | dbs_drop | dbs_exchange | dbs_execute | dbs_explain |
2323
dbs_fetch | dbs_free | dbs_get | dbs_grant | dbs_hold | dbs_include | dbs_insert |
2424
dbs_label | dbs_lock | dbs_merge | dbs_open | dbs_prepare | dbs_refresh | dbs_release | dbs_rename |
2525
dbs_revoke | dbs_rollback | dbs_savepoint | dbs_select | dbs_set | dbs_signal | dbs_transfer | dbs_truncate |
26-
dbs_update | dbs_values | dbs_whenever) dbs_semicolon_end?)+;
26+
dbs_update | dbs_values | dbs_whenever) dbs_semicolon_end?)+ EOF;
2727
rulesAllowedInDataDivision: ((dbs_declare_cursor | dbs_declare_table | dbs_include) dbs_semicolon_end?)+;
2828
rulesAllowedInWorkingStorageAndLinkageSection: ((dbs_begin | dbs_end | dbs_include_sqlca | dbs_include_sqlda) dbs_semicolon_end?)+;
2929

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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+
package org.eclipse.lsp.cobol.usecases;
16+
17+
import com.google.common.collect.ImmutableList;
18+
import com.google.common.collect.ImmutableMap;
19+
import org.eclipse.lsp.cobol.common.error.ErrorSource;
20+
import org.eclipse.lsp.cobol.test.engine.UseCaseEngine;
21+
import org.eclipse.lsp4j.Diagnostic;
22+
import org.eclipse.lsp4j.DiagnosticSeverity;
23+
import org.eclipse.lsp4j.Range;
24+
import org.junit.jupiter.api.Test;
25+
26+
/** Test that tokens are not skipped for embedded language. */
27+
public class TestEmbeddedCodeWithIssueOnLastToken {
28+
private static final String ISSUE_1 = " :testing,{|1}\n" + " END-EXEC.";
29+
30+
private static final String ISSUE_2 = " :{$testing}({|1}\n" + " END-EXEC.";
31+
32+
private static final String NO_ISSUE = " :{$testing}\n" + " END-EXEC.";
33+
34+
public static final String TEXT =
35+
" IDENTIFICATION DIVISION.\n"
36+
+ " PROGRAM-ID. TEST12.\n"
37+
+ " ENVIRONMENT DIVISION.\n"
38+
+ " DATA DIVISION.\n"
39+
+ " WORKING-STORAGE SECTION.\n"
40+
+ " 01 {$*testing} pic x.\n"
41+
+ " PROCEDURE DIVISION.\n"
42+
+ " EXEC SQL \n"
43+
+ " fetch abc \n"
44+
+ " into \n"
45+
+ " asas,\n"
46+
+ " ajsjs, \n";
47+
48+
@Test
49+
void testCobolParserDontEatEmbeddedToken() {
50+
UseCaseEngine.runTest(
51+
TEXT + ISSUE_1,
52+
ImmutableList.of(),
53+
ImmutableMap.of(
54+
"1",
55+
new Diagnostic(
56+
new Range(),
57+
"No viable alternative at input abc\n into\n asas, \n ajsjs, \n :testing,",
58+
DiagnosticSeverity.Error,
59+
ErrorSource.PARSING.getText())));
60+
}
61+
62+
@Test
63+
void testEmbeddedTokensAreFullyMatchedAgainstEmbeddedParserRule() {
64+
UseCaseEngine.runTest(
65+
TEXT + ISSUE_2,
66+
ImmutableList.of(),
67+
ImmutableMap.of(
68+
"1",
69+
new Diagnostic(
70+
new Range(),
71+
"No viable alternative at input (",
72+
DiagnosticSeverity.Error,
73+
ErrorSource.PARSING.getText())));
74+
}
75+
76+
@Test
77+
void testPositiveScenario() {
78+
UseCaseEngine.runTest(TEXT + NO_ISSUE, ImmutableList.of(), ImmutableMap.of());
79+
}
80+
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ class TestSqlAllAlterStatements {
467467
private static final String ALTER_VIEW =
468468
TEXT
469469
+ " EXEC SQL\n"
470-
+ " ALTER VIEW MYVIEW REGENERATE;;\n"
470+
+ " ALTER VIEW MYVIEW REGENERATE;\n"
471471
+ " END-EXEC.";
472472

473473
private static final String ALTER_VIEW2 =

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class TestSqlInsertStatement {
8282
private static final String INSERT6 =
8383
TEXT
8484
+ " INSERT INTO ABC INCLUDE (A SMALLINT, \n"
85-
+ " B SMALLINT) VALUEs :{$TAD}+1;\n"
85+
+ " B SMALLINT) VALUEs (:{$TAD}+1);\n"
8686
+ " END-EXEC.";
8787

8888
public static final String INSERT7 =

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ END_COMPUTE : E N D MINUSCHAR C O M P U T E;
244244
END_DELETE : E N D MINUSCHAR D E L E T E;
245245
END_DIVIDE : E N D MINUSCHAR D I V I D E;
246246
END_EVALUATE : E N D MINUSCHAR E V A L U A T E;
247-
END_EXEC : E N D MINUSCHAR E X E C;
247+
END_EXEC : E N D MINUSCHAR E X E C {enableCobolSpecialSeparators = true;};
248248
END_IF : E N D MINUSCHAR I F;
249249
END_JSON: E N D MINUSCHAR J S O N;
250250
END_MULTIPLY : E N D MINUSCHAR M U L T I P L Y;
@@ -278,7 +278,7 @@ EVERY : E V E R Y;
278278
EX : E X;
279279
EXCEPTION : E X C E P T I O N;
280280
EXCLUSIVE : E X C L U S I V E;
281-
EXEC : E X E C;
281+
EXEC : E X E C {enableCobolSpecialSeparators = false;};
282282
EXHIBIT : E X H I B I T;
283283
EXIT : E X I T;
284284
EXP : E X P;

0 commit comments

Comments
 (0)