没有特定字符序列的antlr字符串令牌
我正在尝试定义与不包含某些字符序列的字符串令牌相匹配的Lexer语法。例如,我想捕获的字符串的“
”
""
"asda A rewr A"
"asda A"
"asdas B ad"
示例
"asdas AB fdsdf"
ab
I'm trying to define a lexer grammar that matches string tokens that don't contain a certain sequence of characters. For instance "AB"
Example of strings I want to capture
""
"asda A rewr A"
"asda A"
"asdas B ad"
but not
"asdas AB fdsdf"
I tried a few things but I always seem to miss some case
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可以用一些模式魔术:当您进入第一个 string-mode 并遇到
ab
时,您只需推入第二个字符串模式:Java演示:
将打印以下内容:
Could be done with a little mode magic: when you're in the first string-mode and you encounter a
AB
, you just push into the second string-mode:The Java demo:
will print the following: