Python3 XPath: Use Token.INVALID_TYPE instead of -1 on getXPathElement

This commit is contained in:
João Henrique 2019-09-05 14:29:25 -03:00
parent b0eb1825fb
commit ae28213343
1 changed files with 2 additions and 2 deletions

View File

@ -218,7 +218,7 @@ class XPath(object):
elif wordToken.type in [XPathLexer.TOKEN_REF, XPathLexer.STRING]:
tsource = self.parser.getTokenStream().tokenSource
ttype = -1
ttype = Token.INVALID_TYPE
if wordToken.type == XPathLexer.TOKEN_REF:
if word in tsource.ruleNames:
ttype = tsource.ruleNames.index(word) + 1
@ -226,7 +226,7 @@ class XPath(object):
if word in tsource.literalNames:
ttype = tsource.literalNames.index(word)
if ttype == -1:
if ttype == Token.INVALID_TYPE:
raise Exception("%s at index %d isn't a valid token name" % (word, wordToken.tokenIndex))
return XPathTokenAnywhereElement(word, ttype) if anywhere else XPathTokenElement(word, ttype)