How to fix the “multi-character literals are not allowed” error in antlr4 lexer rule?

佐手、 提交于 2021-01-28 06:04:34

问题


The rule I am trying to write is:

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

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'

How to resolve this problem?


回答1:


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

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

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

[...] 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 \.



来源:https://stackoverflow.com/questions/56322449/how-to-fix-the-multi-character-literals-are-not-allowed-error-in-antlr4-lexer

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!