def handle_signature(self, sig, signode): """ Transform a hotkey signature into RST nodes. """ m = km_sig_re.match(sig) if m is None: raise ValueError name, operator, map_type, value = m.groups() # determine module and class name (if applicable), as well as full name modname = self.options.get('module', self.env.ref_context.get('km:module')) fullname = modname + '->' + name + '->' + operator signode['module'] = modname signode['fullname'] = fullname sig_prefix = self.get_signature_prefix() if sig_prefix: signode += addnodes.desc_annotation(sig_prefix, sig_prefix) signode += addnodes.desc_name(name, name) signode += addnodes.desc_returns(operator, operator) map_type = ' : ' + map_type signode += addnodes.desc_annotation(map_type, map_type) signode += addnodes.desc_returns(value, value) return fullname, name
def _parse_return(self) -> addnodes.desc_returns: """ Convert the function's return to a node. """ if self.__inspect_sig.return_annotation is not self.__inspect_sig.empty: return addnodes.desc_returns( text=self._annotation(self.__type_hints["return"])) else: return addnodes.desc_returns(text="null")
def handle_signature(self, sig, signode): """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 """ name_prefix = None name = sig arglist = None retann = None # determine module and class name (if applicable), as well as full name modname = self.options.get( 'module', self.env.temp_data.get('py:module')) classname = self.env.temp_data.get('py:class') 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) anno = self.options.get('annotation') 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) if anno: signode += addnodes.desc_annotation(' ' + anno, ' ' + anno) return fullname, name_prefix _pseudo_parse_arglist(signode, arglist) if retann: signode += addnodes.desc_returns(retann, retann) if anno: signode += addnodes.desc_annotation(' ' + anno, ' ' + anno) return fullname, name_prefix
def _handle_function_signature(self, sig, signode): m = ada_func_sig_re.match(sig) if m is None: print "m did not match the function" raise ValueError modname, name, dummy, arglist, returntype, abstract = m.groups() print "DEBUG: modname %s name %s arglist %s" % (modname, name, arglist) fullname = self._resolve_module_name(signode, modname, name) print "DEBUG: fullname %s" % fullname if not arglist: if self.needs_arglist(): # for functions and procedures, add an empty parameter list new_node = addnodes.desc_parameterlist() new_node.child_text_separator = '; ' signode += new_node if returntype: signode += addnodes.desc_returns(returntype, returntype) return fullname signode += nodes.Text(' ') new_node = addnodes.desc_parameterlist() new_node.child_text_separator = '; ' signode += new_node stack = [signode[-1]] counters = [0, 0] for token in string.split(arglist, ';'): pieces = string.split(token, ':') name = pieces[0].strip() stack[-1] += addnodes.desc_parameter( name, name + " : " + pieces[1].strip()) 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 returntype: signode += addnodes.desc_returns(returntype, returntype) return fullname
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
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
def _handle_function_signature(self, sig, signode): m = ada_func_sig_re.match(sig) if m is None: print "m did not match the function" raise ValueError modname, name, dummy, arglist, returntype, abstract = m.groups() print "DEBUG: modname %s name %s arglist %s" % (modname, name, arglist) fullname = self._resolve_module_name(signode, modname, name) print "DEBUG: fullname %s" % fullname if not arglist: if self.needs_arglist(): # for functions and procedures, add an empty parameter list new_node = addnodes.desc_parameterlist() new_node.child_text_separator = '; ' signode += new_node if returntype: signode += addnodes.desc_returns(returntype, returntype) return fullname signode += nodes.Text(' ') new_node = addnodes.desc_parameterlist() new_node.child_text_separator = '; ' signode += new_node stack = [signode[-1]] counters = [0, 0] for token in string.split(arglist, ';'): pieces = string.split(token, ':') name = pieces[0].strip() stack[-1] += addnodes.desc_parameter(name, name + " : " + pieces[1].strip()) 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 returntype: signode += addnodes.desc_returns(returntype,returntype) return fullname
def handle_signature(self, sig, signode): sdkname = self.options.get('sdk', self.env.ref_context.get('qbs:sdk')) pkgname = self.options.get('package', self.env.ref_context.get('qbs:package')) modname = self.env.ref_context.get('qbs:module', None) itemname = self.env.ref_context.get('qbs:item', None) type, name, value = self.parse(sig) signode['module'] = modname signode['package'] = pkgname signode['item'] = itemname if self.objtype == 'property': fullname = self.get_signature_name(objname=(modname or itemname), name=name) else: fullname = name signode['sdk'] = sdkname signode['fullname'] = fullname sigprefix = self.get_signature_prefix() if sigprefix: signode += addnodes.desc_annotation(sigprefix, sigprefix) if type: signode += addnodes.desc_addname(type, type) if name: signode += addnodes.desc_name(name, name) if value: signode += addnodes.desc_returns(value, value) return fullname
def _build_prop_anno(self): self.options.setdefault('type', 'None') prop_type = self.options['type'] prop_cls = self.options.get('propcls') if prop_cls is None: prop_cls = 'Property' if prop_type == 'dict': prop_cls = 'DictProperty' elif prop_type == 'list': prop_cls = 'ListProperty' elif prop_type == 'set': prop_cls = 'SetProperty' if prop_cls == 'SetProperty': prop_cls_xr = f'tallypi.utils.{prop_cls}' else: prop_cls_xr = f'pydispatch.properties.{prop_cls}' prop_type_xr = f':class:`{prop_type}`' # self.options['annotation'] = f'{prop_cls_xr}({prop_cls})' anno = addnodes.desc_returns('', '') # anno += ANNO_CLS(' -> ', ' -> ') anno += build_xref(prop_cls, prop_cls_xr, env=self.env) anno += ANNO_CLS('(', '(') anno += build_xref(prop_type, prop_type, env=self.env) anno += ANNO_CLS(')', ')') self._annotation_node = anno
def _handle_function_signature(self, sig, signode, m): if m is None: raise ValueError struct, name, arglist, retann = m.groups() signode += addnodes.desc_addname("func ", "func" + u'\xa0') fullname = self._resolve_package_name(signode, struct, name) if not arglist: # for callables, add an empty parameter list signode += addnodes.desc_parameterlist() else: paramlist = addnodes.desc_parameterlist() args = arglist.split(",") for arg in args: arg = arg.strip() param = addnodes.desc_parameter('', '', noemph=True) try: argname, gotype = arg.split(' ', 1) except ValueError: # no argument name given, only the type self._parse_type(param, arg) else: param += nodes.emphasis(argname + ' ', argname + u'\xa0') self._parse_type(param, gotype) # separate by non-breaking space in the output paramlist += param signode += paramlist if retann: signode += addnodes.desc_returns(retann, retann) return fullname
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
def make_signature(self): ret = super(FunctionDocumenter, self).make_signature() with addto(ret, addnodes.desc_parameterlist()) as params: params += make_desc_parameters(self.item.params) retval = self.item.return_val if retval.type or retval.doc: ret.append(addnodes.desc_returns(retval.type or '*', retval.type or '*')) return ret
def build_signode(self, signode): if self.type == 'unary': signode += addnodes.desc_name(self.name, self.name) context = self.context + self.contextsep signode += addnodes.desc_addname(context, context) if self.retann: signode += addnodes.desc_returns(self.retann, self.retann) elif self.type == 'binary': context = self.context + self.contextsep name = " %s " % (self.name) signode += addnodes.desc_addname(context, context) signode += addnodes.desc_name(name, name) signode += addnodes.desc_addname(context, context) if self.retann: signode += addnodes.desc_returns(self.retann, self.retann) elif self.type == 'index' or self.type == 'newindex': context = self.context + self.contextsep signode += addnodes.desc_addname(context, context) self.build_parameters(signode) if self.retann: if self.type == 'newindex': retann = " = %s" % (self.retann) signode += addnodes.desc_type(retann, retann) else: signode += addnodes.desc_returns(self.retann, self.retann) elif self.type == 'convert': context = self.context + self.contextsep signode += addnodes.desc_name(self.name, self.name) paramlist = _desc_parameterlist('(', ')') paramlist.append(addnodes.desc_addname(context, context)) signode.append(paramlist) if self.retann: signode += addnodes.desc_returns(self.retann, self.retann)
def _handle_function_signature(self, sig, signode): m = pure_func_sig_re.match(sig) if m is None: raise ValueError fixity, namesp, name, tag, arglist, retsym, retann = m.groups() fullname = self._resolve_namespace(signode, namesp, name) if tag: fullname += "/%s" % tag self.add_signature_prefix(signode) if fixity: signode['fixity'] = fixity # Sphinx' default format for the parameter list isn't very useful with # Pure's curried function applications, so we use freeform text for # the arguments instead. We also have to take care of different # fixities here. if fixity=='postfix': if arglist: arglist += " " signode += desc_args(arglist, arglist) self._add_desc_name(signode, name) elif fixity=='infix': arglist = pure_paramlist_re.split(arglist) left = ''.join(arglist[:1]) right = ''.join(arglist[2:]) if left: left += " " signode += desc_args(left, left) self._add_desc_name(signode, name) if right: right = " "+right signode += desc_args(right, right) elif fixity=='outfix' and arglist: arglist = pure_paramlist_re.split(arglist) name2 = arglist[0] signode['other'] = name2 arglist = ''.join(arglist[2:]) self._add_desc_name(signode, name) if arglist: arglist = " "+arglist+" " signode += desc_args(arglist, arglist) self._add_desc_name(signode, name2) else: self._add_desc_name(signode, name) if arglist: arglist = " "+arglist signode += desc_args(arglist, arglist) if retann: if retsym=="->": signode += addnodes.desc_returns(retann, retann) else: retann = " %s %s" % (retsym, retann) signode += desc_args(retann, retann) return fullname
def handle_signature(self, sig, signode): """Transform a Lasso signature into RST nodes. """ sig = sig.strip().replace(' ', ' ').replace(' ::', '::').replace(':: ', '::') if '(' in sig: if ')::' in sig: sig, returntype = sig.rsplit('::', 1) else: returntype = None prefix, arglist = sig.split('(', 1) prefix = prefix.strip() arglist = arglist[:-1].strip().replace(' =', '=').replace('= ', '=') else: if '::' in sig: sig, returntype = sig.rsplit('::', 1) else: returntype = None prefix = sig arglist = None if '->' in prefix: objectprefix, name = prefix.rsplit('->', 1) objectprefix += '->' else: objectprefix = None name = prefix objectname = self.env.ref_context.get('ls:object') if objectprefix: fullname = objectprefix + name elif objectname: fullname = objectname + '->' + name else: objectname = '' fullname = name signode['object'] = objectname signode['fullname'] = fullname sig_prefix = self.get_signature_prefix(sig) if sig_prefix: signode += addnodes.desc_annotation(sig_prefix, sig_prefix) if objectprefix: signode += addnodes.desc_addname(objectprefix, objectprefix) signode += addnodes.desc_name(name, name) if self.needs_arglist(): if arglist: _pseudo_parse_arglist(signode, arglist) else: signode += addnodes.desc_parameterlist() if returntype: signode += addnodes.desc_returns(returntype, returntype) return fullname, objectprefix
def build_signode(self, signode): if self.context: context = self.context + self.contextsep signode += addnodes.desc_addname(context, context) signode += addnodes.desc_name(self.name, self.name) self.build_parameters(signode) if self.retann: signode += addnodes.desc_returns(self.retann, self.retann)
def handle_signature(self, sig, signode): rtype = self.retann = self.options.get('proptype') r = super().handle_signature(sig, signode) if rtype is not None: anno = addnodes.desc_returns('', '') anno += build_xref(rtype, rtype) signode += anno if 'readonly' in self.options: # signode['classes'].append('readonly') # t = ' [{}]'.format(l_('READ ONLY')) t = ' [read-only]' signode += nodes.emphasis(t, t)#, classes=['readonly-label'])#, 'align-center']) return r
def handle_signature(self, sig, signode): parser = edgeql_parser.EdgeQLBlockParser() try: astnode = parser.parse( f'CREATE FUNCTION {sig} USING SQL FUNCTION "xxx";')[0] except Exception as ex: raise shared.DirectiveParseError( self, f'could not parse function signature {sig!r}', cause=ex) if (not isinstance(astnode, ql_ast.CreateFunction) or not isinstance(astnode.name, ql_ast.ObjectRef)): raise shared.DirectiveParseError( self, f'EdgeQL parser returned unsupported AST') modname = astnode.name.module funcname = astnode.name.name if not modname: raise shared.DirectiveParseError( self, f'EdgeQL function declaration is missing namespace') func_repr = ql_gen.EdgeQLSourceGenerator.to_source(astnode) m = re.match(r'''(?xs) ^ CREATE\sFUNCTION\s (?P<f>.*?) \sUSING\sSQL\sFUNCTION .*$ ''', func_repr) if not m or not m.group('f'): raise shared.DirectiveParseError( self, f'could not recreate function signature from AST') func_repr = m.group('f') signode['eql-module'] = modname signode['eql-name'] = funcname signode['eql-fullname'] = fullname = f'{modname}::{funcname}' signode['eql-signature'] = func_repr signode += s_nodes.desc_annotation('function', 'function') signode += d_nodes.Text(' ') signode += s_nodes.desc_name(fullname, fullname) ret_repr = ql_gen.EdgeQLSourceGenerator.to_source(astnode.returning) if astnode.returning_typemod is qltypes.TypeModifier.SET_OF: ret_repr = f'SET OF {ret_repr}' elif astnode.returning_typemod is qltypes.TypeModifier.OPTIONAL: ret_repr = f'OPTIONAL {ret_repr}' signode += s_nodes.desc_returns(ret_repr, ret_repr) return fullname
def handle_signature(self, sig, signode): # if the function has a return type specified, clip it before # processing the rest of signature if sig[-1] != ')' and '):' in sig: newsig, rettype = sig.rsplit(':', 1) rettype = rettype.strip() else: newsig = sig rettype = None fullname, prefix = super().handle_signature(newsig, signode) if rettype: signode += s_nodes.desc_returns(rettype, rettype) return fullname, prefix
def describe_signature(self, sig, sig_node): sig_match = self.KOTLIN_PROPERTY_SIG_RE.match(sig) if sig_match is None: raise ValueError('no match') class_name, prop_name, prop_type = sig_match.groups() # TODO: also attempt to parse package name from prop_name package_name = self.env.ref_context.get('polyglot:namespace') sig_node += addnodes.desc_annotation('property ', 'property ') if package_name is not None: sig_node += self.make_namespace_prefix(package_name + '.' + class_name + '.') sig_node += addnodes.desc_name(prop_name, prop_name) if prop_type is not None and len(prop_type) > 0: sig_node += nodes.Text(' ') sig_node += addnodes.desc_returns(prop_type, prop_type) return class_name + '#' + prop_name
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
def describe_signature(self, sig, sig_node): sig_match = self.SQL_FUNCTION_SIG_RE.match(sig) if sig_match is None: raise ValueError('no match') func_name, func_params, func_return = sig_match.groups() # TODO: also attempt to parse package name from func_name package_name = self.env.ref_context.get('polyglot:namespace') sig_node += addnodes.desc_annotation('function ', 'function ') if package_name is not None: sig_node += self.make_namespace_prefix(package_name + '.') sig_node += addnodes.desc_name(func_name, func_name) if func_params is not None: sig_node += self.make_parameter_list(func_params) # TODO: split params if func_return is not None and len(func_return) > 0: sig_node += nodes.Text(' ') sig_node += addnodes.desc_returns(func_return, func_return) return func_name
def describe_signature(self, sig, sig_node): sig_match = self.KOTLIN_METHOD_SIG_RE.match(sig) if sig_match is None: raise ValueError('no match') class_name, method_name, method_params, method_type = sig_match.groups() # TODO: also attempt to parse package name from method_name package_name = self.env.ref_context.get('polyglot:namespace') sig_node += addnodes.desc_annotation('method ', 'method ') if package_name is not None: sig_node += self.make_namespace_prefix(package_name + '.' + class_name + '.') sig_node += addnodes.desc_name(method_name, method_name) if method_params is not None: sig_node += self.make_parameter_list(method_params) # TODO: split params if method_type is not None and len(method_type) > 0: sig_node += nodes.Text(' ') sig_node += addnodes.desc_returns(method_type, method_type) return class_name + '#' + method_name
def handle_signature(self, sig, signode): m = plsql_sig_re.match(sig) if m is None: raise ValueError name_prefix, name, arglist, retann = m.groups() if not name_prefix: name_prefix = '' if self.env.temp_data.get('plsql:in_package'): name_prefix = self.env.temp_data['plsql:current_package'] + '.' sig_prefix = self.get_signature_prefix(sig) if sig_prefix: signode += addnodes.desc_annotation(sig_prefix, sig_prefix) if not self.env.temp_data.get('plsql:in_package'): signode += addnodes.desc_annotation(name_prefix, name_prefix) fullname = '' if name_prefix: fullname += name_prefix fullname += name signode += addnodes.desc_name(name, name) if arglist: signode += addnodes.desc_parameterlist() stack = [signode[-1]] for token in arglist.split(','): if not token or token == ',' or token.isspace(): pass else: token = token.strip() stack[-1] += addnodes.desc_parameter(token, token) if retann: signode += addnodes.desc_returns(retann, retann) return fullname
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
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
def _handle_proc_signature(self, sig, signode, m): "Transform a Nim proc node into RST nodes." name, arglist, rettype, pragmas = m.groups() signode += addnodes.desc_type('proc', 'proc') signode += addnodes.desc_name(name, name) if arglist is None: signode += addnodes.desc_parameterlist() else: arguments = nim_arg_sig_re.match(arglist).groups()[0] signode += addnodes.desc_parameterlist(arguments, arguments) if rettype is not None: retnode = addnodes.desc_returns() self._parse_type(retnode, nim_rettype_sig_re.match(rettype).groups()[0]) signode += retnode if pragmas: signode += addnodes.desc_addname(pragmas, pragmas) return name
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)
def handle_signature(self, sig, signode): """Transform a TLisp signature into RST nodes. Return (fully qualified name of the thing, classname if any). """ m = tlisp_sig_re.match(sig) if m is None: raise ValueError name, arglist, retann = m.groups() name_prefix = None package = self.env.temp_data.get('tl:package') 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) anno = self.options.get('annotation') sexp = tlisp_parameterlist() sexp += addnodes.desc_name(name, name) for argument in arglist.split(' '): argument = argument.strip() sexp += tlisp_parameter(argument, argument) signode += sexp if retann: signode += addnodes.desc_returns(retann, retann) if anno: signode += addnodes.desc_annotation(' ' + anno, ' ' + anno) return name, name_prefix
def handle_signature(self, sig, signode): """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 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('py:module')) classname = self.env.temp_data.get('py: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('py:module')) if modname and modname != 'exceptions': nodetext = modname + '.' signode += addnodes.desc_addname(nodetext, nodetext) anno = self.options.get('annotation') 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) if anno: signode += addnodes.desc_annotation(' ' + anno, ' ' + anno) return fullname, name_prefix _pseudo_parse_arglist(signode, arglist) if retann: signode += addnodes.desc_returns(retann, retann) if anno: signode += addnodes.desc_annotation(' ' + anno, ' ' + anno) return fullname, name_prefix
def handle_signature(self, sig, signode): s = sig.split(' ') if True: name_prefix = None name = None paramlist = None first = True for p in s: p = p.replace('_', ' ') if len(p) == 0: continue if not first: if paramlist is None: signode += addnodes.desc_annotation(' ', ' ') else: first = False if p.startswith('L'): # param if paramlist is None: paramlist = desc_parameterlist() paramlist += addnodes.desc_parameter(p[1:], p[1:]) else: if paramlist is not None: signode += paramlist paramlist = None signode += addnodes.desc_annotation(' ', ' ') if p.startswith('S'): # sig_prefix signode += addnodes.desc_annotation(p[1:] + ' ', p[1:] + ' ') elif p.startswith('P'): # name_prefix name_prefix = p[1:] signode += addnodes.desc_addname(name_prefix, name_prefix) elif p.startswith('N'): # name name = p[1:] np = name.split(' ') for k in np[:-1]: signode += addnodes.desc_name(k, k) signode += addnodes.desc_annotation(' ', ' ') signode += addnodes.desc_name(np[-1], np[-1]) elif p.startswith('A'): # annotation signode += addnodes.desc_annotation(p[1:], p[1:]) elif p.startswith('R'): # returns signode += addnodes.desc_returns(p[1:], p[1:]) if paramlist is not None: signode += paramlist paramlist = None if name_prefix: classname = name_prefix.lstrip(' ') fullname = name + ' of ' + name_prefix else: classname = '' fullname = name modname = self.options.get('module', self.env.temp_data.get('tvpl:module')) signode['module'] = modname signode['class'] = classname signode['fullname'] = fullname return fullname, name_prefix m = tvpl_sig_re.match(sig) if m is None: print 'FAILED', sig raise ValueError sig_prefix, name_prefix, name, arglist = m.groups() arglist = arglist.strip() if len(arglist) == 0: arglist = None # determine module and class name (if applicable), as well as full name modname = self.options.get('module', self.env.temp_data.get('tvpl:module')) classname = self.env.temp_data.get('tvpl: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 #print ">" + str(modname) + '<', ">" + classname + '<', ">" + fullname + '<' 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('tvpl:module')) if modname and modname != 'exceptions': nodetext = modname + '.' signode += addnodes.desc_addname(nodetext, nodetext) if sig_prefix: signode += addnodes.desc_annotation(' <uid> ', ' <uid> ') else: signode += addnodes.desc_annotation(' ', ' ') signode += addnodes.desc_name(name, name) if not arglist: if self.needs_arglist(): # for callables, add an empty parameter list signode += desc_parameterlist() #if retann: # signode += addnodes.desc_returns(retann, retann) return fullname, name_prefix _pseudo_parse_arglist(signode, arglist) #if retann: # signode += addnodes.desc_returns(retann, retann) return fullname, name_prefix
def handle_signature(self, sig, signode): # type: (unicode, addnodes.desc_signature) -> Tuple[unicode, unicode] """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) # type: ignore if m is None: 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.ref_context.get('py:module')) classname = self.env.ref_context.get('py: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.ref_context.get('py:module')) if modname and modname != 'exceptions': nodetext = modname + '.' signode += addnodes.desc_addname(nodetext, nodetext) anno = self.options.get('annotation') 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) if anno: signode += addnodes.desc_annotation(' ' + anno, ' ' + anno) return fullname, name_prefix _pseudo_parse_arglist(signode, arglist) if retann: signode += addnodes.desc_returns(retann, retann) if anno: signode += addnodes.desc_annotation(' ' + anno, ' ' + anno) return fullname, name_prefix
def handle_signature(self, sig, signode): """Transform a Bsv signature into RST nodes. Return (fully qualified name of the thing, interfacename if any). If inside a interface, the current interface 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 """ print 'BsvObject.handle_signature', sig name_prefix = '' name = sig arglist = '' retann = '' if self.objtype in ['interface', 'instance', 'typeclass']: split = sig.split('#', 1) name = split[0] if len(split) > 1: arglist = split[1] m = bsv_param_re.match(arglist) if m: arglist = m.group(1) elif self.objtype in ['subinterface', 'field']: split = sig.rsplit(' ', 1) print 'rsplit', split name = split[-1] if len(split) > 1: retann = split[0] elif self.objtype in ['method', 'function']: split = sig.split(' ', 1) retann = split[0] nameparams = split[1] split = nameparams.split('(', 1) name = split[0] if len(split) > 1: arglist = split[1][0:-1] elif self.objtype in ['module']: split = sig.split('#', 1) name = split[0] if len(split) > 1: depth = 0 paramreturn = split[1] #print 'module', paramreturn, len(paramreturn) for i in range(0,len(paramreturn)): c = paramreturn[i] if c == '(': depth = depth+1 elif c == ')': depth = depth-1 #print i, c, depth if depth==0: endofparam=i break arglist = paramreturn[1:endofparam] retann = paramreturn[endofparam+1:-1] #print arglist #print endofparam, retann # determine package and interface name (if applicable), as well as full name modname = self.options.get( 'package', self.env.temp_data.get('bsv:package')) interfacename = self.env.temp_data.get('bsv:interface') if interfacename: add_package = False if name_prefix and name_prefix.startswith(interfacename): fullname = name_prefix + name # interface name is given again in the signature name_prefix = name_prefix[len(interfacename):].lstrip('.') elif name_prefix: # interface name is given in the signature, but different # (shouldn't happen) fullname = interfacename + '.' + name_prefix + name else: # interface name is not given in the signature fullname = interfacename + '.' + name else: add_package = True if name_prefix: interfacename = name_prefix.rstrip('.') fullname = name_prefix + name else: interfacename = '' fullname = name signode['package'] = modname signode['interface'] = interfacename 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' package. elif add_package and self.env.config.add_package_names: modname = self.options.get( 'package', self.env.temp_data.get('bsv:package')) if modname and modname != 'exceptions': nodetext = modname + '::' signode += addnodes.desc_addname(nodetext, nodetext) anno = self.options.get('annotation') signode += addnodes.desc_name(name, name) #print 'arglist', arglist if not arglist: if self.needs_arglist(): # for callables, add an empty parameter list if arglist: signode += addnodes.desc_parameterlist(text=arglist) elif self.options.get('parameter'): signode += addnodes.desc_parameterlist(text=self.options.get('parameter')) if retann: signode += addnodes.desc_returns(text=retann) elif self.options.get('returntype'): signode += addnodes.desc_returns(text=self.options.get('returntype')) if anno: signode += addnodes.desc_annotation(' ' + anno, ' ' + anno) #print 'signode', signode return fullname, name_prefix _pseudo_parse_arglist(signode, arglist) if retann: signode += addnodes.desc_returns(retann, retann) if anno: signode += addnodes.desc_annotation(' ' + anno, ' ' + anno) return fullname, name_prefix
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
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
def parse_signature(self, sig, signode): """ Returns (fully qualified name, classname if any). """ m = ooc_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): # classname is repeated in the signature classname = classname[len(self.env.currclass):].lstrip('/') elif classname: # class name given in the signature, but different, # should not happen fullname = self.env.currclass + '/' + classname + name else: # not given if isinstance(self, ClassmemberDesc): fullname = self.env.currclass + ' ' + name else: 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('', '', *self._resolve_typeref(retann)) return fullname, classname signode += addnodes.desc_parameterlist() stack = [signode[-1]] token_before = None for token in ooc_paramlist_re.split(arglist): if token_before is not None: if token == ',': # add commas yay. token_before += token continue else: token = token_before + token print 'NOW TOKEN: %r' % token token_before = None if token.count('<') != token.count('>'): # splitted in the middle of a <A, B, C> declaration :( token_before = token elif not token or token == ',' or token.isspace(): pass else: token = token.strip() if ':' in token: stack[-1] += addnodes.desc_parameter('', '', *self._resolve_typeref(token)) else: stack[-1] += addnodes.desc_parameter(token, token) if len(stack) != 1: raise ValueError if retann: ret_nodes = self.state.inline_text(retann, self.lineno)[0] signode += addnodes.desc_returns('', '', *self._resolve_typeref(retann)) return fullname, classname
def handle_signature(self, sig, signode): """Transform a Bsv signature into RST nodes. Return (fully qualified name of the thing, interfacename if any). If inside a interface, the current interface 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 """ print('BsvObject.handle_signature', sig) name_prefix = '' name = sig arglist = '' retann = '' if self.objtype in ['interface', 'instance', 'typeclass']: split = sig.split('#', 1) name = split[0] if len(split) > 1: arglist = split[1] m = bsv_param_re.match(arglist) if m: arglist = m.group(1) elif self.objtype in ['subinterface', 'field']: split = sig.rsplit(' ', 1) print('rsplit', split) name = split[-1] if len(split) > 1: retann = split[0] elif self.objtype in ['method', 'function']: split = sig.split(' ', 1) retann = split[0] nameparams = split[1] split = nameparams.split('(', 1) name = split[0] if len(split) > 1: arglist = split[1][0:-1] elif self.objtype in ['module']: split = sig.split('#', 1) name = split[0] if len(split) > 1: depth = 0 paramreturn = split[1] #print('module', paramreturn, len(paramreturn)) for i in range(0, len(paramreturn)): c = paramreturn[i] if c == '(': depth = depth + 1 elif c == ')': depth = depth - 1 #print(i, c, depth) if depth == 0: endofparam = i break arglist = paramreturn[1:endofparam] retann = paramreturn[endofparam + 1:-1] #print(arglist) #print(endofparam, retann) # determine package and interface name (if applicable), as well as full name modname = self.options.get('package', self.env.temp_data.get('bsv:package')) interfacename = self.env.temp_data.get('bsv:interface') if interfacename: add_package = False if name_prefix and name_prefix.startswith(interfacename): fullname = name_prefix + name # interface name is given again in the signature name_prefix = name_prefix[len(interfacename):].lstrip('.') elif name_prefix: # interface name is given in the signature, but different # (shouldn't happen) fullname = interfacename + '.' + name_prefix + name else: # interface name is not given in the signature fullname = interfacename + '.' + name else: add_package = True if name_prefix: interfacename = name_prefix.rstrip('.') fullname = name_prefix + name else: interfacename = '' fullname = name signode['package'] = modname signode['interface'] = interfacename 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' package. elif add_package and self.env.config.add_package_names: modname = self.options.get('package', self.env.temp_data.get('bsv:package')) if modname and modname != 'exceptions': nodetext = modname + '::' signode += addnodes.desc_addname(nodetext, nodetext) anno = self.options.get('annotation') signode += addnodes.desc_name(name, name) #print('arglist', arglist) if not arglist: if self.needs_arglist(): # for callables, add an empty parameter list if arglist: signode += addnodes.desc_parameterlist(text=arglist) elif self.options.get('parameter'): signode += addnodes.desc_parameterlist( text=self.options.get('parameter')) if retann: signode += addnodes.desc_returns(text=retann) elif self.options.get('returntype'): signode += addnodes.desc_returns( text=self.options.get('returntype')) if anno: signode += addnodes.desc_annotation(' ' + anno, ' ' + anno) #print('signode', signode) return fullname, name_prefix _pseudo_parse_arglist(signode, arglist) if retann: signode += addnodes.desc_returns(retann, retann) if anno: signode += addnodes.desc_annotation(' ' + anno, ' ' + anno) return fullname, name_prefix
def _handle_signature(self, cid, lineno, sig, signode): # type: (str, addnodes.desc_signature) -> Tuple[str, str] """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 This is the xml string result of signode, whitespace is not equivalent for readability. <desc_signature class="" first="False" fullname="com.google.fonts/check/all_glyphs_have_codepoints" module="fontbakery.profiles.cmap" > <desc_annotation xml:space="preserve">FontBakeryCheck </desc_annotation> <desc_addname xml:space="preserve">fontbakery.profiles.cmap.</desc_addname> <desc_name xml:space="preserve">com_google_fonts_check_all_glyphs_have_codepoints</desc_name> <desc_parameterlist xml:space="preserve"> <desc_parameter xml:space="preserve">ttFont</desc_parameter> </desc_parameterlist> </desc_signature> """ m = py_sig_re.match(sig) if m is None: # this is the immediate fail!!! raise ValueError prefix, name, arglist, retann = m.groups() # print('prefix, name, arglist, retann =', prefix, name, arglist, retann) # > prefix, name, arglist, retann = None com_google_fonts_check_all_glyphs_have_codepoints ttFont None # determine module and class name (if applicable), as well as full name modname = self.options.get('module', self.env.ref_context.get('py:module')) classname = self.env.ref_context.get('py:class') if classname: add_module = False if prefix and (prefix == classname or prefix.startswith(classname + ".")): fullname = prefix + name # class name is given again in the signature prefix = prefix[len(classname):].lstrip('.') elif prefix: # class name is given in the signature, but different # (shouldn't happen) fullname = classname + '.' + prefix + name else: # class name is not given in the signature fullname = classname + '.' + name else: add_module = True if prefix: classname = prefix.rstrip('.') fullname = prefix + name else: classname = '' fullname = name signode['module'] = modname signode['class'] = classname signode['fullname'] = fullname signode.attributes['lineno'] = lineno #sig_prefix = self.get_signature_prefix(sig) #if sig_prefix: # signode += addnodes.desc_annotation(sig_prefix, sig_prefix) if prefix: signode += addnodes.desc_addname(prefix, prefix) elif add_module and self.env.config.add_module_names: if modname and modname != 'exceptions': # exceptions are a special case, since they are documented in the # 'exceptions' module. #nodetext = modname + ' ID: ' #signode += addnodes.desc_addname(nodetext, nodetext) pass signode += addnodes.desc_name(name, cid) if arglist: _pseudo_parse_arglist(signode, arglist) else: if self.needs_arglist(): # for callables, add an empty parameter list signode += addnodes.desc_parameterlist() if retann: signode += addnodes.desc_returns(retann, retann) anno = self.options.get('annotation') if anno: signode += addnodes.desc_annotation(' ' + anno, ' ' + anno) return cid, prefix
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 visibility, modifiers, 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] # Method declared as Class::methodName if not classname and '::' in name_prefix: classname = name_prefix.rstrip('::') 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 if visibility: signode += addnodes.desc_annotation(visibility, visibility) sig_prefix = self.get_signature_prefix(sig) if modifiers and not (sig_prefix and 'static' in sig_prefix): signode += addnodes.desc_annotation(modifiers, modifiers) 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 _pseudo_parse_arglist(signode, arglist) if retann: signode += addnodes.desc_returns(retann, retann) return fullname, name_prefix
def handle_signature(self, sig: str, signode: desc_signature) -> Tuple[str, str]: """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 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.ref_context.get('py:module')) classname = self.env.ref_context.get('py:class') if classname: add_module = False if prefix and (prefix == classname or prefix.startswith(classname + ".")): fullname = prefix + name # class name is given again in the signature prefix = prefix[len(classname):].lstrip('.') elif prefix: # class name is given in the signature, but different # (shouldn't happen) fullname = classname + '.' + prefix + name else: # class name is not given in the signature fullname = classname + '.' + name else: add_module = True if prefix: classname = prefix.rstrip('.') fullname = 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 prefix: signode += addnodes.desc_addname(prefix, prefix) elif add_module and self.env.config.add_module_names: if modname and modname != 'exceptions': # exceptions are a special case, since they are documented in the # 'exceptions' module. nodetext = modname + '.' signode += addnodes.desc_addname(nodetext, nodetext) signode += addnodes.desc_name(name, name) if arglist: try: signode += _parse_arglist(arglist) except SyntaxError: # fallback to parse arglist original parser. # it supports to represent optional arguments (ex. "func(foo [, bar])") _pseudo_parse_arglist(signode, arglist) except NotImplementedError as exc: logger.warning("could not parse arglist (%r): %s", arglist, exc) _pseudo_parse_arglist(signode, arglist) else: if self.needs_arglist(): # for callables, add an empty parameter list signode += addnodes.desc_parameterlist() if retann: signode += addnodes.desc_returns(retann, retann) anno = self.options.get('annotation') if anno: signode += addnodes.desc_annotation(' ' + anno, ' ' + anno) return fullname, prefix
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