Skip to content
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

Cics PUT CONTAINER improvements #2598

Open
wants to merge 21 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
6a4d423
Initial grammar
mm-broadcom Nov 20, 2024
9cb264e
Add checks for grammar
mm-broadcom Nov 20, 2024
90622d0
Add tests for grammar
mm-broadcom Nov 20, 2024
deb820f
Fixed checkstyle error
mm-broadcom Nov 20, 2024
80a5998
Add PREPEND to lexer, keywords and the regex
mm-broadcom Nov 21, 2024
8d7e82c
Added note about PREPEND's availability.
mm-broadcom Nov 21, 2024
86935e7
Fixed keyword count test
mm-broadcom Nov 21, 2024
5438a92
Fixed tests
mm-broadcom Nov 21, 2024
d76c284
Add PUT64 keyword support
mm-broadcom Nov 25, 2024
b5a685c
Update server/engine/src/test/java/org/eclipse/lsp/cobol/usecases/Tes…
mm-broadcom Dec 2, 2024
27eea7a
Update server/engine/src/test/java/org/eclipse/lsp/cobol/usecases/Tes…
mm-broadcom Dec 2, 2024
f6c67b2
Update server/engine/src/test/java/org/eclipse/lsp/cobol/usecases/Tes…
mm-broadcom Dec 2, 2024
078c28a
Update server/engine/src/test/java/org/eclipse/lsp/cobol/usecases/Tes…
mm-broadcom Dec 2, 2024
9e71158
Add FROM check, test, fix imports
mm-broadcom Dec 2, 2024
b0fdcab
Merge branch 'development' into CICS-PUT-CONTAINER-Improvements
mm-broadcom Dec 2, 2024
8d792a2
Merge branch 'development' into CICS-PUT-CONTAINER-Improvements
mm-broadcom Dec 16, 2024
ed6503f
Merge branch 'development' into CICS-PUT-CONTAINER-Improvements
mm-broadcom Dec 18, 2024
038e048
Add terms to cicsLexerDefinedVariableUsage rule
mm-broadcom Dec 18, 2024
ba5cd5f
Added check for APPEND or PREPEND
mm-broadcom Dec 20, 2024
67b7c30
Merge branch 'development' into CICS-PUT-CONTAINER-Improvements
mm-broadcom Dec 20, 2024
6e2e030
Add PUT64, remove duplicate optionsMap entry
mm-broadcom Dec 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -1135,6 +1135,7 @@ PPT : P P T;
PREDICATE : P R E D I C A T E;
PREFIX : P R E F I X;
PREPARE : P R E P A R E;
PREPEND : P R E P E N D;
PRIMPRED : P R I M P R E D;
PRIMPREDOP : P R I M P R E D O P;
PRIMPREDTYPE : P R I M P R E D T Y P E;
Expand Down Expand Up @@ -1187,6 +1188,7 @@ PURGECYCLES : P U R G E C Y C L E S;
PURGETHRESH : P U R G E T H R E S H;
PUSH : P U S H;
PUT : P U T;
PUT64: P U T '6' '4';
mm-broadcom marked this conversation as resolved.
Show resolved Hide resolved
QNAME : Q N A M E;
QUALIFIER : Q U A L I F I E R;
QUALLEN : Q U A L L E N;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ allCicsRule: cics_send | cics_receive | cics_add | cics_address | cics_allocate
cics_endbrowse | cics_enq | cics_enter | cics_extract | cics_force | cics_formattime | cics_free |
cics_freemain | cics_get | cics_getmain | cics_getmain64 | cics_getnext | cics_handle | cics_ignore | cics_inquire |
cics_invoke | cics_issue | cics_link | cics_load | cics_monitor | cics_move | cics_point | cics_pop |
cics_post | cics_purge | cics_push | cics_put | cics_query | cics_read | cics_readnext_readprev |
cics_post | cics_purge | cics_push | cics_put_container | cics_query | cics_read | cics_readnext_readprev |
cics_readq | cics_release | cics_remove | cics_reset | cics_resetbr | cics_resume | cics_retrieve |
cics_return | cics_rewind | cics_rewrite | cics_route | cics_run | cics_signal | cics_signoff | cics_signon |
cics_soapfault | cics_spoolclose | cics_spoolopen | cics_spoolread | cics_spoolwrite | cics_start |
Expand Down Expand Up @@ -645,10 +645,11 @@ cics_purge: PURGE cics_handle_response? MESSAGE cics_handle_response?;
cics_push: PUSH cics_handle_response? HANDLE cics_handle_response?;

/** PUT CONTAINER (both of them): */
cics_put: PUT CONTAINER cics_data_value (cics_put_bts | cics_put_channel);
cics_put_bts: (ACTIVITY cics_data_value | ACQACTIVITY | PROCESS | ACQPROCESS | FROM cics_data_area | FLENGTH cics_data_value | cics_handle_response)+;
cics_put_channel: (CHANNEL cics_data_value | FROM cics_data_area | FLENGTH cics_data_value | BIT | DATATYPE cics_cvda |
CHAR | FROMCCSID cics_data_value | FROMCODEPAGE cics_data_value | cics_handle_response)+;
cics_put_container: ((PUT CONTAINER cics_data_value cics_put_container_bts) | (PUT|PUT64) CONTAINER cics_data_value cics_put_container_channel);
cics_put_container_bts: ((ACQACTIVITY | PROCESS | ACQPROCESS) | (ACTIVITY | FLENGTH) cics_data_value | (FROM) cics_data_area | cics_handle_response)+;
cics_put_container_channel: ((BIT | CHAR | APPEND | PREPEND) | (CHANNEL | FLENGTH | FROMCCSID | FROMCODEPAGE) cics_data_value | FROM cics_data_area | DATATYPE cics_cvda | cics_handle_response)+;



/** QUERY CHANNEL / COUNTER / DCOUNTER / SECURITY */
cics_query: QUERY (cics_query_channel | cics_query_counter | cics_query_security);
Expand Down Expand Up @@ -2120,6 +2121,7 @@ ABCODE
| PREDICATE
| PREFIX
| PREPARE
| PREPEND
slavek-kucera marked this conversation as resolved.
Show resolved Hide resolved
| PRIMPRED
| PRIMPREDOP
| PRIMPREDTYPE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ public CICSOptionsCheckUtility(DialectProcessingContext context, List<SyntaxErro
optionsMap.put(
CICSReadNextReadPrevOptionsUtility.RULE_INDEX,
new CICSReadNextReadPrevOptionsUtility(context, errors));
optionsMap.put(
CICSPutContainerOptionsCheckUtility.RULE_INDEX,
new CICSPutContainerOptionsCheckUtility(context, errors));
optionsMap.put(
CICSForceOptionsCheckUtility.RULE_INDEX,
new CICSForceOptionsCheckUtility(context, errors));
Expand Down Expand Up @@ -159,6 +162,9 @@ public CICSOptionsCheckUtility(DialectProcessingContext context, List<SyntaxErro
optionsMap.put(
CICSWriteOptionsCheckUtility.RULE_INDEX,
new CICSWriteOptionsCheckUtility(context, errors));
optionsMap.put(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks unrelated.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate.

CICSWSAEPRUtility.RULE_INDEX,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CICSWriteOptionsCheckUtility was removed from the list in the last commit.

new CICSWSAEPRUtility(context, errors));
optionsMap.put(
CICSRetrieveOptionsCheckUtility.RULE_INDEX,
new CICSRetrieveOptionsCheckUtility(context, errors));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Copyright (c) 2024 Broadcom.
* The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Broadcom, Inc. - initial API and implementation
*
*/
package org.eclipse.lsp.cobol.implicitDialects.cics.utility;

import org.antlr.v4.runtime.ParserRuleContext;
import org.eclipse.lsp.cobol.common.dialects.DialectProcessingContext;
import org.eclipse.lsp.cobol.common.error.ErrorSeverity;
import org.eclipse.lsp.cobol.common.error.SyntaxError;
import org.eclipse.lsp.cobol.implicitDialects.cics.CICSLexer;
import org.eclipse.lsp.cobol.implicitDialects.cics.CICSParser;

import java.util.*;

import static org.eclipse.lsp.cobol.implicitDialects.cics.CICSParser.RULE_cics_put_container;

/** Checks CICS PUT CONTAINER rules for required and invalid options */
public class CICSPutContainerOptionsCheckUtility extends CICSOptionsCheckBaseUtility {

public static final int RULE_INDEX = RULE_cics_put_container;

private static final Map<Integer, ErrorSeverity> DUPLICATE_CHECK_OPTIONS =
new HashMap<Integer, ErrorSeverity>() {
{
put(CICSLexer.PUT, ErrorSeverity.ERROR);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PUT is not an operand.

put(CICSLexer.CONTAINER, ErrorSeverity.ERROR);
put(CICSLexer.ACTIVITY, ErrorSeverity.ERROR);
put(CICSLexer.ACQACTIVITY, ErrorSeverity.ERROR);
put(CICSLexer.PROCESS, ErrorSeverity.ERROR);
put(CICSLexer.ACQPROCESS, ErrorSeverity.ERROR);
put(CICSLexer.FROM, ErrorSeverity.ERROR);
put(CICSLexer.FLENGTH, ErrorSeverity.ERROR);
}
};

public CICSPutContainerOptionsCheckUtility(DialectProcessingContext context, List<SyntaxError> errors) {
super(context, errors, DUPLICATE_CHECK_OPTIONS);
}

/**
* Entrypoint to check CICS PUT CONTAINER rules for required and invalid options
* @param ctx ParserRuleContext subclass containing options
* @param <E> A subclass of ParserRuleContext
*/
public <E extends ParserRuleContext> void checkOptions(E ctx) {
switch (ctx.getRuleIndex()) {
case CICSParser.RULE_cics_put_container_bts:
checkBTS((CICSParser.Cics_put_container_btsContext) ctx);
break;
case CICSParser.RULE_cics_put_container_channel:
checkChannel((CICSParser.Cics_put_container_channelContext) ctx);
break;
default:
break;
}

checkDuplicates(ctx);
}

private void checkBTS(CICSParser.Cics_put_container_btsContext ctx) {
mm-broadcom marked this conversation as resolved.
Show resolved Hide resolved
checkMutuallyExclusiveOptions("ACTIVITY, ACQACTIVITY, PROCESS or ACQPROCESS", ctx.ACTIVITY(), ctx.ACQACTIVITY(), ctx.PROCESS(), ctx.ACQPROCESS());
checkHasMandatoryOptions(ctx.FROM(), ctx, "FROM");
}

private void checkChannel(CICSParser.Cics_put_container_channelContext ctx) {
mm-broadcom marked this conversation as resolved.
Show resolved Hide resolved
mm-broadcom marked this conversation as resolved.
Show resolved Hide resolved
checkMutuallyExclusiveOptions("BIT, DATATYPE or CHAR", ctx.BIT(), ctx.DATATYPE(), ctx.CHAR());

checkMutuallyExclusiveOptions("FROMCCSID or FROMCODEPAGE", ctx.FROMCCSID(), ctx.FROMCODEPAGE());
checkMutuallyExclusiveOptions("APPEND or PREPEND", ctx.APPEND(), ctx.PREPEND());

checkHasMandatoryOptions(ctx.FROM(), ctx, "FROM");
}

}
2 changes: 2 additions & 0 deletions server/engine/src/main/resources/LanguageKeywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2167,6 +2167,7 @@ PRECISION=
PREDICATE=
PREFIX=
PREPARE=
PREPEND=The PREPEND keyword is available in CICS 6.2 or later.
PRESERVE=
PREVIOUS=
PRIMARY=
Expand Down Expand Up @@ -2237,6 +2238,7 @@ PURGECYCLES=
PURGETHRESH=
PUSH=
PUT=
PUT64=
QNAME=
QUALIFIER=
QUALLEN=
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright (c) 2024 Broadcom.
* The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Broadcom, Inc. - initial API and implementation
*
*/

package org.eclipse.lsp.cobol.usecases;

import org.eclipse.lsp.cobol.common.error.ErrorSource;
import org.eclipse.lsp.cobol.usecases.common.CICSTestUtils;
import org.eclipse.lsp4j.Diagnostic;
import org.eclipse.lsp4j.DiagnosticSeverity;
import org.eclipse.lsp4j.Range;
import org.junit.jupiter.api.Test;

import java.util.*;

/**
* Test CICS PUT CONTAINER command. Documentation link: <a
* href="https://www.ibm.com/docs/en/cics-ts/6.x?topic=summary-put-container-channel">PUT CONTAINER
* Command</a>
*
* <p>This class tests all variations of the CONVERSE command found in the link above.
*/
public class TestCicsPutContainerStatement {

// Test Strings
private static final String PUT_BTS_VALID_1 = "PUT CONTAINER(123) ACTIVITY(123) FROM(123) FLENGTH(123)";
private static final String PUT_BTS_VALID_2 = "PUT CONTAINER(123) ACQACTIVITY FROM(123)";

private static final String PUT_CHANNEL_VALID_1 = "PUT CONTAINER(123) CHANNEL(123) FROM(123) FLENGTH(123) BIT FROMCCSID(123) APPEND";
private static final String PUT_CHANNEL_VALID_2 = "PUT CONTAINER(123) FROM(123)";

private static final String PUT_BTS_INVALID = "PUT CONTAINER(123) ACTIVITY(123) {ACQACTIVITY|errorOne} FROM(123) FLENGTH(123)";
private static final String PUT_CHANNEL_INVALID = "PUT CONTAINER(123) CHANNEL(123) FROM(123) FLENGTH(123) BIT {DATATYPE|errorOne}(123) APPEND";
private static final String PUT_BTS_INVALID_2 = "PUT CONTAINER(123) {ACQACTIVITY|errorOne}";
mm-broadcom marked this conversation as resolved.
Show resolved Hide resolved

// Test Functions
@Test
void testBTSValid() {
CICSTestUtils.noErrorTest(PUT_BTS_VALID_1);
CICSTestUtils.noErrorTest(PUT_BTS_VALID_2);
}

@Test
void testChannelValid() {
CICSTestUtils.noErrorTest(PUT_CHANNEL_VALID_1);
CICSTestUtils.noErrorTest(PUT_CHANNEL_VALID_2);
}

// Invalid Tests
mm-broadcom marked this conversation as resolved.
Show resolved Hide resolved
@Test
void testBTSInvalid() {
HashMap<String, Diagnostic> expectedDiagnostics = new HashMap<>();
expectedDiagnostics.put("errorOne", new Diagnostic(new Range(), "Options \"ACTIVITY, ACQACTIVITY, PROCESS or ACQPROCESS\" are mutually exclusive.", DiagnosticSeverity.Error, ErrorSource.PARSING.getText()));
CICSTestUtils.errorTest(PUT_BTS_INVALID, expectedDiagnostics);
}

@Test
void testBTSInvalid2() {
HashMap<String, Diagnostic> expectedDiagnostics = new HashMap<>();
expectedDiagnostics.put("errorOne", new Diagnostic(new Range(), "Missing required option: FROM", DiagnosticSeverity.Error, ErrorSource.PARSING.getText()));
CICSTestUtils.errorTest(PUT_BTS_INVALID_2, expectedDiagnostics);
}

@Test
void testChannelInvalid() {
HashMap<String, Diagnostic> expectedDiagnostics = new HashMap<>();
expectedDiagnostics.put("errorOne", new Diagnostic(new Range(), "Options \"BIT, DATATYPE or CHAR\" are mutually exclusive.", DiagnosticSeverity.Error, ErrorSource.PARSING.getText()));
CICSTestUtils.errorTest(PUT_CHANNEL_INVALID, expectedDiagnostics);
}
}
Loading