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

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

问题描述

我要写的规则是:

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

但是当尝试对定义了该词法的lexer文件运行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 解释为介于 x y 之间的一组字符.以下转义字符被解释为单个特殊字符: \ 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天全站免登陆