如何在规则中排除多个字符? [英] How to exclude more than one character in rule?
本文介绍了如何在规则中排除多个字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在 ANTLRWorks 中编写字符串匹配规则,我需要匹配转义引号或任何非引号字符.我可以匹配转义的引号,但另一部分有问题: ~'\'' |~'\"'
最终将匹配所有内容,而 ~'\'\"'
似乎被语法生成器(至少是视觉显示)忽略了.什么样的字符序列会让我得到我想要的?
I'm trying to write a string matching rule in ANTLRWorks, and I need to match either escaped quotes or any non quote character. I can match escaped quotes but I'm having trouble with the other part: ~'\'' | ~'\"'
will end up matching everything and ~'\'\"'
seems to be ignored by the grammar generator (at least the visual display). What sequence of characters will get me what I want?
推荐答案
试试这个:
StringLiteral
: '"' (EscapeSequence | StringChar)* '"'
;
EscapeSequence
: '\\' ('"' | '\\')
;
StringChar
: ~('"' | '\\')
;
这篇关于如何在规则中排除多个字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文