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


Python pygram.python_grammar_no_print_statement方法代码示例

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


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

示例1: lib2to3_parse

# 需要导入模块: from lib2to3 import pygram [as 别名]
# 或者: from lib2to3.pygram import python_grammar_no_print_statement [as 别名]
def lib2to3_parse(src_txt):
    """Given a string with source, return the lib2to3 Node."""
    grammar = pygram.python_grammar_no_print_statement
    drv = driver.Driver(grammar, pytree.convert)
    if src_txt[-1] != "\n":
        nl = "\r\n" if "\r\n" in src_txt[:1024] else "\n"
        src_txt += nl
    try:
        result = drv.parse_string(src_txt, True)
    except ParseError as pe:
        lineno, column = pe.context[1]
        lines = src_txt.splitlines()
        try:
            faulty_line = lines[lineno - 1]
        except IndexError:
            faulty_line = "<line number missing in source>"
        raise ValueError(f"Cannot parse: {lineno}:{column}: {faulty_line}") from None

    if isinstance(result, Leaf):
        result = Node(syms.file_input, [result])

    return result 
开发者ID:ambv,项目名称:retype,代码行数:24,代码来源:__init__.py

示例2: test_print_function_option

# 需要导入模块: from lib2to3 import pygram [as 别名]
# 或者: from lib2to3.pygram import python_grammar_no_print_statement [as 别名]
def test_print_function_option(self):
        rt = self.rt({"print_function" : True})
        self.assertIs(rt.grammar, pygram.python_grammar_no_print_statement)
        self.assertIs(rt.driver.grammar,
                      pygram.python_grammar_no_print_statement) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:7,代码来源:test_refactor.py

示例3: test_idempotency_print_as_function

# 需要导入模块: from lib2to3 import pygram [as 别名]
# 或者: from lib2to3.pygram import python_grammar_no_print_statement [as 别名]
def test_idempotency_print_as_function(self):
        self.refactor.driver.grammar = pygram.python_grammar_no_print_statement
        s = """print(1, 1+1, 1+1+1)"""
        self.unchanged(s)

        s = """print()"""
        self.unchanged(s)

        s = """print('')"""
        self.unchanged(s) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:12,代码来源:test_fixers.py

示例4: test_print_function_option

# 需要导入模块: from lib2to3 import pygram [as 别名]
# 或者: from lib2to3.pygram import python_grammar_no_print_statement [as 别名]
def test_print_function_option(self):
        rt = self.rt({"print_function" : True})
        self.assertTrue(rt.grammar is pygram.python_grammar_no_print_statement)
        self.assertTrue(rt.driver.grammar is
                        pygram.python_grammar_no_print_statement) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:7,代码来源:test_refactor.py

示例5: LastLeafNode

# 需要导入模块: from lib2to3 import pygram [as 别名]
# 或者: from lib2to3.pygram import python_grammar_no_print_statement [as 别名]
def LastLeafNode(node):
  if isinstance(node, pytree.Leaf):
    return node
  return LastLeafNode(node.children[-1])


# lib2to3 thoughtfully provides pygram.python_grammar_no_print_statement for
# parsing Python 3 code that wouldn't parse otherwise (when 'print' is used in a
# context where a keyword is disallowed).
# It forgets to do the same for 'exec' though. Luckily, Python is amenable to
# monkey-patching. 
开发者ID:google,项目名称:yapf,代码行数:13,代码来源:pytree_utils.py


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