(: .)表达式在ANTLR规则中有什么意义?
message
: COLON (: .)*?
;在https://github.com/antlr/grammars-v4/blob/master/stacktrace/StackTrace.g4#L79
我不能用医生的话说冒号是被允许进入规则的。在这种情况下,不应该将括号中的:替换为COLON吗?
更新
这些案例是否也是从options的清除中遗留下来的?
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发布于 2020-10-22 08:02:51
它没有任何意义,应该删除。我的猜测是语法是从ANTLR3转换而来的,v3版本中有以下内容:
message
: COLON (options{greedy=false;}: .)*
;他们删除了options{greedy=false;}部件而没有删除:。为了匹配v4中的不贪婪,引入了?。还可以删除括号:
message
: COLON .*?
;这应该是对您的一个警告:语法没有经过很好的测试,规则以.*?结尾这一事实对我来说总是有点可疑(通常有更好的方法来匹配这样的规则)。还有更多的事情我不喜欢这个语法(不一定是错的,但事情我认为不好的做法)。在生产环境中小心使用这个!
https://stackoverflow.com/questions/64477446
复制相似问题