词法分析器中的ANTLR3动态引号 [英] ANTLR3 Dynamic quotes in lexer
问题描述
我需要匹配 Perl 正则表达式匹配器之类的东西
I need to match something like the Perl regexp matcher
m/my regex!*/
其中引号可以是范围内的任何字符.所以上面是一样的
where the quotes can be any character from a range. So the above is the same as
m%my regex!*%
对词法分析器规则的天真猜测是
A naive guess of a lexer rule would be
REGEX: 'm' quote=. (~(quote))* quote;
但这不起作用,因为后面的 quote
不是指 quote=
而是指一些规则.
but that does not work, because the latter quote
is not referring to the quote=
but to some rule.
我可以用很多自己的代码来做,比如
I can do it with a lot of own code, like
REGEX: 'm' quote=. { ... implement the loop and final match myself ... } ;
但不知何故,我认为应该有一种规范的方式来做这样的事情.
but somehow I think there should be a canonical way to do such things.
推荐答案
...但不知何故,我认为应该有一种规范的方式来做这样的事情.
... but somehow I think there should be a canonical way to do such things.
没有.您必须使用自定义代码来执行此操作.
There is not. You'll have to do this with custom code.
这篇关于词法分析器中的ANTLR3动态引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!