Skip to content

Commit cd8dce6

Browse files
committed
fix: add semantics check for table locator db2 host variable
1 parent ee9fc89 commit cd8dce6

File tree

2 files changed

+30
-25
lines changed

2 files changed

+30
-25
lines changed

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

+8-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,14 @@ binary_host_variable_varbinary_size: T=dbs_integerliteral_expanded {validateInte
3636

3737
host_variable_usage: (USAGE IS?)? SQL TYPE IS;
3838

39-
sql_host_variables: dbs_level_01 entry_name host_variable_usage (result_set_locator | tableLocators);
39+
sql_host_variables: result_set_locator_variable
40+
| tableLocators_variable ;
41+
42+
result_set_locator_variable: dbs_level_01 entry_name host_variable_usage result_set_locator;
43+
44+
tableLocators_variable: dbs_host_var_levels entry_name host_variable_usage tableLocators;
45+
46+
dbs_host_var_levels: dbs_level_01 | T=dbs_integer {validateIntegerRange($T.text, 2, 48);};
4047

4148
result_set_locator: RESULT_SET_LOCATOR VARYING;
4249

server/engine/src/main/java/org/eclipse/lsp/cobol/implicitDialects/sql/Db2SqlVisitor.java

+22-24
Original file line numberDiff line numberDiff line change
@@ -82,33 +82,31 @@ public List<Node> visitExecRule(Db2SqlParser.ExecRuleContext ctx) {
8282
}
8383

8484
@Override
85-
public List<Node> visitSql_host_variables(
86-
Db2SqlParser.Sql_host_variablesContext ctx) {
85+
public List<Node> visitResult_set_locator_variable(Db2SqlParser.Result_set_locator_variableContext ctx) {
86+
return createHostVariableDefinitionNode(ctx, ctx.dbs_level_01(), ctx.entry_name());
87+
}
88+
89+
@Override
90+
public List<Node> visitTableLocators_variable(Db2SqlParser.TableLocators_variableContext ctx) {
91+
return createHostVariableDefinitionNode(ctx, ctx.dbs_host_var_levels(), ctx.entry_name());
92+
}
93+
94+
private List<Node> createHostVariableDefinitionNode(ParserRuleContext ctx, ParserRuleContext levelCtx, ParserRuleContext nameCtx) {
8795
addReplacementContext(ctx);
88-
Locality statementLocality =
89-
getLocality(this.context.getExtendedDocument().mapLocation(constructRange(ctx)));
96+
Locality statementLocality = getLocality(this.context.getExtendedDocument().mapLocation(constructRange(ctx)));
9097

91-
// semantics node just checks that the statement is present at right location
92-
Db2WorkingAndLinkageSectionNode semanticsNode =
93-
new Db2WorkingAndLinkageSectionNode(statementLocality);
98+
Db2WorkingAndLinkageSectionNode semanticsNode = new Db2WorkingAndLinkageSectionNode(statementLocality);
99+
100+
VariableDefinitionNode variableDefinitionNode = VariableDefinitionNode.builder()
101+
.level(Integer.parseInt(levelCtx.getText()))
102+
.levelLocality(getLocality(this.context.getExtendedDocument().mapLocation(constructRange(levelCtx))))
103+
.statementLocality(statementLocality)
104+
.variableNameAndLocality(new VariableNameAndLocality(
105+
VisitorHelper.getName(nameCtx),
106+
getLocality(this.context.getExtendedDocument().mapLocation(constructRange(nameCtx)))))
107+
.usageClauses(ImmutableList.of(UsageFormat.DISPLAY))
108+
.build();
94109

95-
// variable definition node
96-
VariableDefinitionNode variableDefinitionNode =
97-
VariableDefinitionNode.builder()
98-
.level(Integer.parseInt(ctx.dbs_level_01().getText()))
99-
.levelLocality(
100-
getLocality(
101-
this.context.getExtendedDocument().mapLocation(constructRange(ctx.dbs_level_01()))))
102-
.statementLocality(statementLocality)
103-
.variableNameAndLocality(
104-
new VariableNameAndLocality(
105-
VisitorHelper.getName(ctx.entry_name()),
106-
getLocality(
107-
this.context
108-
.getExtendedDocument()
109-
.mapLocation(constructRange(ctx.entry_name())))))
110-
.usageClauses(ImmutableList.of(UsageFormat.DISPLAY))
111-
.build();
112110
variableDefinitionNode.addChild(semanticsNode);
113111
return ImmutableList.of(variableDefinitionNode);
114112
}

0 commit comments

Comments
 (0)