Merge pull request #1551 from KvanTTT/master

fix 'CommonToken' object has no attribute 'stopIndex' in Python{2|3}
This commit is contained in:
Terence Parr 2016-12-24 10:29:31 -08:00 committed by GitHub
commit 0774117889
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)