在lexer中获得真正的位置。添加了示例

时间:2013-06-26 19:52:33

标签: netbeans netbeans-platform antlr4

我用netbeans7和ANTLR4编写编辑器 我在my.g4文件中有一行

Label       : {(getCharPositionInLine()==0)}? ID; 

适用于静态文件,但编辑getCharPositionInLine()时常常在其他地方返回0。 如何在词法分析器中找到真正的位置?

更新
我用这个问题创建了例子 https://github.com/daimor/SimpleANTLR

1 个答案:

答案 0 :(得分:1)

您的错误很可能与构建词法分析器和/或输入流(即此处未显示的代码)有关。您在上面描述的谓词将按预期用于ANTLR 4词法分析器。

此外,如果getCharPositionInLine()==0,则下列条件之一也是如此:

  1. _input.index()==0
  2. _input.LA(-1)=='\n'