Пример #1
0
    def handle_signature(self, sig: str, signode: desc_signature) -> str:
        """Transform an option description into RST nodes."""
        count = 0
        firstname = ''
        for potential_option in sig.split(', '):
            potential_option = potential_option.strip()
            m = option_desc_re.match(potential_option)
            if not m:
                logger.warning(__(
                    'Malformed option description %r, should '
                    'look like "opt", "-opt args", "--opt args", '
                    '"/opt args" or "+opt args"'),
                               potential_option,
                               location=signode)
                continue
            optname, args = m.groups()
            if optname[-1] == '[' and args[-1] == ']':
                # optional value surrounded by brackets (ex. foo[=bar])
                optname = optname[:-1]
                args = '[' + args

            if count:
                if self.env.config.option_emphasise_placeholders:
                    signode += addnodes.desc_sig_punctuation(',', ',')
                    signode += addnodes.desc_sig_space()
                else:
                    signode += addnodes.desc_addname(', ', ', ')
            signode += addnodes.desc_name(optname, optname)
            if self.env.config.option_emphasise_placeholders:
                add_end_bracket = False
                if args:
                    if args[0] == '[' and args[-1] == ']':
                        add_end_bracket = True
                        signode += addnodes.desc_sig_punctuation('[', '[')
                        args = args[1:-1]
                    elif args[0] == ' ':
                        signode += addnodes.desc_sig_space()
                        args = args.strip()
                    elif args[0] == '=':
                        signode += addnodes.desc_sig_punctuation('=', '=')
                        args = args[1:]
                    for part in samp_role.parse(args):
                        if isinstance(part, nodes.Text):
                            signode += nodes.Text(part.astext())
                        else:
                            signode += part
                if add_end_bracket:
                    signode += addnodes.desc_sig_punctuation(']', ']')
            else:
                signode += addnodes.desc_addname(args, args)
            if not count:
                firstname = optname
                signode['allnames'] = [optname]
            else:
                signode['allnames'].append(optname)
            count += 1
        if not firstname:
            raise ValueError
        return firstname
Пример #2
0
    def handle_signature(self, sig: str, signode: desc_signature) -> Tuple[str, str]:
        """Transform a DML signature into RST nodes.

        Return (fully qualified name of the thing, classname if any).
        """
 
        #relevant info: 
        (typ, name, arglist, annotations) = self.split_signature(sig)

        # determine class name as well as full name
        classname = self.env.ref_context.get('dml:class')
        if classname:
            # class name is not given in the signature
            fullname = classname + '.' + name
        else:
            # It is a class itself, so fullname = name
            classname = ""
            fullname = name
 
        signode['class'] = classname
        signode['fullname'] = fullname
          
        signode += addnodes.desc_annotation(str(typ), str(typ))
        signode += addnodes.desc_sig_space()
        signode += addnodes.desc_name(name, name)
        
        if arglist is not None:
                        
            # diff between None (no arguments) and [] (empty argument list, but brackets will be drawn)
            paramlist = addnodes.desc_parameterlist()
            for arg in arglist:
                
                if isinstance(arg, addnodes.pending_xref):
                    print("add pending xref")
                    paramlist += addnodes.desc_parameter('', '', arg)
                else:
                    paramlist += addnodes.desc_parameter(arg, arg)

            signode += paramlist
        
        if annotations:
            signode += addnodes.desc_sig_space()
            signode += addnodes.desc_sig_operator('', '[')
            addsepertor = False
            for anno in annotations:
                if addsepertor:
                    signode += addnodes.desc_sig_operator('', ',')
                    signode += addnodes.desc_sig_space()
                    
                signode += addnodes.desc_annotation(anno, anno)
                aaddseperator = True
                
            signode += addnodes.desc_sig_operator('', ']')
                           
        return fullname, classname
Пример #3
0
 def get_signature_prefix(self, sig: str) -> tp.List[nodes.Node]:
     prefix = []
     if 'async' in self.options:
         prefix.extend([
             nodes.Text('async'),
             addnodes.desc_sig_space(),
         ])
     prefix.extend([
         qt_type_to_xref(FULL_NAMES[Slot], self.env, suppress_prefix=True),
         addnodes.desc_sig_space()
     ])
     return prefix
Пример #4
0
    def handle_signature(self, sig: str, signode: desc_signature) -> str:
        params = addnodes.desc_parameterlist()
        returns = addnodes.desc_parameterlist()

        contentnode = addnodes.desc_content()
        self.state.nested_parse(self.content, self.content_offset, contentnode)
        for child in contentnode:
            if isinstance(child, nodes.field_list):
                for field in child:
                    ty, sg, name = field[0].astext().split(None, 2)
                    param = addnodes.desc_parameter()
                    param += addnodes.desc_sig_keyword_type(sg, sg)
                    param += addnodes.desc_sig_space()
                    param += addnodes.desc_sig_name(name, name)
                    if ty == "arg":
                        params += param
                    elif ty == "ret":
                        returns += param

        anno = "signal " if self.signal else "method "
        signode += addnodes.desc_annotation(anno, anno)
        signode += addnodes.desc_name(sig, sig)
        signode += params
        if not self.signal and "noreply" not in self.options:
            ret = addnodes.desc_returns()
            ret += returns
            signode += ret

        return sig
Пример #5
0
 def get_signature_prefix(self, sig: str) -> tp.List[nodes.Node]:
     return [
         qt_type_to_xref(FULL_NAMES[Property],
                         self.env,
                         suppress_prefix=True),
         addnodes.desc_sig_space(),
     ]
Пример #6
0
    def handle_signature(self, sig, signode):

        signode += addnodes.desc_annotation("Procedure", "Procedure")
        signode += addnodes.desc_sig_space()

        # parse the path into nodes, including making <> things a parameter
        parts = sig.split('.')
        for part in parts[:-1]:
            if part.startswith("<"):
                part = part[1:-1]
                node = nodes.emphasis()
                node += addnodes.desc_addname(part, part + '.')
                signode += node
            else:
                signode += addnodes.desc_addname(part, part + '.')

        # parse procedure into name and parameters
        fnc = parts[-1].split("(")[0]
        signode += addnodes.desc_name(fnc, fnc)

        params = parts[-1].split("(")[1][:-1].split(",")
        paramlist = addnodes.desc_parameterlist()
        for param in params:
            paramlist += addnodes.desc_parameter(param, param)
        signode += paramlist

        return sig
Пример #7
0
 def describe_signature(self, signode: TextElement) -> None:
     if len(self.attrs) == 0:
         return
     self.attrs[0].describe_signature(signode)
     if len(self.attrs) == 1:
         return
     for attr in self.attrs[1:]:
         signode.append(addnodes.desc_sig_space())
         attr.describe_signature(signode)
Пример #8
0
    def handle_signature(self, sig, signode):

        signode += addnodes.desc_annotation("Uri", "Uri")
        signode += addnodes.desc_sig_space()

        # parse the path into nodes, including making <> things a parameter
        parts = sig.split('.')
        for part in parts:
            if part.startswith("<"):
                part = part[1:-1]
                node = nodes.emphasis()
                node += addnodes.desc_addname(part, part + '.')
                signode += node
            else:
                signode += addnodes.desc_addname(part, part + '.')

        return sig
Пример #9
0
    def handle_signature(self, sig: str,
                         signode: addnodes.desc_signature) -> Tuple[str, str]:
        """Transform a signature/object into RST nodes."""
        try:
            self.obj = BlarkSphinxCache.instance().find_by_name(sig)
        except KeyError:
            self.obj = MissingDeclaration(sig)
            logger.error("Could not find object: %r (signatures unsupported)",
                         sig)
            raise ValueError(f"Code object not found: {sig!r}")

        self.env.ref_context["bk:function"] = self.obj

        signode["ids"] = [sig]
        signode["docname"] = self.env.docname
        signode["qualified_name"] = sig
        domain_data = self.env.domaindata["bk"][self.signature_prefix.lower()]
        domain_data.setdefault(sig, []).append(signode)
        sig_prefix = self.get_signature_prefix(sig)
        signode += addnodes.desc_annotation(str(sig_prefix), '', *sig_prefix)
        signode += addnodes.desc_name(self.obj.name, self.obj.name)

        paramlist = addnodes.desc_parameterlist("paramlist")

        for block in ("VAR_INPUT", "VAR_IN_OUT", "VAR_OUTPUT", "STRUCT"):
            decls = self.obj.declarations_by_block.get(block, {})
            for variable, decl in decls.items():
                node = addnodes.desc_parameter()
                # node += addnodes.desc_sig_operator('', '*')
                node += addnodes.desc_type("", decl.type)
                node += addnodes.desc_sig_space()
                node += addnodes.desc_sig_name("", variable)
                if block == "VAR_OUTPUT":
                    node += addnodes.desc_sig_punctuation(text="=>")

                paramlist += node

        signode += paramlist

        if getattr(self.obj, "return_type", None) is not None:
            signode += addnodes.desc_returns()
            signode += addnodes.desc_type(text=self.obj.return_type)

        prefix = ""
        return sig, prefix
Пример #10
0
 def get_display_prefix(self) -> List[Node]:
     return [addnodes.desc_sig_keyword('class', 'class'),
             addnodes.desc_sig_space()]