Esempio n. 1
0
def parse_macro(env, sig, signode):
    #import rpdb2 ; rpdb2.start_embedded_debugger('foo')
    m = macro_sig_re.match(sig)
    if not m:
        signode += addnodes.desc_name(sig, sig)
        return sig
    name, args = m.groups()
    signode += addnodes.desc_name(name, name)
    plist = desc_cmake_argumentlist()
    for m in macro_param_re.finditer(args):
        arg = m.group(0)

        if arg.startswith('['):
            arg = arg[1:-1].strip()
            x = desc_cmake_argument()
            opt = addnodes.desc_optional()
            x += opt
            m = macro_param_re.match(arg)

            assert m is not None, "%s does not match %s" % (arg, macro_param_re.pattern)

            opt += _get_param_node(m)
            plist += x

        # elif arg.startswith('{') choice
        else:
            x = desc_cmake_argument()
            x += _get_param_node(m)
            plist += x

    signode += plist
    return name
Esempio n. 2
0
def parse_macro(env, sig, signode):
    #import rpdb2 ; rpdb2.start_embedded_debugger('foo')
    m = macro_sig_re.match(sig)
    if not m:
        signode += addnodes.desc_name(sig, sig)
        return sig
    name, args = m.groups()
    signode += addnodes.desc_name(name, name)
    plist = desc_cmake_argumentlist()
    for m in macro_param_re.finditer(args):
        arg = m.group(0)

        if arg.startswith('['):
            arg = arg[1:-1].strip()
            x = desc_cmake_argument()
            opt = addnodes.desc_optional()
            x += opt
            m = macro_param_re.match(arg)

            assert m is not None, "%s does not match %s" % (
                arg, macro_param_re.pattern)

            opt += _get_param_node(m)
            plist += x

        # elif arg.startswith('{') choice
        else:
            x = desc_cmake_argument()
            x += _get_param_node(m)
            plist += x

    signode += plist
    return name
Esempio n. 3
0
def parse_macro(env, sig, signode):
    m = macro_sig_re.match(sig)
    if not m:
        signode += addnodes.desc_name(sig, sig)
        return sig
    name, args = m.groups()
    signode += addnodes.desc_name(name, name)
    plist = desc_cmake_argumentlist()
    for m in macro_param_re.finditer(args):
        arg = m.group(0)
        if arg.startswith('['):
            arg = arg[1:-1].strip()
            x = desc_cmake_argument()
            opt = addnodes.desc_optional()
            x += opt
            m = macro_param_re.match(arg)
            assert m is not None, "%s does not match %s" % (arg, macro_param_re.pattern)
            opt += _get_param_node(m, True)
            plist += x
        else:
            x = desc_cmake_argument()
            x += _get_param_node(m, False)
            plist += x
    signode += plist
    return name
Esempio n. 4
0
def _pseudo_parse_arglist(sig_node: addnodes.desc_signature, arg_list: str):
    param_list = addnodes.desc_parameterlist()
    stack = [param_list]

    processed_args_list = []
    try:
        for argument in arg_list.split(','):
            argument = argument.strip()
            ends_open = ends_close = 0
            while argument.startswith('['):
                stack.append(addnodes.desc_optional())
                stack[-2] += stack[-1]
                argument = argument[1:].strip()
            while argument.startswith(']'):
                stack.pop()
                argument = argument[1:].strip()
            while argument.endswith(']') and not argument.endswith('[]'):
                ends_close += 1
                argument = argument[:-1].strip()
            while argument.endswith('['):
                ends_open += 1
                argument = argument[:-1].strip()
            if argument:
                stack[-1] += addnodes.desc_parameter(argument, argument)
                processed_args_list.append({"name": argument})

                if ends_close > 0:
                    processed_args_list[-1]["optional"] = True
            while ends_open:
                stack.append(addnodes.desc_optional())
                stack[-2] += stack[-1]
                ends_open -= 1
            while ends_close:
                stack.pop()
                ends_close -= 1
        if len(stack) != 1:
            raise IndexError
    except IndexError:
        # if there are too few or too many elements on the stack, just give up
        # and treat the whole argument list as one argument, discarding the
        # already partially populated paramlist node
        sig_node += addnodes.desc_parameterlist()
        sig_node[-1] += addnodes.desc_parameter(arg_list, arg_list)
    finally:
        sig_node += param_list

    return processed_args_list
Esempio n. 5
0
def _pseudo_parse_arglist(signode, arglist):
    # type: (addnodes.desc_signature, unicode) -> None
    """"Parse" a list of arguments separated by commas.

    Arguments can have "optional" annotations given by enclosing them in
    brackets.  Currently, this will split at any comma, even if it's inside a
    string literal (e.g. default argument value).
    """
    paramlist = addnodes.desc_parameterlist()
    stack = [paramlist]  # type: List[nodes.Element]
    try:
        for argument in arglist.split(','):
            argument = argument.strip()
            ends_open = ends_close = 0
            while argument.startswith('['):
                stack.append(addnodes.desc_optional())
                stack[-2] += stack[-1]
                argument = argument[1:].strip()
            while argument.startswith(']'):
                stack.pop()
                argument = argument[1:].strip()
            while argument.endswith(']') and not argument.endswith('[]'):
                ends_close += 1
                argument = argument[:-1].strip()
            while argument.endswith('['):
                ends_open += 1
                argument = argument[:-1].strip()
            if argument:
                stack[-1] += addnodes.desc_parameter(argument, argument)
            while ends_open:
                stack.append(addnodes.desc_optional())
                stack[-2] += stack[-1]
                ends_open -= 1
            while ends_close:
                stack.pop()
                ends_close -= 1
        if len(stack) != 1:
            raise IndexError
    except IndexError:
        # if there are too few or too many elements on the stack, just give up
        # and treat the whole argument list as one argument, discarding the
        # already partially populated paramlist node
        paramlist = addnodes.desc_parameterlist()
        paramlist += addnodes.desc_parameter(arglist, arglist)
        signode += paramlist
    else:
        signode += paramlist
Esempio n. 6
0
def _pseudo_parse_arglist(signode, arglist):
    # type: (addnodes.desc_signature, str) -> None
    """"Parse" a list of arguments separated by commas.

    Arguments can have "optional" annotations given by enclosing them in
    brackets.  Currently, this will split at any comma, even if it's inside a
    string literal (e.g. default argument value).
    """
    paramlist = addnodes.desc_parameterlist()
    stack = [paramlist]  # type: List[nodes.Element]
    try:
        for argument in arglist.split(','):
            argument = argument.strip()
            ends_open = ends_close = 0
            while argument.startswith('['):
                stack.append(addnodes.desc_optional())
                stack[-2] += stack[-1]
                argument = argument[1:].strip()
            while argument.startswith(']'):
                stack.pop()
                argument = argument[1:].strip()
            while argument.endswith(']') and not argument.endswith('[]'):
                ends_close += 1
                argument = argument[:-1].strip()
            while argument.endswith('['):
                ends_open += 1
                argument = argument[:-1].strip()
            if argument:
                stack[-1] += addnodes.desc_parameter(argument, argument)
            while ends_open:
                stack.append(addnodes.desc_optional())
                stack[-2] += stack[-1]
                ends_open -= 1
            while ends_close:
                stack.pop()
                ends_close -= 1
        if len(stack) != 1:
            raise IndexError
    except IndexError:
        # if there are too few or too many elements on the stack, just give up
        # and treat the whole argument list as one argument, discarding the
        # already partially populated paramlist node
        paramlist = addnodes.desc_parameterlist()
        paramlist += addnodes.desc_parameter(arglist, arglist)
        signode += paramlist
    else:
        signode += paramlist
Esempio n. 7
0
def make_desc_parameters(params):
    for p in params:
        if '.' in p.name:
            continue

        node = addnodes.desc_parameter(p.name, p.name)
        if p.optional:
            node = addnodes.desc_optional('', '', node)
        yield node
Esempio n. 8
0
def make_desc_parameters(params):
    for p in params:
        if '.' in p.name:
            continue

        node = addnodes.desc_parameter(p.name, p.name)
        if p.optional:
            node = addnodes.desc_optional('', '', node)
        yield node
Esempio n. 9
0
def _pseudo_parse_arglist(signode, argstart, arglist, argend):
    """"Parse" a list of arguments separated by commas.

    Arguments can have "optional" annotations given by enclosing them in
    brackets.  Currently, this will split at any comma, even if it's inside a
    string literal (e.g. default argument value).
    """
    paramlist = _desc_parameterlist(argstart, argend)
    stack = [paramlist]
    for argument in arglist.split(','):
        argument = argument.strip()
        ends_open = ends_close = 0
        while argument.startswith('['):
            stack.append(addnodes.desc_optional())
            stack[-2] += stack[-1]
            argument = argument[1:].strip()

        while argument.startswith(']'):
            stack.pop()
            argument = argument[1:].strip()

        while argument.endswith(']'):
            ends_close += 1
            argument = argument[:-1].strip()

        while argument.endswith('['):
            ends_open += 1
            argument = argument[:-1].strip()

        if argument:
            stack[-1] += addnodes.desc_parameter(argument, argument)
            while ends_open:
                stack.append(addnodes.desc_optional())
                stack[-2] += stack[-1]
                ends_open -= 1

            while ends_close:
                stack.pop()
                ends_close -= 1

    if len(stack) != 1:
        raise IndexError

    signode += paramlist
Esempio n. 10
0
 def parse_arglist(self, signode, arglist):
     """parses argument lists
     
     largely imported from sphinx.domains.python,
     changes are mainly to make it work with space-separated
     argument lists and to make it look so"""
     paramlist = self._fix_paramlist(addnodes.desc_parameterlist())
     stack = [paramlist]
     try:
         for argument in arglist.split(" "):
             argument = argument.strip()
             ends_open = ends_close = 0
             while argument.startswith("["):
                 stack.append(self._fix_paramlist(addnodes.desc_optional(), False))
                 stack[-2] += stack[-1]
                 argument = argument[1:].strip()
             while argument.startswith("]"):
                 stack.pop()
                 argument = argument[1:].strip()
             while argument.endswith("]"):
                 ends_close += 1
                 argument = argument[:-1].strip()
             while argument.endswith("["):
                 ends_open += 1
                 argument = argument[:-1].strip()
             if argument:
                 stack[-1] += addnodes.desc_parameter(argument, argument)
             while ends_open:
                 stack.append(self._fix_paramlist(addnodes.desc_optional(), False))
                 stack[-2] += stack[-1]
                 ends_open -= 1
             while ends_close:
                 stack.pop()
                 ends_close -= 1
         if len(stack) != 1:
             raise IndexError
     except IndexError:
         # if there are too few or too many elements on the stack, just give up
         # and treat the whole argument list as one argument, discarding the
         # already partially populated paramlist node
         signode += self._fix_paramlist(addnodes.desc_parameterlist())
         signode[-1] += addnodes.desc_parameter(arglist, arglist)
     else:
         signode += paramlist
Esempio n. 11
0
def _pseudo_parse_arglist(signode, argstart, arglist, argend):
    """"Parse" a list of arguments separated by commas.

    Arguments can have "optional" annotations given by enclosing them in
    brackets.  Currently, this will split at any comma, even if it's inside a
    string literal (e.g. default argument value).
    """
    paramlist = _desc_parameterlist(argstart, argend)
    stack = [paramlist]
    for argument in arglist.split(','):
        argument = argument.strip()
        ends_open = ends_close = 0
        while argument.startswith('['):
            stack.append(addnodes.desc_optional())
            stack[-2] += stack[-1]
            argument = argument[1:].strip()

        while argument.startswith(']'):
            stack.pop()
            argument = argument[1:].strip()

        while argument.endswith(']'):
            ends_close += 1
            argument = argument[:-1].strip()

        while argument.endswith('['):
            ends_open += 1
            argument = argument[:-1].strip()

        if argument:
            stack[-1] += addnodes.desc_parameter(argument, argument)
            while ends_open:
                stack.append(addnodes.desc_optional())
                stack[-2] += stack[-1]
                ends_open -= 1

            while ends_close:
                stack.pop()
                ends_close -= 1

    # if len(stack) != 1:
    #     raise IndexError

    signode += paramlist
    def _pseudo_parse_arglist(signode, arglist):
        """Parse list of comma separated arguments.

        Arguments can have optional types.
        """
        paramlist = addnodes.desc_parameterlist()
        stack = [paramlist]
        try:
            for argument in arglist.split(','):
                argument = argument.strip()
                ends_open = 0
                ends_close = 0
                while argument.startswith('['):
                    stack.append(addnodes.desc_optional())
                    stack[-2] += stack[-1]
                    argument = argument[1:].strip()
                while argument.startswith(']'):
                    stack.pop()
                    argument = argument[1:].strip()
                while argument.endswith(']') and not argument.endswith('[]'):
                    ends_close += 1
                    argument = argument[:-1].strip()
                while argument.endswith('['):
                    ends_open += 1
                    argument = argument[:-1].strip()
                if argument:
                    stack[-1] += addnodes.desc_parameter(argument, argument)
                while ends_open:
                    stack.append(addnodes.desc_optional())
                    stack[-2] += stack[-1]
                    ends_open -= 1
                while ends_close:
                    stack.pop()
                    ends_close -= 1
            if len(stack) != 1:
                raise IndexError
        except IndexError:
            # If there are too few or too many elements on the stack, just give
            # up and treat the whole argument list as one argument, discarding
            # the already partially populated paramlist node.
            signode += addnodes.desc_parameterlist()
            signode[-1] += addnodes.desc_parameter(arglist, arglist)
        else:
            signode += paramlist
Esempio n. 13
0
def _pseudo_parse_generic(signode, arglist, desc_listtype, desc_type):
    # type: (addnodes.desc_signature, unicode) -> None
    """ "Parse" a list of returns separated by commas.
    """
    genericlist = desc_listtype()
    stack = [genericlist]
    try:
        for argument in arglist.split(','):
            argument = argument.strip()
            ends_open = ends_close = 0
            while argument.startswith('['):
                stack.append(addnodes.desc_optional())
                stack[-2] += stack[-1]
                argument = argument[1:].strip()
            while argument.startswith(']'):
                stack.pop()
                argument = argument[1:].strip()
            while argument.endswith(']') and not argument.endswith('[]'):
                ends_close += 1
                argument = argument[:-1].strip()
            while argument.endswith('['):
                ends_open += 1
                argument = argument[:-1].strip()
            if argument:
                stack[-1] += desc_type(argument, argument)
            while ends_open:
                stack.append(addnodes.desc_optional())
                stack[-2] += stack[-1]
                ends_open -= 1
            while ends_close:
                stack.pop()
                ends_close -= 1
        if len(stack) != 1:
            raise IndexError
    except IndexError:
        # if there are too few or too many elements on the stack, just give up
        # and treat the whole argument list as one argument, discarding the
        # already partially populated returnlist node
        signode += desc_listtype()
        signode[-1] += desc_type(arglist, arglist)
    else:
        signode += genericlist
Esempio n. 14
0
    def handle_signature(self, sig: str,
                         sig_node: addnodes.desc_signature) -> str:
        self.input_sig = sig
        self.table_call = "table_call" in self.options

        if self.table_call:
            print(re.search(r'([A-Za-z_-]+)\b', sig).group(1))
            self.obj_name = re.search(r'([A-Za-z_-]+)\b', sig).group(1)
            self.register_signature(self.obj_name, sig)

            sig_node += addnodes.desc_name(sig, sig)
        else:
            m = sig_re.match(sig)

            if m is None:
                raise ValueError

            name, arg_list = m.groups()

            if name is None:
                raise ValueError

            self.register_signature(name, sig)

            sig_node += addnodes.desc_name(name, name)

            self.parsed_args = _pseudo_parse_arglist(sig_node, arg_list)
            self.obj_name = name

        if "has_table_overload" in self.options:
            sig_node += addnodes.desc_optional("has-table-overload",
                                               "has-table-overload")

        if self.table_call:
            sig_node += addnodes.desc_optional("table_call", "table_call")

        return sig
Esempio n. 15
0
 def _handle_function_signature(self, sig, signode):
     # extract parts of the signature.
     m = mat_func_sig_re.match(sig)
     if m is None:
         raise ValueError
     retann, toolbox, name, arglist = m.groups()
     # resolve full function name.
     fullname = self._resolve_toolbox_name(signode, toolbox, name)
     # handle (absence of) arguments list.
     if not arglist:
         if self.needs_arglist():
             # for callables, add an empty parameter list
             signode += addnodes.desc_parameterlist()
         if retann:
             signode += addnodes.desc_returns(retann, retann)
         if self.objtype == 'function':
             return fullname + '/0'
         return fullname
     signode += addnodes.desc_parameterlist()
     stack = [signode[-1]]
     counters = [0, 0]
     for token in mat_paramlist_re.split(arglist):
         if token == '[':
             opt = addnodes.desc_optional()
             stack[-1] += opt
             stack.append(opt)
         elif token == ']':
             try:
                 stack.pop()
             except IndexError:
                 raise ValueError
         elif not token or token == ',' or token.isspace():
             pass
         else:
             token = token.strip()
             stack[-1] += addnodes.desc_parameter(token, token)
             if len(stack) == 1:
                 counters[0] += 1
             else:
                 counters[1] += 1
     if len(stack) != 1:
         raise ValueError
     if not counters[1]:
         fullname = '%s/%d' % (fullname, counters[0])
     else:
         fullname = '%s/%d..%d' % (fullname, counters[0], sum(counters))
     if retann:
         signode += addnodes.desc_returns(retann, retann)
     return fullname
Esempio n. 16
0
    def _handle_function_signature(self, sig, signode):
        m = erl_func_sig_re.match(sig)
        if m is None:
            raise ValueError
        modname, name, arglist, retann = m.groups()

        fullname = self._resolve_module_name(signode, modname, name)

        if not arglist:
            if self.needs_arglist():
                # for callables, add an empty parameter list
                signode += addnodes.desc_parameterlist()
            if retann:
                signode += addnodes.desc_returns(retann, retann)
            if self.objtype == 'function':
                return fullname + '/0'
            return fullname
        signode += addnodes.desc_parameterlist()

        stack = [signode[-1]]
        counters = [0, 0]
        for token in erl_paramlist_re.split(arglist):
            if token == '[':
                opt = addnodes.desc_optional()
                stack[-1] += opt
                stack.append(opt)
            elif token == ']':
                try:
                    stack.pop()
                except IndexError:
                    raise ValueError
            elif not token or token == ',' or token.isspace():
                pass
            else:
                token = token.strip()
                stack[-1] += addnodes.desc_parameter(token, token)
                if len(stack) == 1:
                    counters[0] += 1
                else:
                    counters[1] += 1
        if len(stack) != 1:
            raise ValueError
        if not counters[1]:
            fullname = '%s/%d' % (fullname, counters[0])
        else:
            fullname = '%s/%d..%d' % (fullname, counters[0], sum(counters))
        if retann:
            signode += addnodes.desc_returns(retann, retann)
        return fullname
Esempio n. 17
0
def _pseudo_parse_arglist(signode, arglist):
    paramlist = addnodes.desc_parameterlist()
    stack = [paramlist]
    try:
        for argument in arglist.split(','):
            argument = argument.strip()
            ends_open = ends_close = 0
            while argument.startswith('['):
                stack.append(addnodes.desc_optional())
                stack[-2] += stack[-1]
                argument = argument[1:].strip()
            while argument.startswith(']'):
                stack.pop()
                argument = argument[1:].strip()
            while argument.endswith(']') and not argument.endswith('[]'):
                ends_close += 1
                argument = argument[:-1].strip()
            while argument.endswith('['):
                ends_open += 1
                argument = argument[:-1].strip()
            if argument:
                stack[-1] += addnodes.desc_parameter(argument, argument)
            while ends_open:
                stack.append(addnodes.desc_optional())
                stack[-2] += stack[-1]
                ends_open -= 1
            while ends_close:
                stack.pop()
                ends_close -= 1
        if len(stack) != 1:
            raise IndexError
    except IndexError:
        signode += addnodes.desc_parameterlist()
        signode[-1] += addnodes.desc_parameter(arglist, arglist)
    else:
        signode += paramlist
Esempio n. 18
0
    def format_parameters(self, parameters):
        params = addnodes.desc_parameterlist()
        for param in parameters:
            node = n.container()
            if param['required']:
                node += addnodes.desc_parameter(param['name'], param['name'])
            else:
                node += addnodes.desc_optional(param['name'], param['name'])

            node += n.strong(text=' type: %s ' % param['dataType'])
            allowableValues = param.get('allowableValues')
            if allowableValues:
                allowableValues.pop('valueType', None)
                node += n.emphasis(text=' %s' % allowableValues)
            params += node
        return params
Esempio n. 19
0
    def format_parameters(self, parameters):
        params = addnodes.desc_parameterlist()
        for param in parameters:
            node = n.container()
            if param['required']:
                node += addnodes.desc_parameter(param['name'], param['name'])
            else:
                node += addnodes.desc_optional(param['name'], param['name'])

            node += n.strong(text=' type: %s ' % param['dataType'])
            allowableValues = param.get('allowableValues')
            if allowableValues:
                allowableValues.pop('valueType', None)
                node += n.emphasis(text=' %s' % allowableValues)
            params += node
        return params
Esempio n. 20
0
    def format_parameters(self, parameters):
        params = addnodes.desc_parameterlist()
        for param in parameters:
            node = n.container()
            if param["required"]:
                node += addnodes.desc_parameter(param["name"], param["name"])
            else:
                node += addnodes.desc_optional(param["name"], param["name"])

            node += n.strong(text=" type: %s " % param["dataType"])
            allowableValues = param.get("allowableValues")
            if allowableValues:
                allowableValues.pop("valueType", None)
                node += n.emphasis(text=" %s" % allowableValues)
            params += node
        return params
Esempio n. 21
0
    def handle_signature(self, sig, signode):
        m = http_method_sig_re.match(sig)
        if m is None:
            raise ValueError

        verb, url, query = m.groups()
        if verb is None:
            verb = 'GET'

        signode += addnodes.desc_addname(verb, verb)
        signode += addnodes.desc_name(url, url)

        if query:
            params = query.strip().split()
            for param in params:
                signode += addnodes.desc_optional(param, param)
            
        return url
Esempio n. 22
0
    def handle_signature(self, sig, signode):
        symbol_name = []
        package = self.env.temp_data.get('cl:package')
        objtype = self.get_signature_prefix(sig)
        sig_split = sig.split(" ")
        sig = sig_split[0]
        signode.append(addnodes.desc_annotation(objtype, objtype))
        lisp_args = ARGS[package].get(sig.upper(), "")
        function_name = addnodes.desc_name(sig, sig)

        if not lisp_args.strip() and self.objtype in ["function"]:
            lisp_args = "()"
        if lisp_args.strip():
            types = []
            if self.objtype in ["method"]:
                types = self.arguments[0].split(' ')[1:]
            sexp = SEXP(lisp_args,
                        types=types,
                        show_defaults=self.env.app.config.cl_show_defaults)
            arg_list = sexp.as_parameterlist(function_name)
            signode.append(arg_list)
        else:
            signode.append(function_name)

        # Add Slots
        slots = SLOTS[package].get(sig.upper())
        if slots and "noinitargs" not in self.options:
            # TODO add slot details if describing a class
            for slot in slots:
                initarg = slot.get(u'initarg')
                if initarg and initarg.lower() != 'nil':
                    slotarg = addnodes.literal_emphasis(
                        slot.get(u'name'), slot.get(u'name'))
                    slotsig = initarg.lower() + u' '
                    signode.append(
                        addnodes.desc_optional(slotsig, slotsig, slotarg))

        symbol_name = sig
        if not symbol_name:
            raise Exception("Unknown symbol type for signature %s" % sig)

        record_use(package, symbol_name, self.objtype)
        return objtype.strip(), symbol_name
Esempio n. 23
0
def _parse_parameter_list(params):
    """Parse a SpeedCrunch parameter list into nodes."""
    paramlist = sc_parameterlist()
    stack = deque([paramlist])
    for param in params.split(';'):
        param = param.strip()
        if param and param[-1] in '[]':
            p = param[:-1].strip()
            stack[-1] += addnodes.desc_parameter(p, p)
        else:
            stack[-1] += addnodes.desc_parameter(param, param)

        if param.endswith('['):
            node = addnodes.desc_optional()
            stack[-1] += node
            stack.append(node)
        elif param.endswith(']'):
            stack.pop()

    return paramlist
def _parse_parameter_list(params):
    """Parse a SpeedCrunch parameter list into nodes."""
    paramlist = sc_parameterlist()
    stack = deque([paramlist])
    for param in params.split(';'):
        param = param.strip()
        if param and param[-1] in '[]':
            p = param[:-1].strip()
            stack[-1] += addnodes.desc_parameter(p, p)
        else:
            stack[-1] += addnodes.desc_parameter(param, param)

        if param.endswith('['):
            node = addnodes.desc_optional()
            stack[-1] += node
            stack.append(node)
        elif param.endswith(']'):
            stack.pop()

    return paramlist
Esempio n. 25
0
    def format_response_class(self, response_class_name):
        ret = n.container()
        ret += addnodes.desc_returns(text=response_class_name)
        model = self.models.get(response_class_name)
        props = addnodes.desc_parameterlist()
        for key, property in model['properties'].items():
            pc = n.container()
            if property['required']:
                pc += addnodes.desc_parameter(key, key)
            else:
                pc += addnodes.desc_optional(key, key)

            pc += n.strong(text=' type: %s ' % property['type'])
            allowableValues = property.get('allowableValues')
            if allowableValues:
                allowableValues.pop('valueType', None)
                pc += n.subscript(text=' %s' % allowableValues)

            props += pc
        ret += props
        return ret
Esempio n. 26
0
    def format_response_class(self, response_class_name):
        ret = n.container()
        ret += addnodes.desc_returns(text=response_class_name)
        model = self.models.get(response_class_name)
        props = addnodes.desc_parameterlist()
        for key, property in model["properties"].items():
            pc = n.container()
            if property["required"]:
                pc += addnodes.desc_parameter(key, key)
            else:
                pc += addnodes.desc_optional(key, key)

            pc += n.strong(text=" type: %s " % property["type"])
            allowableValues = property.get("allowableValues")
            if allowableValues:
                allowableValues.pop("valueType", None)
                pc += n.subscript(text=" %s" % allowableValues)

            props += pc
        ret += props
        return ret
Esempio n. 27
0
    def handle_signature(self, sig, signode):
        symbol_name = []
        package = self.env.temp_data.get('cl:package')
        objtype = self.get_signature_prefix(sig)
        sig_split = sig.split(" ")
        sig = sig_split[0]
        signode.append(addnodes.desc_annotation(objtype, objtype))
        lisp_args = ARGS[package].get(sig.upper(), "")
        function_name = addnodes.desc_name(sig, sig)

        if not lisp_args.strip() and self.objtype in ["function"]:
            lisp_args = "()"
        if lisp_args.strip():
            types = []
            if self.objtype in ["method"]:
                types = self.arguments[0].split(' ')[1:]
            sexp = SEXP(lisp_args,
                        types=types,
                        show_defaults=self.env.app.config.cl_show_defaults)
            arg_list = sexp.as_parameterlist(function_name)
            signode.append(arg_list)
        else:
            signode.append(function_name)

        # Add Slots
        slots = SLOTS[package].get(sig.upper())
        if slots and "noinitargs" not in self.options:
            # TODO add slot details if describing a class
            for slot in slots:
                initarg = slot.get(u'initarg')
                if initarg and initarg.lower() != 'nil':
                    slotarg = addnodes.literal_emphasis(slot.get(u'name'), slot.get(u'name'))
                    slotsig = initarg.lower() + u' '
                    signode.append(addnodes.desc_optional(slotsig, slotsig, slotarg))

        symbol_name = sig
        if not symbol_name:
            raise Exception("Unknown symbol type for signature %s" % sig)
        record_use(package, symbol_name, self.objtype)
        return objtype.strip(), symbol_name
Esempio n. 28
0
    def format_response_class(self, response_class_name):
        ret = n.container()
        ret += addnodes.desc_returns(text=response_class_name)
        model = self.models.get(response_class_name)
        props = addnodes.desc_parameterlist()
        for key, property in model['properties'].items():
            pc = n.container()
            if property['required']:
                pc += addnodes.desc_parameter(key, key)
            else:
                pc += addnodes.desc_optional(key, key)


            pc += n.strong(text=' type: %s ' % property['type'])
            allowableValues = property.get('allowableValues')
            if allowableValues:
                allowableValues.pop('valueType', None)
                pc += n.subscript(text=' %s' % allowableValues)

            props += pc
        ret += props
        return ret
Esempio n. 29
0
    def _construct_nodes(self, signode):
        sigdata = self.erl_sigdata
        env_object = self.erl_env_object

        # emulate erlang directives, like '-type', '-record', etc.
        if self.objtype not in ('function', 'clause'):
            objtype_part = '-%s' % (self.objtype, )
            signode += addnodes.desc_annotation(objtype_part, objtype_part)
            signode += nodes.inline(' ', ' ')

        modname_part = '%s:' % (sigdata.modname, )
        signode += addnodes.desc_addname(modname_part, modname_part)

        name_part = sigdata.to_desc_name()
        signode += addnodes.desc_name(name_part, name_part)

        if sigdata.arg_list is not None:
            paramlist_node = addnodes.desc_parameterlist()
            signode += paramlist_node
            last_node = paramlist_node
            for (req, txt) in sigdata.arg_list:
                if req == 'mandatory':
                    last_node += addnodes.desc_parameter(txt, txt)
                else:
                    opt = addnodes.desc_optional()
                    opt += addnodes.desc_parameter(txt, txt)
                    last_node += opt
                    last_node = opt

        if sigdata.explicit_flavor:
            flavor_text = ' @%s' % (sigdata.flavor, )
            signode += nodes.inline(flavor_text, flavor_text)

        if sigdata.when_text is not None:
            when_text = ' when %s' % (sigdata.when_text, )
            signode += nodes.emphasis(when_text, when_text)

        if sigdata.ret_ann:
            signode += addnodes.desc_returns(sigdata.ret_ann, sigdata.ret_ann)
Esempio n. 30
0
 def parse_arg(plist, e):
     type_ = parser.ast_type(e)
     if type_ == "list":
         head = e and e[0]
         mode = None
         if head == "?":
             paramlist = addnodes.desc_optional()
             paramlist.child_text_separator = ' '
             for arg in e[1:]:
                 parse_arg(paramlist, arg)
             plist += paramlist
         elif head == "<splice>":
             print "YES"
             for arg in e[1:]:
                 parse_arg(plist, arg)
         elif head == "|":
             for i, arg in enumerate(e[1:]):
                 if i > 0:
                     plist += addnodes.desc_parameter("|",
                                                      " | ",
                                                      noemph=True)
                 parse_arg(plist, arg)
         else:
             paramlist = addnodes.desc_parameterlist()
             paramlist.child_text_separator = ' '
             for arg in e:
                 parse_arg(paramlist, arg)
             plist += paramlist
     elif type_ == "symbol":
         if e.startswith('_:'):
             e = e[2:]
             plist += addnodes.desc_name(e, " " + e + " ")
         else:
             plist += addnodes.desc_parameter(e, " " + e + " ")
     else:
         e = repr(e)
         plist += addnodes.desc_parameter(e, e)
Esempio n. 31
0
    def handle_signature(self, sig, signode):
        """
        Transform a PHP signature into RST nodes.
        Returns (fully qualified name of the thing, classname if any).

        If inside a class, the current class name is handled intelligently:
        * it is stripped from the displayed name if present
        * it is added to the full name (return value) if not present
        """
        m = php_sig_re.match(sig)
        if m is None:
            raise ValueError

        name_prefix, name, arglist, retann = m.groups()

        if not name_prefix:
            name_prefix = ""

        # determine module and class name (if applicable), as well as full name
        modname = self.options.get(
            'namespace', self.env.temp_data.get('php:namespace'))

        classname = self.env.temp_data.get('php:class')
        separator = separators[self.objtype]

        if self.objtype == 'global' or self.objtype == 'function':
            add_module = False
            modname = None
            classname = None
            fullname = name
        else:
            add_module = True
            # name_prefix and a non-static method, means the classname was 
            # repeated. Trim off the <class>::
            if name_prefix and self.objtype != 'staticmethod':
                if name_prefix.startswith(classname):
                    name_prefix = name_prefix[len(classname):].rstrip('::')
                classname = classname.rstrip('::')
                fullname = name_prefix + classname + separator + name
            elif name_prefix:
                classname = classname.rstrip('::')
                fullname = name_prefix + name

            # Currently in a class, but not creating another class,
            elif classname and not self.objtype in ['class', 'exception', 'interface', 'trait']:
                if not self.env.temp_data['php:in_class']:
                    name_prefix = classname + separator

                fullname = classname + separator + name
            else:
                classname = ''
                fullname = name

        signode['namespace'] = modname
        signode['class'] = self.class_name = classname
        signode['fullname'] = fullname

        sig_prefix = self.get_signature_prefix(sig)

        if sig_prefix:
            signode += addnodes.desc_annotation(sig_prefix, sig_prefix)

        if name_prefix:
            if modname and not self.env.temp_data['php:in_class']:
                name_prefix = modname + NS + name_prefix
            signode += addnodes.desc_addname(name_prefix, name_prefix)

        elif add_module and self.env.config.add_module_names:
            if self.objtype == 'global':
                nodetext = ''
                signode += addnodes.desc_addname(nodetext, nodetext)
            else:
                modname = self.options.get(
                    'namespace', self.env.temp_data.get('php:namespace'))

                if modname and not self.env.temp_data.get('php:in_class', False):
                    nodetext = modname + NS
                    signode += addnodes.desc_addname(nodetext, nodetext)

        signode += addnodes.desc_name(name, name)
        if not arglist:
            if self.needs_arglist():
                # for callables, add an empty parameter list
                signode += addnodes.desc_parameterlist()
            if retann:
                signode += addnodes.desc_returns(retann, retann)
            return fullname, name_prefix

        signode += addnodes.desc_parameterlist()

        stack = [signode[-1]]
        for token in php_paramlist_re.split(arglist):
            if token == '[':
                opt = addnodes.desc_optional()
                stack[-1] += opt
                stack.append(opt)
            elif token == ']':
                try:
                    stack.pop()
                except IndexError:
                    raise ValueError
            elif not token or token == ',' or token.isspace():
                pass
            else:
                token = token.strip()
                stack[-1] += addnodes.desc_parameter(token, token)
        if len(stack) != 1:
            raise ValueError
        if retann:
            signode += addnodes.desc_returns(retann, retann)
        return fullname, name_prefix
Esempio n. 32
0
def parse_py_signature(signode, sig, desctype, module, env):
    """
    Transform a python signature into RST nodes.
    Return (fully qualified name of the thing, classname if any).

    If inside a class, the current class name is handled intelligently:
    * it is stripped from the displayed name if present
    * it is added to the full name (return value) if not present
    """
    m = py_sig_re.match(sig)
    if m is None:
        raise ValueError
    classname, name, arglist, retann = m.groups()

    if retann:
        retann = u' \N{RIGHTWARDS ARROW} ' + retann.strip()[2:]

    if env.currclass:
        add_module = False
        if classname and classname.startswith(env.currclass):
            fullname = classname + name
            # class name is given again in the signature
            classname = classname[len(env.currclass):].lstrip('.')
        elif classname:
            # class name is given in the signature, but different
            # (shouldn't happen)
            fullname = env.currclass + '.' + classname + name
        else:
            # class name is not given in the signature
            fullname = env.currclass + '.' + name
    else:
        add_module = True
        fullname = classname and classname + name or name

    if desctype == 'staticmethod':
        signode += addnodes.desc_annotation('static ', 'static ')

    if classname:
        signode += addnodes.desc_addname(classname, classname)
    # exceptions are a special case, since they are documented in the
    # 'exceptions' module.
    elif add_module and env.config.add_module_names and \
           module and module != 'exceptions':
        nodetext = module + '.'
        signode += addnodes.desc_addname(nodetext, nodetext)

    signode += addnodes.desc_name(name, name)
    if not arglist:
        if desctype in ('function', 'method', 'staticmethod'):
            # for callables, add an empty parameter list
            signode += addnodes.desc_parameterlist()
        if retann:
            signode += addnodes.desc_type(retann, retann)
        return fullname, classname
    signode += addnodes.desc_parameterlist()

    stack = [signode[-1]]
    for token in py_paramlist_re.split(arglist):
        if token == '[':
            opt = addnodes.desc_optional()
            stack[-1] += opt
            stack.append(opt)
        elif token == ']':
            try:
                stack.pop()
            except IndexError:
                raise ValueError
        elif not token or token == ',' or token.isspace():
            pass
        else:
            token = token.strip()
            stack[-1] += addnodes.desc_parameter(token, token)
    if len(stack) != 1:
        raise ValueError
    if retann:
        signode += addnodes.desc_type(retann, retann)
    return fullname, classname
Esempio n. 33
0
def parse_py_signature(signode, sig, desctype, module, env):
    """
    Transform a python signature into RST nodes.
    Return (fully qualified name of the thing, classname if any).

    If inside a class, the current class name is handled intelligently:
    * it is stripped from the displayed name if present
    * it is added to the full name (return value) if not present
    """
    m = py_sig_re.match(sig)
    if m is None:
        raise ValueError
    classname, name, arglist, retann = m.groups()

    if env.currclass:
        add_module = False
        if classname and classname.startswith(env.currclass):
            fullname = classname + name
            # class name is given again in the signature
            classname = classname[len(env.currclass):].lstrip('.')
        elif classname:
            # class name is given in the signature, but different
            # (shouldn't happen)
            fullname = env.currclass + '.' + classname + name
        else:
            # class name is not given in the signature
            fullname = env.currclass + '.' + name
    else:
        add_module = True
        fullname = classname and classname + name or name

    if desctype == 'staticmethod':
        signode += addnodes.desc_annotation('static ', 'static ')

    if classname:
        signode += addnodes.desc_addname(classname, classname)
    # exceptions are a special case, since they are documented in the
    # 'exceptions' module.
    elif add_module and env.config.add_module_names and \
           module and module != 'exceptions':
        nodetext = module + '.'
        signode += addnodes.desc_addname(nodetext, nodetext)

    signode += addnodes.desc_name(name, name)
    if not arglist:
        if desctype in ('function', 'method', 'staticmethod'):
            # for callables, add an empty parameter list
            signode += addnodes.desc_parameterlist()
        return fullname, classname
    signode += addnodes.desc_parameterlist()

    stack = [signode[-1]]
    for token in py_paramlist_re.split(arglist):
        if token == '[':
            opt = addnodes.desc_optional()
            stack[-1] += opt
            stack.append(opt)
        elif token == ']':
            try:
                stack.pop()
            except IndexError:
                raise ValueError
        elif not token or token == ',' or token.isspace():
            pass
        else:
            token = token.strip()
            stack[-1] += addnodes.desc_parameter(token, token)
    if len(stack) != 1:
        raise ValueError
    if retann:
        retann = u' \N{RIGHTWARDS ARROW} ' + retann.strip()[2:]
        signode += addnodes.desc_type(retann, retann)
    return fullname, classname
Esempio n. 34
0
    def handle_signature(self, sig, signode):
        """
        Transform a TCP/IP signature into RST nodes.
        Returns (fully qualified name of the thing, classname if any).

        If inside a class, the current class name is handled intelligently:
        * it is stripped from the displayed name if present
        * it is added to the full name (return value) if not present
        """
        m = tcpip_sig_re.match(sig)
        if m is None:
            print 'FAILED', sig
            raise ValueError
        name_prefix, name, arglist, retann = m.groups()

        # determine module and class name (if applicable), as well as full name
        modname = self.options.get(
            'module', self.env.temp_data.get('tcpip:module'))
        classname = self.env.temp_data.get('tcpip:class')
        if classname:
            add_module = False
            if name_prefix and name_prefix.startswith(classname):
                fullname = name_prefix + name
                # class name is given again in the signature
                name_prefix = name_prefix[len(classname):].lstrip('.')
            elif name_prefix:
                # class name is given in the signature, but different
                # (shouldn't happen)
                fullname = classname + '.' + name_prefix + name
            else:
                # class name is not given in the signature
                fullname = classname + '.' + name
        else:
            add_module = True
            if name_prefix:
                classname = name_prefix.rstrip('.')
                fullname = name_prefix + name
            else:
                classname = ''
                fullname = name

        signode['module'] = modname
        signode['class'] = classname
        signode['fullname'] = fullname

        sig_prefix = self.get_signature_prefix(sig)
        if sig_prefix:
            signode += addnodes.desc_annotation(sig_prefix, sig_prefix)

        if name_prefix:
            signode += addnodes.desc_addname(name_prefix, name_prefix)
        # exceptions are a special case, since they are documented in the
        # 'exceptions' module.
        elif add_module and self.env.config.add_module_names:
            modname = self.options.get(
                'module', self.env.temp_data.get('tcpip:module'))
            if modname and modname != 'exceptions':
                nodetext = modname + '.'
                signode += addnodes.desc_addname(nodetext, nodetext)

        signode += addnodes.desc_name(name, name)
        if not arglist:
            if self.needs_arglist():
                # for callables, add an empty parameter list
                signode += addnodes.desc_parameterlist()
            if retann:
                signode += addnodes.desc_returns(retann, retann)
            return fullname, name_prefix
        signode += addnodes.desc_parameterlist()

        stack = [signode[-1]]
        for token in tcpip_paramlist_re.split(arglist):
            if token == '[':
                opt = addnodes.desc_optional()
                stack[-1] += opt
                stack.append(opt)
            elif token == ']':
                try:
                    stack.pop()
                except IndexError:
                    raise ValueError
            elif not token or token == ',' or token.isspace():
                pass
            else:
                token = token.strip()
                stack[-1] += addnodes.desc_parameter(token, token)
        if len(stack) != 1:
            raise ValueError
        if retann:
            signode += addnodes.desc_returns(retann, retann)
        return fullname, name_prefix
Esempio n. 35
0
def getArgLabel(Arg):
  if 'default' in Arg:
    return desc_optional('', '{}={}'.format(Arg['name'], getReadableValue(Arg['default'])))

  else:
    return (desc_parameter if not 'default' in Arg else desc_optional)('', Arg['name'])
Esempio n. 36
0
    def parse_signature(self, sig, signode):
        """
        Transform a Python signature into RST nodes.
        Returns (fully qualified name of the thing, classname if any).

        If inside a class, the current class name is handled intelligently:
        * it is stripped from the displayed name if present
        * it is added to the full name (return value) if not present
        """
        m = py_sig_re.match(sig)
        if m is None:
            raise ValueError
        classname, name, arglist, retann = m.groups()

        if self.env.currclass:
            add_module = False
            if classname and classname.startswith(self.env.currclass):
                fullname = classname + name
                # class name is given again in the signature
                classname = classname[len(self.env.currclass):].lstrip('.')
            elif classname:
                # class name is given in the signature, but different
                # (shouldn't happen)
                fullname = self.env.currclass + '.' + classname + name
            else:
                # class name is not given in the signature
                fullname = self.env.currclass + '.' + name
        else:
            add_module = True
            fullname = classname and classname + name or name

        prefix = self.get_signature_prefix(sig)
        if prefix:
            signode += addnodes.desc_annotation(prefix, prefix)

        if classname:
            signode += addnodes.desc_addname(classname, classname)
        # exceptions are a special case, since they are documented in the
        # 'exceptions' module.
        elif add_module and self.env.config.add_module_names:
            modname = self.options.get('module', self.env.currmodule)
            if modname and modname != 'exceptions':
                nodetext = modname + '.'
                signode += addnodes.desc_addname(nodetext, nodetext)

        signode += addnodes.desc_name(name, name)
        if not arglist:
            if self.needs_arglist():
                # for callables, add an empty parameter list
                signode += addnodes.desc_parameterlist()
            if retann:
                signode += addnodes.desc_returns(retann, retann)
            return fullname, classname
        signode += addnodes.desc_parameterlist()

        stack = [signode[-1]]
        for token in py_paramlist_re.split(arglist):
            if token == '[':
                opt = addnodes.desc_optional()
                stack[-1] += opt
                stack.append(opt)
            elif token == ']':
                try:
                    stack.pop()
                except IndexError:
                    raise ValueError
            elif not token or token == ',' or token.isspace():
                pass
            else:
                token = token.strip()
                stack[-1] += addnodes.desc_parameter(token, token)
        if len(stack) != 1:
            raise ValueError
        if retann:
            signode += addnodes.desc_returns(retann, retann)
        return fullname, classname
Esempio n. 37
0
    def handle_signature(self, sig, signode):
        """
        Transform a Ruby signature into RST nodes.
        Returns (fully qualified name of the thing, classname if any).

        If inside a class, the current class name is handled intelligently:
        * it is stripped from the displayed name if present
        * it is added to the full name (return value) if not present
        """
        m = kl_sig_re.match(sig)
        if m is None:
            raise ValueError
        functype, retann, name_prefix, name, arglist = m.groups()
        if not name_prefix:
            name_prefix = ""
        # determine module and class name (if applicable), as well as full name
        modname = self.options.get('module',
                                   self.env.temp_data.get('kl:module'))
        classname = self.env.temp_data.get('kl:class')
        if self.objtype == 'global':
            add_module = False
            modname = None
            classname = None
            fullname = name
        elif classname:
            add_module = False
            if name_prefix and name_prefix.startswith(classname):
                fullname = name_prefix + name
                # class name is given again in the signature
                name_prefix = name_prefix[len(classname):].lstrip('.')
            else:
                separator = separators[self.objtype]
                fullname = classname + separator + name_prefix + name
        else:
            add_module = True
            if name_prefix:
                classname = name_prefix.rstrip('.')
                fullname = name_prefix + name
            else:
                classname = ''
                fullname = name

        signode['module'] = modname
        signode['class'] = self.class_name = classname
        signode['fullname'] = fullname

        signode += addnodes.desc_annotation(functype, functype)
        if retann:
            signode += addnodes.desc_annotation(retann, retann)

        if name_prefix:
            signode += addnodes.desc_addname(name_prefix, name_prefix)
        # exceptions are a special case, since they are documented in the
        # 'exceptions' module.
        elif add_module and self.env.config.add_module_names:
            if self.objtype == 'global':
                nodetext = ''
                signode += addnodes.desc_addname(nodetext, nodetext)
            else:
                modname = self.options.get('module',
                                           self.env.temp_data.get('kl:module'))
                if modname and modname != 'exceptions':
                    nodetext = modname + separators[self.objtype]
                    signode += addnodes.desc_addname(nodetext, nodetext)

        signode += addnodes.desc_name(name, name)
        if not arglist:
            if self.needs_arglist():
                # for callables, add an empty parameter list
                signode += addnodes.desc_parameterlist()
            return fullname, name_prefix
        signode += addnodes.desc_parameterlist()

        stack = [signode[-1]]
        for token in kl_paramlist_re.split(arglist):
            if token == '[':
                opt = addnodes.desc_optional()
                stack[-1] += opt
                stack.append(opt)
            elif token == ']':
                try:
                    stack.pop()
                except IndexError:
                    raise ValueError
            elif not token or token == ',' or token.isspace():
                pass
            else:
                token = token.strip()
                stack[-1] += addnodes.desc_parameter(token, token)
        if len(stack) != 1:
            raise ValueError
        return fullname, name_prefix
Esempio n. 38
0
def getArgLabel(Arg):
  if 'default' in Arg:
    return desc_optional('', '{}={}'.format(Arg['name'], getReadableValue(Arg['default'])))

  else:
    return (desc_parameter if not 'default' in Arg else desc_optional)('', Arg['name'])