當前位置: 首頁>>代碼示例>>Python>>正文


Python ErrorListener.ErrorListener方法代碼示例

本文整理匯總了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 
開發者ID:augustt198,項目名稱:latex2sympy,代碼行數:5,代碼來源:process_latex.py

示例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.
    # 
開發者ID:FederatedAI,項目名稱:FATE,代碼行數:55,代碼來源:XPath.py


注:本文中的antlr4.error.ErrorListener.ErrorListener方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。