本文整理汇总了Python中antlr4.error.ErrorListener.ErrorListener方法的典型用法代码示例。如果您正苦于以下问题:Python ErrorListener.ErrorListener方法的具体用法?Python ErrorListener.ErrorListener怎么用?Python ErrorListener.ErrorListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类antlr4.error.ErrorListener
的用法示例。
在下文中一共展示了ErrorListener.ErrorListener方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from antlr4.error import ErrorListener [as 别名]
# 或者: from antlr4.error.ErrorListener import ErrorListener [as 别名]
def __init__(self, src):
super(ErrorListener, self).__init__()
self.src = src
示例2: split
# 需要导入模块: from antlr4.error import ErrorListener [as 别名]
# 或者: from antlr4.error.ErrorListener import ErrorListener [as 别名]
def split(self, path:str):
input = InputStream(path)
lexer = XPathLexer(input)
def recover(self, e):
raise e
lexer.recover = recover
lexer.removeErrorListeners()
lexer.addErrorListener(ErrorListener()) # XPathErrorListener does no more
tokenStream = CommonTokenStream(lexer)
try:
tokenStream.fill()
except LexerNoViableAltException as e:
pos = lexer.getColumn()
msg = "Invalid tokens or characters at index " + str(pos) + " in path '" + path + "'"
raise Exception(msg, e)
tokens = tokenStream.getTokens()
elements = list()
n = len(tokens)
i=0
while i < n :
el = tokens[i]
next = None
if el.type in [XPathLexer.ROOT, XPathLexer.ANYWHERE]:
anywhere = el.type == XPathLexer.ANYWHERE
i += 1
next = tokens[i]
invert = next.type==XPathLexer.BANG
if invert:
i += 1
next = tokens[i]
pathElement = self.getXPathElement(next, anywhere)
pathElement.invert = invert
elements.append(pathElement)
i += 1
elif el.type in [XPathLexer.TOKEN_REF, XPathLexer.RULE_REF, XPathLexer.WILDCARD] :
elements.append( self.getXPathElement(el, False) )
i += 1
elif el.type==Token.EOF :
break
else:
raise Exception("Unknown path element " + str(el))
return elements
#
# Convert word like {@code#} or {@code ID} or {@code expr} to a path
# element. {@code anywhere} is {@code true} if {@code //} precedes the
# word.
#