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


Python ParserPython.getASG方法代码示例

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


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

示例1: test_direct_rule_call

# 需要导入模块: from arpeggio import ParserPython [as 别名]
# 或者: from arpeggio.ParserPython import getASG [as 别名]
def test_direct_rule_call():
    '''
    Test regression where in direct rule call semantic action is
    erroneously attached to both caller and callee.
    '''

    def grammar():  return rule1, rule2
    def rule1():    return "a"
    def rule2():    return rule1

    call_count = [0]

    class DummySemAction(SemanticAction):
        def first_pass(self, parser, node, nodes):
            call_count[0] += 1
            return SemanticAction.first_pass(self, parser, node, nodes)

    # Sem action is attached to rule2 only but
    # this bug will attach it to rule1 also resulting in
    # wrong call count.
    rule2.sem = DummySemAction()

    parser = ParserPython(grammar)
    parse_tree = parser.parse("aa")
    parser.getASG()

    assert call_count[0] == 1, "Semantic action should be called once!"
开发者ID:Amper,项目名称:Arpeggio,代码行数:29,代码来源:test_direct_rule_call.py

示例2: test_default_action_disabled

# 需要导入模块: from arpeggio import ParserPython [as 别名]
# 或者: from arpeggio.ParserPython import getASG [as 别名]
def test_default_action_disabled():

    parser = ParserPython(grammar)

    parser.parse('(-34) strmatch')

    parser.getASG(defaults=False)

    assert not p_removed
    assert not number_str
    assert parse_tree_node
开发者ID:igordejanovic,项目名称:Arpeggio,代码行数:13,代码来源:test_default_semantic_action.py

示例3: test_semantic_action_results

# 需要导入模块: from arpeggio import ParserPython [as 别名]
# 或者: from arpeggio.ParserPython import getASG [as 别名]
def test_semantic_action_results():

    global first_sar, third_sar

    input = "4 3 3 3 a 3 3 b"

    parser = ParserPython(grammar, reduce_tree=False)
    result = parser.parse(input)

    PTDOTExporter().exportFile(result, 'test_semantic_action_results_pt.dot')

    parser.getASG()

    assert isinstance(first_sar, SemanticActionResults)
    assert len(first_sar.third) == 3
    assert third_sar.third_str[0] == '3'
开发者ID:Avram88,项目名称:Arpeggio,代码行数:18,代码来源:test_semantic_action_results.py

示例4: main

# 需要导入模块: from arpeggio import ParserPython [as 别名]
# 或者: from arpeggio.ParserPython import getASG [as 别名]
def main(debug=False):
    
    parser = ParserPython(initial, debug=debug)
    file_input = open("input.txt", 'r')
   
    input_expr = file_input.read()

    
    parse_tree = parser.parse(input_expr)

    result = parser.getASG()
开发者ID:dusanmaric90,项目名称:WebApp,代码行数:13,代码来源:initial.py

示例5: main

# 需要导入模块: from arpeggio import ParserPython [as 别名]
# 或者: from arpeggio.ParserPython import getASG [as 别名]
def main(debug=False):
    # First we will make a parser - an instance of the calc parser model.
    # Parser model is given in the form of python constructs therefore we
    # are using ParserPython class.
    parser = ParserPython(calc, debug=debug)

    # An expression we want to evaluate
    input_expr = "-(4-1)*5+(2+4.67)+5.89/(.2+7)"

    # We create a parse tree out of textual input_expr
    parse_tree = parser.parse(input_expr)

    result = parser.getASG()

    if debug:
        # getASG will start semantic analysis.
        # In this case semantic analysis will evaluate expression and
        # returned value will be the result of the input_expr expression.
        print("{} = {}".format(input_expr, result))
开发者ID:codeyash,项目名称:plugins,代码行数:21,代码来源:php.py

示例6: language_from_str

# 需要导入模块: from arpeggio import ParserPython [as 别名]
# 或者: from arpeggio.ParserPython import getASG [as 别名]
def language_from_str(language_def, metamodel):
    """
    Constructs parser and initializes metamodel from language description
    given in textX language.

    Args:
        language_def (str): A language description in textX.
        metamodel (TextXMetaModel): A metamodel to initialize.

    Returns:
        Parser for the new language.
    """

    if metamodel.debug:
        metamodel.dprint("*** PARSING LANGUAGE DEFINITION ***")

    # Check the cache for already conctructed textX parser
    if metamodel.debug in textX_parsers:
        parser = textX_parsers[metamodel.debug]
    else:
        # Create parser for TextX descriptions from
        # the textX grammar specified in this module
        parser = ParserPython(textx_model, comment_def=comment,
                              ignore_case=False,
                              reduce_tree=False, debug=metamodel.debug)

        # Prepare regex used in keyword-like strmatch detection.
        # See str_match_SA
        flags = 0
        if metamodel.ignore_case:
            flags = re.IGNORECASE
        parser.keyword_regex = re.compile(r'[^\d\W]\w*', flags)

        # Cache it for subsequent calls
        textX_parsers[metamodel.debug] = parser

    # This is used during parser construction phase.
    # Metamodel is filled in. Classes are created based on grammar rules.
    parser.metamodel = metamodel

    # Builtin rules representing primitive types
    parser.root_rule_name = None

    # Parse language description with textX parser
    try:
        parser.parse(language_def)
    except NoMatch as e:
        line, col = parser.pos_to_linecol(e.position)
        raise TextXSyntaxError(text(e), line, col)

    # Construct new parser based on the given language description.
    lang_parser = parser.getASG()

    # Meta-model is constructed. Validate semantics of metamodel.
    parser.metamodel.validate()

    # Meta-model is constructed. Here we connect meta-model and language
    # parser for convenience.
    lang_parser.metamodel = parser.metamodel
    metamodel.parser = lang_parser

    if metamodel.debug:
        # Create dot file for debuging purposes
        PMDOTExporter().exportFile(
            lang_parser.parser_model,
            "{}_parser_model.dot".format(metamodel.rootcls.__name__))

    return lang_parser
开发者ID:zeph,项目名称:textX,代码行数:70,代码来源:textx.py


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