Skip to content

Commit

Permalink
Feature: Add support for DACO-CONTROL statement in DaCo dialect
Browse files Browse the repository at this point in the history
  • Loading branch information
Jules Kreutzer authored and ishche committed Jan 15, 2024
1 parent 4960389 commit 8dfd7e0
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ CHECK : C H E C K;
CLOSE : C L O S E;
COLS : C O L S;
CR : C R;
DACO_CONTROL: D A C O MINUSCHAR C O N T R O L;
DATE : D A T E;
DAY : D A Y;
DAY_OF_WEEK : D A Y MINUSCHAR O F MINUSCHAR W E E K;
Expand Down Expand Up @@ -127,6 +128,7 @@ RETURN : R E T U R N;
RETURN_CODE : R E T U R N MINUSCHAR C O D E;
ROW : R O W;
RCU : R C U;
SECTION: S E C T I O N;
SEQ : S E Q;
SHIFT_IN : S H I F T MINUSCHAR I N;
SHIFT_OUT : S H I F T MINUSCHAR O U T;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,19 @@ parser grammar DaCoParser;
options {tokenVocab = DaCoLexer; superClass = MessageServiceParser;}

startRule: .*? dacoRules* EOF;
dacoRules: dacoStatements .*?;
dacoRules: (dacoStatements | dacoSections) .*?;

dacoSections
: dacoControlSection
;

dacoControlSection
: DACO_CONTROL SECTION DOT_FS dacoControlSectionParagraph
;

dacoControlSectionParagraph
: ROW BUFFER qualifiedDataName IS YES DOT_FS
;

dacoStatements
: readTransactionStatement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ public List<Node> visitDacoStatements(DacoStatementsContext ctx) {
return visitChildren(ctx);
}

@Override
public List<Node> visitDacoSections(DaCoParser.DacoSectionsContext ctx) {
addReplacementContext(ctx);
return visitChildren(ctx);
}

@Override
public List<Node> visitSortTableStatement(DaCoParser.SortTableStatementContext ctx) {
return addTreeNode(ctx, SortTableNode::new);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright (c) 2024 DAF Trucks NV.
*
* 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:
* DAF Trucks NV – implementation of DaCo COBOL statements
* and DAF development standards
*/
package org.eclipse.lsp.cobol.dialects.daco.usecases;

import com.google.common.collect.ImmutableList;
import org.eclipse.lsp.cobol.common.error.ErrorSource;
import org.eclipse.lsp.cobol.dialects.daco.utils.DialectConfigs;
import org.eclipse.lsp.cobol.test.engine.UseCaseEngine;
import org.eclipse.lsp4j.Diagnostic;
import org.eclipse.lsp4j.DiagnosticSeverity;
import org.eclipse.lsp4j.Range;
import org.junit.jupiter.api.Test;

import java.util.HashMap;
import java.util.Map;

/** A test case for DACO-CONTROL section statements */
class TestDaCoControlSection {
private static final String TEXT =
" IDENTIFICATION DIVISION. \r\n"
+ " PROGRAM-ID. test1. \r\n"
+ " ENVIRONMENT DIVISION.\r\n"
+ " DACO-CONTROL SECTION.\r\n"
+ " ROW BUFFER {$TBLLAY-XW4} IS YES.\r\n"
// Negative test
+ " DACO-CONTROL SECTION.\r\n"
+ " ROW BUFFER {UNKVAR-XW4|1} IS YES.\r\n"
+ " IDMS-CONTROL SECTION.\r\n"
+ " PROTOCOL. MODE ABC.\r\n"
+ " IDMS-RECORDS MANUAL\r\n"
+ " DATA DIVISION. \r\n"
+ " WORKING-STORAGE SECTION. \r\n"
+ " 01 {$*WS-AREA}. \r\n"
+ " 03 {$*AREA-XW4}. \r\n"
+ " 05 {$*TBLLAY-XW4} PIC X(4) VALUE SPACE.\r\n"
+ " PROCEDURE DIVISION. \r\n"
+ " DISPLAY {$TBLLAY-XW4}. \r\n";

@Test
void test() {

Map<String, Diagnostic> diagnosticMap = new HashMap<>();
diagnosticMap.put(
"1",
new Diagnostic(
new Range(),
"Variable UNKVAR-XW4 is not defined",
DiagnosticSeverity.Error,
ErrorSource.PARSING.getText()));
UseCaseEngine.runTest(
TEXT, ImmutableList.of(), diagnosticMap, ImmutableList.of(), DialectConfigs.getDaCoAnalysisConfig());
}
}

0 comments on commit 8dfd7e0

Please sign in to comment.