我用Antlr4和Python3。在
我有一个getTerminalPos
方法,它返回给定终端的行和列号的元组。为此,我首先使用.getSymbol()
获取令牌,然后使用.getLine()
和{
def getTerminalPos(self, terminal):
token = terminal.getSymbol()
return (token.getLine(), token.getCharPositionInLine())
在antlr访问者中调用getTerminalPos
的示例:
运行代码时,收到以下错误消息:
File ".../py-antlr4-lmaspl/AntlrVisitor.py", line 55, in getTerminalPos
return (token.getLine(), token.getCharPositionInLine())
AttributeError: 'CommonToken' object has no attribute 'getLine'
根据antlr4java运行时,存在以下方法:https://www.antlr.org/api/Java/org/antlr/v4/runtime/CommonToken.html
根据antlr3python运行时,存在以下方法:https://www.antlr3.org/api/Python/classantlr3_1_1_common_token.html
那么,它们也应该存在于antlr4python运行时?在
如何修复此错误?我是否应该使用不同的方法来获取行号和列号?在
编辑:我的意思是我在这里发现了一个类似的问题:https://github.com/antlr/antlr4/issues/1529。它被标记为bug,但暂时关闭。。。在
如果我查看python3运行时的源代码,就会看到^{} like this :
像这样
^{pr2}$Token
:所以,我想这应该对你有用:
相关问题 更多 >
编程相关推荐