ANTLR3 Dynamic quotes in lexer

2019-08-06 13:08发布

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.

标签: antlr antlr3
2条回答
ゆ 、 Hurt°
2楼-- · 2019-08-06 13:34

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

查看更多
叛逆
3楼-- · 2019-08-06 13:49

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

查看更多
登录 后发表回答