gpt4 book ai didi

antlr4 - 摆脱 token 识别错误

转载 作者:行者123 更新时间:2023-12-04 10:38:47 26 4
gpt4 key购买 nike

如何摆脱默认的 ANTLR 识别错误?

我想用我自己的错误类而不是 ANTLR 的错误来写另一条消息。

我的意思是是否有可能扩展某些 ANTLR 错误类以显示我自己的消息?

更清楚地说,我不想在控制台中看到以下错误消息:

token recognition error at:

最佳答案

如果你只是想压制消息,你可以调用lexer.removeErrorListeners() .但是,更好的方法是编写词法分析器规则,以便对所有可能的输入进行标记,并在词法分析器的末尾使用以下规则。这将导致所有错误报告都通过解析器而不是解析器和词法分析器。

// handle characters which failed to match any other token
ErrorCharacter : . ;

关于antlr4 - 摆脱 token 识别错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22415208/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com