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


Python token.COLON属性代码示例

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


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

示例1: classdef

# 需要导入模块: import token [as 别名]
# 或者: from token import COLON [as 别名]
def classdef(self, nodelist):
        # classdef: 'class' NAME ['(' [testlist] ')'] ':' suite

        name = nodelist[1][1]
        doc = self.get_docstring(nodelist[-1])
        if nodelist[2][0] == token.COLON:
            bases = []
        elif nodelist[3][0] == token.RPAR:
            bases = []
        else:
            bases = self.com_bases(nodelist[3])

        # code for class
        code = self.com_node(nodelist[-1])

        if doc is not None:
            assert isinstance(code, Stmt)
            assert isinstance(code.nodes[0], Discard)
            del code.nodes[0]

        return Class(name, bases, doc, code, lineno=nodelist[1][2]) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:23,代码来源:transformer.py

示例2: com_subscriptlist

# 需要导入模块: import token [as 别名]
# 或者: from token import COLON [as 别名]
def com_subscriptlist(self, primary, nodelist, assigning):
        # slicing:      simple_slicing | extended_slicing
        # simple_slicing:   primary "[" short_slice "]"
        # extended_slicing: primary "[" slice_list "]"
        # slice_list:   slice_item ("," slice_item)* [","]

        # backwards compat slice for '[i:j]'
        if len(nodelist) == 2:
            sub = nodelist[1]
            if (sub[1][0] == token.COLON or \
                            (len(sub) > 2 and sub[2][0] == token.COLON)) and \
                            sub[-1][0] != symbol.sliceop:
                return self.com_slice(primary, sub, assigning)

        subscripts = []
        for i in range(1, len(nodelist), 2):
            subscripts.append(self.com_subscript(nodelist[i]))
        return Subscript(primary, assigning, subscripts,
                         lineno=extractLineNo(nodelist)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:21,代码来源:transformer.py

示例3: com_dictorsetmaker

# 需要导入模块: import token [as 别名]
# 或者: from token import COLON [as 别名]
def com_dictorsetmaker(self, nodelist):
        # dictorsetmaker: ( (test ':' test (comp_for | (',' test ':' test)* [','])) |
        #                   (test (comp_for | (',' test)* [','])) )
        assert nodelist[0] == symbol.dictorsetmaker
        nodelist = nodelist[1:]
        if len(nodelist) == 1 or nodelist[1][0] == token.COMMA:
            # set literal
            items = []
            for i in range(0, len(nodelist), 2):
                items.append(self.com_node(nodelist[i]))
            return Set(items, lineno=items[0].lineno)
        elif nodelist[1][0] == symbol.comp_for:
            # set comprehension
            expr = self.com_node(nodelist[0])
            return self.com_comprehension(expr, None, nodelist[1], 'set')
        elif len(nodelist) > 3 and nodelist[3][0] == symbol.comp_for:
            # dict comprehension
            assert nodelist[1][0] == token.COLON
            key = self.com_node(nodelist[0])
            value = self.com_node(nodelist[2])
            return self.com_comprehension(key, value, nodelist[3], 'dict')
        else:
            # dict literal
            items = []
            for i in range(0, len(nodelist), 4):
                items.append((self.com_node(nodelist[i]),
                              self.com_node(nodelist[i+2])))
            return Dict(items, lineno=items[0][0].lineno) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:30,代码来源:transformer.py

示例4: com_subscript

# 需要导入模块: import token [as 别名]
# 或者: from token import COLON [as 别名]
def com_subscript(self, node):
        # slice_item: expression | proper_slice | ellipsis
        ch = node[1]
        t = ch[0]
        if t == token.DOT and node[2][0] == token.DOT:
            return Ellipsis()
        if t == token.COLON or len(node) > 2:
            return self.com_sliceobj(node)
        return self.com_node(ch) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:11,代码来源:transformer.py

示例5: com_sliceobj

# 需要导入模块: import token [as 别名]
# 或者: from token import COLON [as 别名]
def com_sliceobj(self, node):
        # proper_slice: short_slice | long_slice
        # short_slice:  [lower_bound] ":" [upper_bound]
        # long_slice:   short_slice ":" [stride]
        # lower_bound:  expression
        # upper_bound:  expression
        # stride:       expression
        #
        # Note: a stride may be further slicing...

        items = []

        if node[1][0] == token.COLON:
            items.append(Const(None))
            i = 2
        else:
            items.append(self.com_node(node[1]))
            # i == 2 is a COLON
            i = 3

        if i < len(node) and node[i][0] == symbol.test:
            items.append(self.com_node(node[i]))
            i = i + 1
        else:
            items.append(Const(None))

        # a short_slice has been built. look for long_slice now by looking
        # for strides...
        for j in range(i, len(node)):
            ch = node[j]
            if len(ch) == 2:
                items.append(Const(None))
            else:
                items.append(self.com_node(ch[2]))
        return Sliceobj(items, lineno=extractLineNo(node)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:37,代码来源:transformer.py


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