无法在Antlr3 SQL语法中提供主机变量 [英] Can not provide for host variables in Antlr3 SQL grammar

查看:86
本文介绍了无法在Antlr3 SQL语法中提供主机变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个SQL语法,该语法不支持主机变量.在这种情况下,我想为主机变量提供支持,但是遇到的情况很棘手.

I have a SQL grammar which do not have support for host variables. I want to provide support for host variables in that but a situation that I have encountered is tricky.

语法中有SQL Identifier词法分析器规则,它支持字母数字以及一些特殊字符'@','#','$和'_'.

There is SQL Identifier lexer rule in grammar, which supports alphanumeric along with some special characters '@', '#', '$ and '_'.

主机变量取决于嵌入SQL的语言.例如COBOL. COBOL标识符还允许在变量名中使用连字符(-)(它们之间的某些其他区别).

Host variable's are dependent on language in which SQL is embedded. e.g. COBOL. COBOL identifiers allow additionally hyphen(-) in variable names (Some other differences in them).

所以我在语法中另外添加了LANG_ID,它与COBOL标识符匹配.

So I added LANG_ID additionally in grammar, which is matching COBOL identifiers.

宿主变量的解析器规则如下:

Parser rule for host variable was like :

hostvariable : COLON WS* (ID | LANG_ID);

还有其他匹配表达式的规则.像这样的东西:

There was some other rule which was matching expressions. something like that:

expression :  identifier ('+' | '-')  identifier;

这里的标识符是解析器规则,可能具有ID和其他一些令牌.

identifier here is parser rule which may have ID and some other tokens.

表达式的有效输入为ABC + ABC,ABC-ABC,ABC-12.

valid input for expressions is ABC+ABC, ABC-ABC, ABC-12.

现在,当输入类似于ABC-12时,它将被标记为COBOL标识符.

Now when input is like ABC-12, then it is getting tokenized as COBOL identifier.

我实现的解决方案是,如果其后跟COLON(:),则仅是其COBOL标识符.然后,我制作了LANG_ID片段并创建了词法分析器规则:

Solution which I implemented was that, if its followed by COLON (:) , then only its COBOL identifier. Then I made LANG_ID fragment and created lexer rule as :

HOSTVAR : COLON WS* LANG_ID;

现在,JSON_OBJECT SQL函数的语法如下:

Now problem occurred with JSON_OBJECT SQL function which have syntax like:

JSON_OBJECT('​​KEY':VALUE)

JSON_OBJECT('KEY' : VALUE)

对于JSON_OBJECT,有一条规则要求 (character_literal COLON value_expression)

There is a rule for JSON_OBJECT which expects something like (character_literal COLON value_expression)

value_expression也可以是标识符.

value_expression could also be identifier.

在这种情况下,:VALUE"被标记为HOSTVAR并且JSON_OBJECT规则失败.

In this case ': VALUE' is tokenized as HOSTVAR and JSON_OBJECT rule is failing.

我无法找到该问题的任何解决方案.在每种方法中,都有失败的地方.

I am not able to find any solution for the problem. In every approach something getting failed.

推荐答案

JSON_OBJECT('KEY' : VALUE) 

IBM i COBOL不支持

语法.只能以

syntax is not supported in IBM i COBOL. This can only be provided in the form of

JSON_OBJECT (KEY key VALUE value) 

对于COBOL,如果在COLON后面紧跟某些内容,则应将其视为宿主变量.

In the case of COBOL when COLON is followed by something, it should be treated as host variable.

这篇关于无法在Antlr3 SQL语法中提供主机变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆