当前位置: 首页>>代码示例>>Python>>正文


Python antlr4.ParseTreeWalker方法代码示例

本文整理汇总了Python中antlr4.ParseTreeWalker方法的典型用法代码示例。如果您正苦于以下问题:Python antlr4.ParseTreeWalker方法的具体用法?Python antlr4.ParseTreeWalker怎么用?Python antlr4.ParseTreeWalker使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在antlr4的用法示例。


在下文中一共展示了antlr4.ParseTreeWalker方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run_parser

# 需要导入模块: import antlr4 [as 别名]
# 或者: from antlr4 import ParseTreeWalker [as 别名]
def run_parser(quil):
    # type: (str) -> List[AbstractInstruction]
    """
    Run the ANTLR parser.

    :param str quil: a single or multiline Quil program
    :return: list of instructions that were parsed
    """
    # Step 1: Run the Lexer
    input_stream = InputStream(quil)
    lexer = QuilLexer(input_stream)
    stream = CommonTokenStream(lexer)

    # Step 2: Run the Parser
    parser = QuilParser(stream)
    parser.removeErrorListeners()
    parser.addErrorListener(CustomErrorListener())
    tree = parser.quil()

    # Step 3: Run the Listener
    pyquil_listener = PyQuilListener()
    walker = ParseTreeWalker()
    walker.walk(pyquil_listener, tree)

    return pyquil_listener.result 
开发者ID:rigetti,项目名称:pyquil,代码行数:27,代码来源:PyQuilListener.py

示例2: _parse_input_stream

# 需要导入模块: import antlr4 [as 别名]
# 或者: from antlr4 import ParseTreeWalker [as 别名]
def _parse_input_stream(input_stream: antlr4.InputStream) -> RootNode:
    error_listener = _ConsoleErrorListener()

    lexer = JSONPathLexer(input_stream)

    lexer.addErrorListener(error_listener)

    token_stream = antlr4.CommonTokenStream(lexer)

    parser = _JSONPathParser(token_stream)

    parser.addErrorListener(error_listener)

    tree = parser.jsonpath()

    listener = _JSONPathListener(_stack=[])

    walker = antlr4.ParseTreeWalker()
    walker.walk(listener, tree)

    # pylint: disable=protected-access
    return listener._stack.pop()
    # pylint: enable=protected-access 
开发者ID:pacifica,项目名称:python-jsonpath2,代码行数:25,代码来源:__init__.py

示例3: _parse_boolexpr

# 需要导入模块: import antlr4 [as 别名]
# 或者: from antlr4 import ParseTreeWalker [as 别名]
def _parse_boolexpr(self, s):
        lexer = BoolExprLexer(
            antlr4.InputStream(s)
        )
        stream = antlr4.CommonTokenStream(lexer)
        parser = BoolExprParser(stream)
        tree = parser.booleanExpression()

        eb = _BECompiler()
        walker = antlr4.ParseTreeWalker()
        walker.walk(eb, tree)

        return eb.expression, eb.comparator, eb.value 
开发者ID:PaloAltoNetworks,项目名称:minemeld-core,代码行数:15,代码来源:interface.py

示例4: _parse_string

# 需要导入模块: import antlr4 [as 别名]
# 或者: from antlr4 import ParseTreeWalker [as 别名]
def _parse_string(s):
    lexer = minemeld.ft.condition.BoolExprLexer(
        antlr4.InputStream(s)
    )
    stream = antlr4.CommonTokenStream(lexer)
    parser = minemeld.ft.condition.BoolExprParser(stream)
    tree = parser.booleanExpression()

    eb = ExprBuilder()
    walker = antlr4.ParseTreeWalker()
    walker.walk(eb, tree)

    return eb 
开发者ID:PaloAltoNetworks,项目名称:minemeld-core,代码行数:15,代码来源:test_ft_boolexpr.py

示例5: parse

# 需要导入模块: import antlr4 [as 别名]
# 或者: from antlr4 import ParseTreeWalker [as 别名]
def parse(self, equel):
        lexer = equelLexer(equel)
        tokenstream = CommonTokenStream(lexer)
        parser = equelParser(tokenstream)
        parsetree = parser.equel()
        walker = ParseTreeWalker()
        listener = EQUELParserListener(self.engine)
        walker.walk(listener, parsetree)
        return parsetree 
开发者ID:thomaspatzke,项目名称:EQUEL,代码行数:11,代码来源:parser.py

示例6: parse

# 需要导入模块: import antlr4 [as 别名]
# 或者: from antlr4 import ParseTreeWalker [as 别名]
def parse(self, input, trace = False):
        if self.useDatabase:
            self.db = model.A2LDatabase(self.fnbase, debug = self.debug)
        lexer = self.lexerClass(input)
        lexer.removeErrorListeners()
        lexer.addErrorListener(MyErrorListener())
        tokenStream = antlr4.CommonTokenStream(lexer)
#        tokenStream = BufferedTokenStream(lexer)
        parser = self.parserClass(tokenStream)
        parser.setTrace(trace)
        parser.removeErrorListeners()
        parser.addErrorListener(MyErrorListener())
        meth = getattr(parser, self.startSymbol)
        self._syntaxErrors = parser._syntaxErrors
        tree = meth()
        if self.listener:
            if self.useDatabase:
                self.listener.db = self.db
            listener = self.listener()
            walker = antlr4.ParseTreeWalker()
            result = walker.walk(listener, tree)
        if self.useDatabase:
            self.db.session.commit()
            return self.db.session
        else:
            return listener 
开发者ID:christoph2,项目名称:pyA2L,代码行数:28,代码来源:parserlib.py

示例7: parse

# 需要导入模块: import antlr4 [as 别名]
# 或者: from antlr4 import ParseTreeWalker [as 别名]
def parse(text):
    input_stream = antlr4.InputStream(text)
    lexer = ModelicaLexer(input_stream)
    stream = antlr4.CommonTokenStream(lexer)
    parser = ModelicaParser(stream)
    # parser.buildParseTrees = False
    parse_tree = parser.stored_definition()
    ast_listener = ASTListener()
    parse_walker = antlr4.ParseTreeWalker()
    parse_walker.walk(ast_listener, parse_tree)
    modelica_file = ast_listener.ast_result
    return file_to_tree(modelica_file) 
开发者ID:pymoca,项目名称:pymoca,代码行数:14,代码来源:parser.py


注:本文中的antlr4.ParseTreeWalker方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。