From bf85ebd2b3c0a8a6c10db114e937d4ff2296e7e7 Mon Sep 17 00:00:00 2001 From: ap891843 Date: Mon, 5 Aug 2024 16:42:43 +0200 Subject: [PATCH] fix: allow standalone node without pic clause for the supported usage clause allow standalone node without pic clause for the following usage clause: INDEX, POINTER, POINTER_32, PROCEDURE_POINTER, FUNCTION_POINTER, OBJECT_REFERENCE, COMPUTATIONAL_1, COMPUTATIONAL_2, COMP_1, COMP_2 Signed-off-by: ap891843 --- .../model/tree/variable/UsageFormat.java | 17 ++++--- .../processors/StandAloneDataItemCheck.java | 21 ++++++++- .../lsp/cobol/core/visitor/VisitorHelper.java | 3 +- ...estElementaryVariableWithoutPicClause.java | 45 +++++++++++++++++++ .../org/eclipse/lsp/cobol/core/CobolLexer.g4 | 1 + 5 files changed, 78 insertions(+), 9 deletions(-) create mode 100644 server/engine/src/test/java/org/eclipse/lsp/cobol/usecases/TestElementaryVariableWithoutPicClause.java diff --git a/server/common/src/main/java/org/eclipse/lsp/cobol/common/model/tree/variable/UsageFormat.java b/server/common/src/main/java/org/eclipse/lsp/cobol/common/model/tree/variable/UsageFormat.java index 8fc49c5503..db3b59d816 100644 --- a/server/common/src/main/java/org/eclipse/lsp/cobol/common/model/tree/variable/UsageFormat.java +++ b/server/common/src/main/java/org/eclipse/lsp/cobol/common/model/tree/variable/UsageFormat.java @@ -44,7 +44,7 @@ public enum UsageFormat { INDEX, NATIONAL, UTF_8, - OBJECT_REFERENCE, + OBJECT_REFERENCE("OBJECTREFERENCE"), PACKED_DECIMAL, POINTER, POINTER_32, @@ -53,11 +53,18 @@ public enum UsageFormat { UNDEFINED; private static final Map MAP; + private final String text; static { - MAP = - Arrays.stream(values()) - .collect(toMap(it -> it.toDisplayString(), Function.identity())); + MAP = Arrays.stream(values()).collect(toMap(it -> it.text, Function.identity())); + } + + UsageFormat(String text) { + this.text = text.replace("_", "-"); + } + + UsageFormat() { + this.text = this.name().replace("_", "-"); } /** @@ -76,6 +83,6 @@ public static UsageFormat of(String text) { * @return the name to display */ public String toDisplayString() { - return toString().replace("_", "-"); + return this.text; } } diff --git a/server/engine/src/main/java/org/eclipse/lsp/cobol/core/engine/processors/StandAloneDataItemCheck.java b/server/engine/src/main/java/org/eclipse/lsp/cobol/core/engine/processors/StandAloneDataItemCheck.java index f01e9fa3dd..3e060498c0 100644 --- a/server/engine/src/main/java/org/eclipse/lsp/cobol/core/engine/processors/StandAloneDataItemCheck.java +++ b/server/engine/src/main/java/org/eclipse/lsp/cobol/core/engine/processors/StandAloneDataItemCheck.java @@ -14,19 +14,36 @@ */ package org.eclipse.lsp.cobol.core.engine.processors; +import com.google.common.collect.ImmutableList; import org.eclipse.lsp.cobol.common.message.MessageTemplate; +import org.eclipse.lsp.cobol.common.model.tree.variable.UsageFormat; import org.eclipse.lsp.cobol.common.processor.ProcessingContext; import org.eclipse.lsp.cobol.common.processor.Processor; import org.eclipse.lsp.cobol.common.model.tree.variable.StandAloneDataItemNode; -import org.eclipse.lsp.cobol.common.model.tree.variable.UsageFormat; + +import java.util.List; import static org.eclipse.lsp.cobol.common.VariableConstants.EMPTY_STRUCTURE_MSG; /** StandAloneDataItemNode processor */ public class StandAloneDataItemCheck implements Processor { + private static final List USAGE_FOR_NO_MANDATORY_PIC_CLAUSE = + ImmutableList.of( + UsageFormat.INDEX, + UsageFormat.POINTER, + UsageFormat.POINTER_32, + UsageFormat.PROCEDURE_POINTER, + UsageFormat.FUNCTION_POINTER, + UsageFormat.OBJECT_REFERENCE, + UsageFormat.COMPUTATIONAL_1, + UsageFormat.COMP_1, + UsageFormat.COMPUTATIONAL_2, + UsageFormat.COMP_2); + @Override public void accept(StandAloneDataItemNode node, ProcessingContext ctx) { - if (node.getPicClause().isEmpty() && node.getUsageFormat() != UsageFormat.INDEX) { + if (node.getPicClause().isEmpty() + && !USAGE_FOR_NO_MANDATORY_PIC_CLAUSE.contains(node.getUsageFormat())) { ctx.getErrors().add(node.getError(MessageTemplate.of(EMPTY_STRUCTURE_MSG, node.getName()))); } } diff --git a/server/engine/src/main/java/org/eclipse/lsp/cobol/core/visitor/VisitorHelper.java b/server/engine/src/main/java/org/eclipse/lsp/cobol/core/visitor/VisitorHelper.java index 51509c06d9..0e8a4769c7 100644 --- a/server/engine/src/main/java/org/eclipse/lsp/cobol/core/visitor/VisitorHelper.java +++ b/server/engine/src/main/java/org/eclipse/lsp/cobol/core/visitor/VisitorHelper.java @@ -193,8 +193,7 @@ public static List retrieveUsageFormatOld(List pushMode(PICTURECLAUSE) ; PICTURE : P I C T U R E {cobolVerbTokens.add(PICTURE);} -> pushMode(PICTURECLAUSE) ; POINTER : P O I N T E R {cobolVerbTokens.add(POINTER);}; +POINTER_32 : P O I N T E R MINUSCHAR '3' '2' {cobolVerbTokens.add(POINTER_32);}; PORT : P O R T; POSITION : P O S I T I O N {cobolVerbTokens.add(POSITION);}; POSITIVE : P O S I T I V E {cobolVerbTokens.add(POSITIVE);};