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


Python Node.wrapped方法代码示例

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


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

示例1: reworkElse

# 需要导入模块: from jasy.js.parse.Node import Node [as 别名]
# 或者: from jasy.js.parse.Node.Node import wrapped [as 别名]
def reworkElse(node, elsePart):
    """ 
    If an if ends with a return/throw we are able to inline the content 
    of the else to the same parent as the if resides into. This method
    deals with all the nasty details of this operation.
    """
    
    target = node.parent
    targetIndex = target.index(node)+1

    # A workaround for compact if-else blocks
    # We are a elsePart of the if where we want to move our
    # content to. This cannot work. So we need to wrap ourself
    # into a block and move the else statements to this newly
    # established block
    if not target.type in ("block","script"):
        newBlock = Node(None, "block")
        newBlock.wrapped = True
        
        # Replace node with newly created block and put ourself into it
        node.parent.replace(node, newBlock)
        newBlock.append(node)
        
        # Update the target and the index
        target = newBlock
        targetIndex = 1
        
    if not target.type in ("block", "script"):
        # print("No possible target found/created")
        return elsePart
        
    if elsePart.type == "block":
        for child in reversed(elsePart):
            target.insert(targetIndex, child)

        # Remove else block from if statement
        node.remove(elsePart)
            
    else:
        target.insert(targetIndex, elsePart)
        
    return  
开发者ID:csakatoku,项目名称:jasy,代码行数:44,代码来源:BlockReducer.py


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