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

Fix dots processing in SQL preprocessor #2300

Merged
merged 2 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Supplier;

/**
* Extended Text contains information about original text and current text with the mapping
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import lombok.experimental.UtilityClass;
import org.eclipse.lsp.cobol.common.model.Locality;
import org.eclipse.lsp.cobol.common.model.tree.CopyNode;
import org.eclipse.lsp.cobol.common.model.tree.Node;
import org.eclipse.lsp4j.Position;
import org.eclipse.lsp4j.Range;
Expand All @@ -37,6 +38,13 @@ public class RangeUtils {
*/
public static Optional<Node> findNodeByPosition(Node node, String uri, Position position) {
Node candidate = null;
if (isFromCopybook(uri, node)) {
if (node.getChildren().isEmpty()) {
return Optional.of(node);
}
candidate = node;
}

if (isInside(uri, position, node.getLocality())) {
if (node.getChildren().isEmpty()) {
return Optional.of(node);
Expand All @@ -53,6 +61,14 @@ public static Optional<Node> findNodeByPosition(Node node, String uri, Position
return candidate == null ? Optional.empty() : Optional.of(candidate);
}

private boolean isFromCopybook(String uri, Node node) {
if (!(node instanceof CopyNode)) {
return false;
}
CopyNode copyNode = (CopyNode) node;
return uri.equals(copyNode.getUri());
}

/**
* Test if one position is after the another position.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ options {tokenVocab = Db2SqlLexer; superClass = MessageServiceParser;}
startRule: .*? (execRule .*?) * EOF;
//startIncludeRule: .*? (includeStatement .*?)* EOF;

execRule: EXEC SQL sqlCode END_EXEC DOT_FS?
| EXEC SQL END_EXEC DOT_FS?
| EXEC SQLIMS sqlCode END_EXEC DOT_FS? // TODO: check when should this grammar be activated. Probably based on some compiler directives
execRule: EXEC SQL sqlCode END_EXEC
| EXEC SQL END_EXEC
| EXEC SQLIMS sqlCode END_EXEC // TODO: check when should this grammar be activated. Probably based on some compiler directives
| {notifyError("cobolParser.missingEndExec");} EXEC SQL sqlCode DOT_FS? EOF
| {notifyError("cobolParser.missingEndExec");} EXEC SQL;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,15 @@ public List<Node> visitParagraphs(ParagraphsContext ctx) {

@Override
public List<Node> visitProcedureDivisionBody(ProcedureDivisionBodyContext ctx) {
return addTreeNode(ctx, ProcedureDivisionBodyNode::new);

ParserRuleContext context = new ParserRuleContext();
context.start = ctx.getParent().start;
context.stop = ctx.stop;

List<Node> children = visitChildren(ctx);
return retrieveLocality(context)
.map(constructNode(ProcedureDivisionBodyNode::new, children))
.orElse(children);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public List<ProcessorDescription> getProcessors() {
new ImplicitDb2VariablesProcessor()),
new ProcessorDescription(
Db2DataAndProcedureDivisionNode.class,
ProcessingPhase.POST_DEFINITION,
ProcessingPhase.VALIDATION,
new Db2DataAndProcedureDivisionProcessor(messageService)),
new ProcessorDescription(
Db2DeclareVariableNode.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@
import org.eclipse.lsp4j.Diagnostic;
import org.eclipse.lsp4j.DiagnosticSeverity;
import org.eclipse.lsp4j.Range;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

/**
* This test checks that the an asterisk out of indicator area before the COPY statement doesn't
* This test checks that the asterisk out of indicator area before the COPY statement doesn't
* break syntax analysis
*/
class TestAsteriskBeforeCopyDoesntBreakAnalysis {
Expand Down Expand Up @@ -60,7 +61,8 @@ void test() {
}

@Test
void testРц() {
@Disabled("Experimental parser")
void testEx() {

UseCaseEngine.runTest(
TEXT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@
PROCEDURE DIVISION.
EXEC CICS HANDLE ABEND
END-EXEC.
.
Original file line number Diff line number Diff line change
Expand Up @@ -533,5 +533,5 @@ cobolWord
;

dialectNodeFiller
: ZERO_WIDTH_SPACE+
: ZERO_WIDTH_SPACE+ DOT_FS? EOF?
;
Original file line number Diff line number Diff line change
Expand Up @@ -202,5 +202,5 @@ cobolWord
;

dialectNodeFiller
: ZERO_WIDTH_SPACE+
: ZERO_WIDTH_SPACE+ DOT_FS? EOF?
;
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,7 @@ procedureSection

sentence
: statement * (endClause | dialectStatement)
| dialectStatement
;

paragraph
Expand Down Expand Up @@ -2207,7 +2208,7 @@ literal
: NONNUMERICLITERAL | figurativeConstant | numericLiteral | booleanLiteral | charString | dialectLiteral | utfLiteral | hexadecimalUtfLiteral
;

dialectLiteral: dialectNodeFiller+;
dialectLiteral: dialectNodeFiller+ DOT_FS?;

utfLiteral: U_CHAR NONNUMERICLITERAL;

Expand Down Expand Up @@ -2244,7 +2245,7 @@ power
;

basis
: dialectNodeFiller | generalIdentifier | literal | LPARENCHAR arithmeticExpression RPARENCHAR
: (dialectNodeFiller DOT_FS?) | generalIdentifier | literal | LPARENCHAR arithmeticExpression RPARENCHAR
;

cobolWord
Expand All @@ -2263,7 +2264,7 @@ cobolKeywords
;

dialectNodeFiller
: ZERO_WIDTH_SPACE+
: ZERO_WIDTH_SPACE+ DOT_FS? EOF?
;

dot_fs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ COMMENTLINE : COMMENTTAG ~('\n' | '\r')* -> channel(COMMENTS);
WS : [ \t\f]+ -> channel(HIDDEN);
COMPILERLINE : DOUBLEMORETHANCHAR ~('\n' | '\r')* -> channel(HIDDEN);
// period full stopPosition
DOT : '.';
DOT_FS : '.' EOF?;

LEVEL_NUMBER : ([1-9])|([0][1-9])|([1234][0-9]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ paragraph

sentence
: statement * (endClause | dialectStatement)
| dialectStatement
;

conditionalStatementCall
Expand Down Expand Up @@ -1499,5 +1500,5 @@ cobolKeywords
;

dialectNodeFiller
: ZERO_WIDTH_SPACE+
: ZERO_WIDTH_SPACE+ DOT? EOF?
;
Loading