fix error "'CommonToken' object has no attribute 'stopIndex' in Python{2|3}" #1529.

This commit is contained in:
Ivan Kochurkin 2016-12-24 18:22:48 +03:00
parent df142794f6
commit 03a75a5ce6
2 changed files with 6 additions and 6 deletions

View File

@ -59,12 +59,12 @@ class ListTokenSource(TokenSource):
# have to calculate the result from the line/column of the previous
# token, along with the text of the token.
lastToken = self.tokens[len(self.tokens) - 1]
tokenText = lastToken.getText()
tokenText = lastToken.text
if tokenText is not None:
lastNewLine = tokenText.rfind('\n')
if lastNewLine >= 0:
return len(tokenText) - lastNewLine - 1
return lastToken.column + lastToken.stopIndex - lastToken.startIndex + 1
return lastToken.column + lastToken.stop - lastToken.start + 1
# only reach this if tokens is empty, meaning EOF occurs at the first
# position in the input
@ -78,7 +78,7 @@ class ListTokenSource(TokenSource):
if self.eofToken is None:
start = -1
if len(self.tokens) > 0:
previousStop = self.tokens[len(self.tokens) - 1].stopIndex
previousStop = self.tokens[len(self.tokens) - 1].stop
if previousStop != -1:
start = previousStop + 1
stop = max(-1, start - 1)

View File

@ -59,12 +59,12 @@ class ListTokenSource(TokenSource):
# have to calculate the result from the line/column of the previous
# token, along with the text of the token.
lastToken = self.tokens[len(self.tokens) - 1]
tokenText = lastToken.getText()
tokenText = lastToken.text
if tokenText is not None:
lastNewLine = tokenText.rfind('\n')
if lastNewLine >= 0:
return len(tokenText) - lastNewLine - 1
return lastToken.column + lastToken.stopIndex - lastToken.startIndex + 1
return lastToken.column + lastToken.stop - lastToken.start + 1
# only reach this if tokens is empty, meaning EOF occurs at the first
# position in the input
@ -78,7 +78,7 @@ class ListTokenSource(TokenSource):
if self.eofToken is None:
start = -1
if len(self.tokens) > 0:
previousStop = self.tokens[len(self.tokens) - 1].stopIndex
previousStop = self.tokens[len(self.tokens) - 1].stop
if previousStop != -1:
start = previousStop + 1
stop = max(-1, start - 1)