首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >括号内冒号的含义

括号内冒号的含义
EN

Stack Overflow用户
提问于 2020-10-22 07:39:33
回答 1查看 110关注 0票数 1

(: .)表达式在ANTLR规则中有什么意义?

代码语言:javascript
复制
message
   : COLON (: .)*?
   ;

https://github.com/antlr/grammars-v4/blob/master/stacktrace/StackTrace.g4#L79

我不能用医生的话说冒号是被允许进入规则的。在这种情况下,不应该将括号中的:替换为COLON吗?

更新

这些案例是否也是从options的清除中遗留下来的?

代码语言:javascript
复制
grammars-v4/antlr/antlr3/examples/Verilog3.g(548,13): Warning: ignoring colon with no effect, token `'else'` at offset 12136
grammars-v4/vhdl/vhdl.g4(696,18): Warning: ignoring colon with no effect, token `logical_operator` at offset 13302
grammars-v4/vhdl/vhdl.g4(700,17): Warning: ignoring colon with no effect, token `DOUBLESTAR` at offset 13359
grammars-v4/vhdl/vhdl.g4(1087,25): Warning: ignoring colon with no effect, token `identifier` at offset 20396
grammars-v4/vhdl/vhdl.g4(1232,9): Warning: ignoring colon with no effect, token `relational_operator` at offset 22963
grammars-v4/vhdl/vhdl.g4(1310,9): Warning: ignoring colon with no effect, token `shift_operator` at offset 24300
grammars-v4/vhdl/vhdl.g4(1351,32): Warning: ignoring colon with no effect, token `adding_operator` at offset 24999
grammars-v4/vhdl/vhdl.g4(1497,16): Warning: ignoring colon with no effect, token `multiplying_operator` at offset 28078
grammars-v4/pascal/pascal.g4(439,38): Warning: ignoring colon with no effect, token `ELSE` at offset 7347
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-10-22 08:02:51

它没有任何意义,应该删除。我的猜测是语法是从ANTLR3转换而来的,v3版本中有以下内容:

代码语言:javascript
复制
message
   : COLON (options{greedy=false;}: .)*
   ;

他们删除了options{greedy=false;}部件而没有删除:。为了匹配v4中的不贪婪,引入了?。还可以删除括号:

代码语言:javascript
复制
message
   : COLON .*?
   ;

这应该是对您的一个警告:语法没有经过很好的测试,规则以.*?结尾这一事实对我来说总是有点可疑(通常有更好的方法来匹配这样的规则)。还有更多的事情我不喜欢这个语法(不一定是错的,但事情我认为不好的做法)。在生产环境中小心使用这个!

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64477446

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档