antlr4 词法分析器谓词文档

antlr4 lexer predicate documentation

antlr4的好几道题都用到了lexer predicates,书上没有提到,比如 uses ahead(String), uses getCharPositionInLine(), 23465358用了_input.LA(1)等。 _input.LA(1) 在书中也使用了几次(例如在 2014 年版的第 212 和 228 页),但没有解释它到底做了什么.是否有可用的词法分析器谓词列表及其文档?

这些不是词法分析器谓词。相反,它们是 运行 时间对象上的普通方法:Token#getCharPositionInLine()CharStream#LA(int)source code.

中提供了文档

词法分析器 class 将 _input 定义为

public CharStream _input;

此外,ahead() 方法是在该特定语法顶部的 @lexer::members 块中自定义定义的(并且取决于 CharStream#LA(int) 的使用)。

TDAR 仍然是最好的说明文档。源代码在内部有很好的记录。