如何在不改变语法的情况下知道访问期间ANTLR解析器当前处于哪个替代规则
我查看了这些,它们似乎没有解决问题:
例如:
oC_ListOperatorExpression :
( SP IN SP? oC_PropertyOrLabelsExpression )
| ( SP? '[' oC_Expression ']' )
| ( SP? '[' oC_Expression? '..' oC_Expression? ']' ) ;
在这种特殊情况下,替代方案 2 和替代方案 3 没有特殊标记或位于固定位置的标记,我可以利用它们来区分它们。
在不改变语法的情况下,如何判断我在下面使用哪种替代方案?
antlrcpp::Any visitOC_ListOperatorExpression(
CypherParser::OC_ListOperatorExpressionContext* ctx) override {
}
我正在使用 ANTLR4 4.9.3.1 的 C++ 运行时。
完整语法: https://s3.amazonaws.com/artifacts.openencypher.org/ M18/Cypher.g4
I looked at these and they don't seem to solve the problem:
Is there a way to know which alternative rule ANTLR parser is currently in?
How to know which alternative rule ANTLR parser is currently in during visit
For example:
oC_ListOperatorExpression :
( SP IN SP? oC_PropertyOrLabelsExpression )
| ( SP? '[' oC_Expression ']' )
| ( SP? '[' oC_Expression? '..' oC_Expression? ']' ) ;
In this particular case, alternative 2 and alternative 3 have no special tokens or tokens in a fixed position I can leverage to differentiate them.
How can I tell which alternative am I using in the following without changing the grammar?
antlrcpp::Any visitOC_ListOperatorExpression(
CypherParser::OC_ListOperatorExpressionContext* ctx) override {
}
I am using the c++ runtime of ANTLR4 4.9.3.1.
The full grammar:
https://s3.amazonaws.com/artifacts.opencypher.org/M18/Cypher.g4
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在最后一个替代方案中向两个
oC_Expression
添加标签。然后你可以检查它们是否存在。(或者甚至只是检查第二个
oC_Expression
You could add labels to the two
oC_Expression
s in the last alternative. Then you could check for the presence/absence of those.(Or even just check for the 2nd
oC_Expression