ANTLR3 Dynamic quotes in lexer

流过昼夜 提交于 2019-12-24 16:32:57

问题


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;

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.


回答1:


... 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.




回答2:


Take a look at PL/SQL parser (here). Oracle also supports those Perl style quoted strings.

Like:

q':select * from employees where last_name = 'smith':'

Use the custom code as an example. (It contains C and Java implementation). Maybe in your case it can be even simplified.

Ivan



来源:https://stackoverflow.com/questions/14286870/antlr3-dynamic-quotes-in-lexer

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!