lexer中的ANTLR3动态引号 [英] ANTLR3 Dynamic quotes in lexer
本文介绍了lexer中的ANTLR3动态引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要匹配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.
这篇关于lexer中的ANTLR3动态引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文