如何修复“不允许使用多字符文字"antlr4 词法分析器规则中的错误? [英] How to fix the "multi-character literals are not allowed" error in antlr4 lexer rule?

查看:36
本文介绍了如何修复“不允许使用多字符文字"antlr4 词法分析器规则中的错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写的规则是:

Character : '\u0000'..'\u10FFF';

但是当尝试针对定义它的词法分析器文件运行 antlr 工具时,我收到以下错误:

But when trying to run antlr tool against the lexer file where it is defined I get the following error:

multi-character literals are not allowed in lexer sets: '\u10FFF'

如何解决这个问题?

推荐答案

尝试用 {} 包装多字符文字,并使用 v4 样式字符集[...]:

Try wrapping the multi-char literal with { and }, and use the v4 style character set [...]:

Character : [\u0000-\u{10FFF}];

来自 https://github.com/antlr/antlr4/blob/master/doc/lexer-rules.md#lexer-rule-elements:

[...] 匹配字符集中指定的字符之一.将 x-y 解释为范围 xy 之间的字符集,包括.以下转义字符被解释为单个特殊字符:\n\r\b\t\f\uXXXX\u{XXXXXX}.要获得 ]\-,您必须使用 \ 对它们进行转义.

[...] Match one of the characters specified in the character set. Interpret x-y as the set of characters between range x and y, inclusively. The following escaped characters are interpreted as single special characters: \n, \r, \b, \t, \f, \uXXXX, and \u{XXXXXX}. To get ], \, or - you must escape them with \.

这篇关于如何修复“不允许使用多字符文字"antlr4 词法分析器规则中的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆