• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python fmt.block函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pyrser.fmt.block函数的典型用法代码示例。如果您正苦于以下问题:Python block函数的具体用法?Python block怎么用?Python block使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: to_fmt

def to_fmt(self):
    """
    Return an Fmt representation for pretty-printing
    """
    qual = "evalctx"
    lseval = []
    block = fmt.block(":\n", "", fmt.tab(lseval))
    txt = fmt.sep(" ", [qual, block])
    lseval.append(self._sig.to_fmt())
    if len(self.resolution) > 0:
        lsb = []
        for k in sorted(self.resolution.keys()):
            s = self.resolution[k]
            if s is not None:
                lsb.append(fmt.end("\n", ["'%s': %s (%s)" % (k, s, s().show_name())]))
            else:
                lsb.append(fmt.end("\n", ["'%s': Unresolved" % (k)]))
        if self._translate_to is not None:
            lsb.append("use translator:")
            lsb.append(self._translate_to.to_fmt())
        if self._variadic_types is not None:
            lsb.append("variadic types:\n")
            arity = self._sig.arity
            for t in self._variadic_types:
                lsb.append("[%d] : %s\n" % (arity, t))
                arity += 1
        lseval.append(fmt.block("\nresolution :\n", "", fmt.tab(lsb)))
    return txt
开发者ID:vhb,项目名称:pyrser,代码行数:28,代码来源:to_fmt.py


示例2: to_fmt

 def to_fmt(self) -> fmt.indentable:
     key = '*'
     if self.key is not None:
         key = repr(self.key)
     res = fmt.block('{' + key + ': ', '}', [])
     res.lsdata.append(self.v.to_fmt())
     return res
开发者ID:Atch0um,项目名称:pyrser,代码行数:7,代码来源:match.py


示例3: to_c

def to_c(self):
    return fmt.sep(
        "",
        [
            self.call_expr.to_c(),  # expr
            fmt.block('[', ']', [self.params[0].to_c()])  # index
        ]
    )
开发者ID:Py0s,项目名称:KooC,代码行数:8,代码来源:to_c.py


示例4: to_tl4t

 def to_tl4t(self) -> fmt.indentable:
     lssub = []
     for s in self.body:
         lssub.append(s.to_tl4t())
     lsblock = None
     if self.root:
         lsblock = fmt.sep('', lssub)
     else:
         lsblock = fmt.block('{\n', '}', [fmt.tab(lssub)])
     return lsblock
开发者ID:Atch0um,项目名称:pyrser,代码行数:10,代码来源:tl4t.py


示例5: to_fmt

 def to_fmt(self) -> fmt.indentable:
     res = fmt.sep('', [])
     if self.t is not object:
         res.lsdata.append(self.t.__name__)
     else:
         res.lsdata.append('*')
     iparen = []
     if self.attrs is not None:
         # TODO: render unknown attr (.?) at the end after ..., also unknown attr implie 'unstrict' mode
         iparen = fmt.sep(', ', [])
         for a in self.attrs:
             iparen.lsdata.append(a.to_fmt())
     if not self.strict:
         iparen.lsdata.append('...')
     if self.iskindof:
         paren = fmt.block('^(', ')', iparen)
     else:
         paren = fmt.block('(', ')', iparen)
     res.lsdata.append(paren)
     return res
开发者ID:vhb,项目名称:pyrser,代码行数:20,代码来源:match.py


示例6: to_fmt

 def to_fmt(self) -> fmt.indentable:
     res = None
     showlist = {
         'attr': {
             "res": fmt.sep('', ['.']),
             "inblock": fmt.sep('=', [self.value])
         },
         'indice': {
             "res": fmt.block('[', ']', []),
             "inblock": fmt.sep(': ', [repr(self.value)])
         },
         'key': {
             "res": fmt.block('{', '}', []),
             "inblock": fmt.sep(': ', [repr(self.value)])
         }
         }
     for k in sorted(showlist.keys()):
         v = showlist[k]
         if self.kind == CaptureContext.kind_of_node[k]:
             res = v["res"]
             inblock = v["inblock"]
             if self.node is not None:
                 if hasattr(self.node, 'to_fmt'):
                     inblock.lsdata.append(self.node.to_fmt())
                 elif type(self.node) is weakref.ReferenceType:
                     inblock.lsdata.append(repr(self.get()))
             res.lsdata.append(inblock)
     ######
     if self.kind == CaptureContext.kind_of_node['node']:
         res = fmt.sep('', [self.value])
         elmts = fmt.sep(',\n', [])
         for sk in sorted(CaptureContext.map_intern.values()):
             subelmt = None
             if hasattr(self, sk):
                 subelmt = getattr(self, sk)
             if subelmt is not None:
                 for sube in subelmt:
                     elmts.lsdata.append(sube.to_fmt())
         se = fmt.tab(fmt.block('(\n', '\n)', elmts))
         res.lsdata.append(se)
     return res
开发者ID:Thiryn,项目名称:pyrser_patch,代码行数:41,代码来源:state.py


示例7: to_fmt

 def to_fmt(self) -> fmt.indentable:
     """
     Return an Fmt representation for pretty-printing
     """
     lsb = []
     if len(self._lsig) > 0:
         for s in self._lsig:
             lsb.append(s.to_fmt())
     block = fmt.block("(", ")", fmt.sep(', ', lsb))
     qual = "tuple"
     txt = fmt.sep("", [qual, block])
     return txt
开发者ID:Atch0um,项目名称:pyrser,代码行数:12,代码来源:tuple.py


示例8: to_fmt

 def to_fmt(self) -> fmt.indentable:
     txt = fmt.sep("", [self.name])
     if len(self.attributes) > 0:
         lsattr = fmt.sep(", ", [])
         lkey = sorted(self.attributes.keys())
         for k in lkey:
             t = k
             if self.attributes[k] is not None:
                 t += '=' + str(self.attributes[k])
             lsattr.lsdata.append(t)
         txt.lsdata.append(fmt.block("[", "]", lsattr))
     return txt
开发者ID:Atch0um,项目名称:pyrser,代码行数:12,代码来源:type_expr.py


示例9: to_fmt

 def to_fmt(self) -> str:
     """
     Provide a useful representation of the register.
     """
     infos = fmt.end(";\n", [])
     s = fmt.sep(', ', [])
     for ids in sorted(self.states.keys()):
         s.lsdata.append(str(ids))
     infos.lsdata.append(fmt.block('(', ')', [s]))
     infos.lsdata.append("events:" + repr(self.events))
     infos.lsdata.append("named_events:" + repr(list(self.named_events.keys())))
     infos.lsdata.append("uid_events:" + repr(list(self.uid_events.keys())))
     return infos
开发者ID:vhb,项目名称:pyrser,代码行数:13,代码来源:state.py


示例10: to_yml_item

def to_yml_item(item, pp, name):
    global scalar
    refcount = weakref.getweakrefcount(item)
    if refcount > 0:
        name += " &" + str(id(item))
    if type(item).__name__ in scalar:
        tag = fmt.end(
            '\n',
            fmt.sep(
                "",
                [
                    name,
                    " ",
                    yml_attr(
                        type(item).__name__,
                        repr(item)
                    )
                ]
            )
        )
        pp.append(tag)
        return
    if isinstance(item, weakref.ref):
        name += " *" + str(id(item()))
        tag = fmt.end('\n', fmt.sep("", [name, " ", repr(item)]))
        pp.append(tag)
        return
    if isinstance(item, bytes) or isinstance(item, bytearray):
        inner = fmt.tab([])
        tag = fmt.block(name + " " + str(yml_attr('type', 'bytes')) + ':\n',
                        '----' + name + '----\n', inner)
        inner.lsdata.append(fmt.sep(" ", []))
        bindata = inner.lsdata[-1].lsdata
        i = 0
        for b in item:
            bindata.append("%02X" % b)
            i += 1
            if i > 16:
                bindata.append("\n")
                i = 0
        bindata.append("\n")
        pp.append(tag)
        return
    if isinstance(item, object) and hasattr(item, '__dict__'):
        inner = fmt.tab([])
        tag = fmt.block(name + " " +
                        str(yml_attr('type', item.__class__.__name__))
                        + ':\n',
                        '', inner)
        for attr in sorted(vars(item)):
            to_yml_item(getattr(item, attr), inner.lsdata, attr)
        if len(vars(item)) == 0:
            inner.lsdata.append("\n")
        pp.append(tag)
        return
    if isinstance(item, list):
        inner = fmt.tab([])
        tag = fmt.block(
            name + " " + str(yml_attr('type', 'list')) + ':\n',
            '',
            inner
        )
        i = 0
        for subitem in item:
            idxname = str(fmt.sep(" ", ['[', i, ']']))
            to_yml_item(subitem, inner.lsdata, idxname)
            i += 1
        if len(item) == 0:
            inner.lsdata.append("\n")
        pp.append(tag)
        return
    if isinstance(item, tuple):
        inner = fmt.tab([])
        tag = fmt.block(name + " " + str(yml_attr('type', 'tuple')) + ':\n',
                        '', inner)
        i = 0
        for subitem in item:
            idxname = str(fmt.sep(" ", ["[", i, "]"]))
            to_yml_item(subitem, inner.lsdata, idxname)
            i += 1
        if len(item) == 0:
            inner.lsdata.append("\n")
        pp.append(tag)
        return
    if isinstance(item, dict):
        inner = fmt.tab([])
        tag = fmt.block(name + " " + str(yml_attr('type', 'dict')) + ':\n',
                        '', inner)
        for k in sorted(item.keys()):
            idxname = str(fmt.sep(" ", ["[", repr(k), "]"]))
            to_yml_item(item[k], inner.lsdata, idxname)
        if len(item.keys()) == 0:
            inner.lsdata.append("\n")
        pp.append(tag)
        return
    if isinstance(item, set):
        inner = fmt.tab([])
        tag = fmt.block(name + " " + str(yml_attr('type', 'set')) + ':\n',
                        '', inner)
        for subitem in sorted(item):
#.........这里部分代码省略.........
开发者ID:Py0s,项目名称:KooC,代码行数:101,代码来源:to_yml.py


示例11: ctype_to_c

def ctype_to_c(self, func_var_name=""):
    # our global declarator
    declarator = fmt.sep("", [])
    # typename or full decl
    if func_var_name != "":
        declarator.lsdata.append(func_var_name)
    # intern prototype
    if hasattr(self, 'params'):
        # param list
        pf = fmt.sep(", ", [])
        for p in self.params:
            if p.ctype is not None:
                if isinstance(p.ctype, nodes.CType):
                    pf.lsdata.append(p.ctype.ctype_to_c(p._name))
        if hasattr(self, '_ellipsis'):
            pf.lsdata.append('...')
        if len(pf.lsdata) > 0:
            declarator.lsdata.append(fmt.block('(', ')',  pf))
        else:
            declarator.lsdata.append('()')
    # for externalize the last qualifier
    qualextern = None
    # final output
    decl_ls = fmt.sep(" ", [])
    if self.link() is not None:
        # add all qualifiers
        if len(declarator.lsdata) > 0:
            qual_list = declarator
        else:
            qual_list = fmt.sep(" ", [])
        unqual_list = self.link()
        # qualification of declaration
        while unqual_list is not None:
            if isinstance(unqual_list, nodes.ParenType):
                # surround previous defs by ()
                qual_list = fmt.sep("", [fmt.block("(", ")", [qual_list])])
                # () provide param for function pointers
                if len(unqual_list.params) > 0:
                    pf = fmt.sep(", ", [])
                    for p in unqual_list.params:
                        pf.lsdata.append(p.ctype.ctype_to_c(p._name))
                    if hasattr(unqual_list, '_ellipsis'):
                        pf.lsdata.append('...')
                    qual_list.lsdata.append(fmt.block('(', ')', pf))
            if isinstance(unqual_list, nodes.PointerType):
                qual_list.lsdata.insert(0, "*")
            if isinstance(unqual_list, nodes.AttrType):
                qual_list.lsdata.insert(0, unqual_list._attr + " ")
            if isinstance(unqual_list, nodes.QualType):
                if unqual_list._qualifier != nodes.Qualifiers.AUTO:
                    if unqual_list.link() is None:
                        qualextern = unqual_list
                    else:
                        qual_list.lsdata.insert(
                            0,
                            nodes.Qualifiers.rmap[
                                unqual_list._qualifier
                            ].lower() + " "
                        )
            if isinstance(unqual_list, nodes.ArrayType):
                # collect all consecutive array
                consec_ary = []
                consec_ary.append(unqual_list)
                unqual_list = unqual_list.link()
                while ((unqual_list is not None
                        and isinstance(unqual_list, nodes.ArrayType))):
                    consec_ary.append(unqual_list)
                    unqual_list = unqual_list.link()
                reordered = []
                for ary in consec_ary:
                    if ary.expr is not None:
                        ary_expr = None
                        if hasattr(ary.expr, 'to_c'):
                            ary_expr = ary.expr.to_c()
                        reordered.insert(0, fmt.block("[", "]", [ary_expr]))
                    else:
                        reordered.insert(0, "[]")
                qual_list.lsdata.extend(reordered)
                # rewind one for last sentence
                unqual_list = consec_ary[-1]
            unqual_list = unqual_list.link()
        # add qualified declarator
        decl_ls.lsdata.append(qual_list)
    elif len(declarator.lsdata) > 0:
        # no qualifiers just the name
        decl_ls.lsdata.append(declarator)
    # for enum
    if hasattr(self, 'enums'):
        enums = fmt.sep(",\n", [])
        for enum in self.enums:
            if enum.expr is not None and hasattr(enum.expr, 'to_c'):
                enums.lsdata.append(
                    fmt.sep(
                        " = ",
                        [enum.ident, enum.expr.to_c()]
                    ))
            else:
                enums.lsdata.append(enum.ident)
        decl_ls.lsdata.insert(0, fmt.tab(fmt.block("{\n", "}", enums)))
    # for struct
#.........这里部分代码省略.........
开发者ID:Py0s,项目名称:KooC,代码行数:101,代码来源:to_c.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python fmt.sep函数代码示例发布时间:2022-05-27
下一篇:
Python testutils.fix_indent函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap