本文整理汇总了Python中sphinx.addnodes.desc_type函数的典型用法代码示例。如果您正苦于以下问题:Python desc_type函数的具体用法?Python desc_type怎么用?Python desc_type使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了desc_type函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: foobar
def foobar(argument, is_last, param):
parts = argument.replace('[]', '()').split(' ')
if len(parts) != 4:
raise ValueError("Argument '{0}' has unexpected format".format(argument))
param += addnodes.desc_type(parts[0] + ' ', parts[0] + ' ')
param += nodes.emphasis(parts[1] + ' ', parts[1] + ' ')
param += addnodes.desc_type(' '.join(parts[2:]), ' '.join(parts[2:]))
if not is_last:
param += nodes.emphasis(', ', ', ')
示例2: foobar
def foobar(argument, is_last, param):
parts = argument.split(':')
name = parts[0].split(' ')
if len(name) > 1:
param += addnodes.desc_type(name[0] + ' ', name[0] + ' ')
param += nodes.emphasis(' '.join(name[1:]) + ': ', ' '.join(name[1:]) + ': ')
else:
param += nodes.emphasis(name[0] + ': ', name[0] + ': ')
param += addnodes.desc_type(parts[-1], parts[-1])
if not is_last:
param += nodes.emphasis('; ', '; ')
示例3: _make_index_section
def _make_index_section(self, obj, title, id):
section = self._make_section(title)
subobjs = obj.filter_by_id(id)
kwargs = {
'refdomain': 'cpp',
'refexplicit': False,
}
if subobjs:
lst = addnodes.desc()
lst['objtype'] = 'function function-index'
for obj in subobjs:
desc = addnodes.desc_signature()
span = nodes.inline()
try:
kwargs['reftype'] = 'func'
if obj.rv is not None:
span += addnodes.desc_type(text=str(obj.rv))
except AttributeError:
kwargs['reftype'] = 'member'
span += addnodes.desc_type(text=str(obj.typename))
desc += span
desc += nodes.Text(u' ')
name = unicode(obj.name)
kwargs['reftarget'] = unicode(obj.get_name())
name = name.split('::')[-1]
desc_name = addnodes.desc_name()
refnode = addnodes.pending_xref('', **kwargs)
innernode = nodes.literal(text=name)
innernode.attributes['classes'].extend(['xref', 'cpp', 'cpp-func'])
refnode += innernode
desc_name += refnode
desc += desc_name
try:
paramlist = addnodes.desc_parameterlist()
for param_obj in obj.signature:
param = addnodes.desc_parameter('', '', noemph=True)
if param_obj.type is not None:
param += nodes.Text(str(param_obj.type) + ' ')
param += nodes.emphasis(text=str(param_obj.name))
paramlist += param
desc += paramlist
if obj.const:
desc += nodes.Text(u' const')
except AttributeError:
pass
lst += desc
section += lst
return section
return None
示例4: handle_signature
def handle_signature(self, sig, signode):
m = ks_sig_re.match(sig)
name = m.group('object')
struct = None #might override further down
current_struct = self.env.temp_data.get('ks:structure')
if m.group('prefix') is None:
if current_struct is not None:
struct = current_struct
fullname = current_struct + ':' + name
else:
raise Exception("Method name lacks a prefix and isn't " +
"indented inside a structure section. Problem " +
"occurred at " + self.env.docname + ", line " +
str(self.lineno) +
".")
else:
struct = m.group('prefix').split(':')[-1]
fullname = struct + ':' + name
if struct is not None:
if struct != '':
signode += addnodes.desc_type(struct,struct+':')
signode += addnodes.desc_name(fullname, name)
args = m.group('args')
if args:
signode += addnodes.desc_parameterlist(args,args)
else:
signode += addnodes.desc_parameterlist()
return fullname
示例5: handle_field_signature
def handle_field_signature(self, sig, signode):
try:
member = javalang.parse.parse_member_signature(sig)
except javalang.parser.JavaSyntaxError:
raise self.error("syntax error in field signature")
if not isinstance(member, javalang.tree.FieldDeclaration):
raise self.error("expected field declaration")
mods = formatter.output_modifiers(member.modifiers).build()
signode += nodes.Text(mods + ' ', mods + ' ')
tnode = addnodes.desc_type('', '')
tnode += self._build_type_node(member.type)
signode += tnode
signode += nodes.Text(' ', ' ')
if len(member.declarators) > 1:
self.error('only one field may be documented at a time')
declarator = member.declarators[0]
signode += addnodes.desc_name(declarator.name, declarator.name)
dim = '[]' * len(declarator.dimensions)
signode += nodes.Text(dim)
if declarator.initializer and isinstance(declarator.initializer, javalang.tree.Literal):
signode += nodes.Text(' = ' + declarator.initializer.value)
return declarator.name
示例6: render
def render(self):
title = self.title()
rettype, name, arglist, const, signature = self.directive.parse_title(title)
fullname = self.directive.get_full_name(name)
if self.data_object.kind == "function":
# set True that this might be a structure method
self.directive.sphinx_directive.typemethod_set = True
target = self.directive.create_target(fullname)
if self.data_object.kind == "function":
self.directive.sphinx_directive.typemethod_set = False
# add a signature node
signode = addnodes.desc_signature(signature, '')
signode['first'] = False
signode += addnodes.desc_type('', '')
self.directive.add_return_type(signode[-1] , rettype)
name = self.directive.add_sig_name(signode, name)
self.directive.add_sig_args(signode, arglist, const)
description_nodes = self.description()
content_node = addnodes.desc_content('')
content_node += description_nodes
target.extend(signode)
term = self.node_factory.term("","", ids=[name], *target )
entry = self.node_factory.definition_list_item("",term, content_node)
return [entry]
示例7: handle_signature
def handle_signature(self, sig, signode):
"""Transform a C signature into RST nodes."""
# first try the function pointer signature regex, it's more specific
m = c_funcptr_sig_re.match(sig)
if m is None:
m = c_sig_re.match(sig)
if m is None:
raise ValueError('no match')
rettype, name, arglist, const = m.groups()
signode += addnodes.desc_type('', '')
self._parse_type(signode[-1], rettype)
try:
classname, funcname = name.split('::', 1)
classname += '::'
signode += addnodes.desc_addname(classname, classname)
signode += addnodes.desc_name(funcname, funcname)
# name (the full name) is still both parts
except ValueError:
signode += addnodes.desc_name(name, name)
# clean up parentheses from canonical name
m = c_funcptr_name_re.match(name)
if m:
name = m.group(1)
typename = self.env.temp_data.get('c:type')
if self.name == 'c:member' and typename:
fullname = typename + '.' + name
else:
fullname = name
if not arglist:
if self.objtype == 'function':
# for functions, add an empty parameter list
signode += addnodes.desc_parameterlist()
if const:
signode += addnodes.desc_addname(const, const)
return fullname
paramlist = addnodes.desc_parameterlist()
arglist = arglist.replace('`', '').replace('\\ ', '') # remove markup
# this messes up function pointer types, but not too badly ;)
args = arglist.split(',')
for arg in args:
arg = arg.strip()
param = addnodes.desc_parameter('', '', noemph=True)
try:
ctype, argname = arg.rsplit(' ', 1)
except ValueError:
# no argument name given, only the type
self._parse_type(param, arg)
else:
self._parse_type(param, ctype)
# separate by non-breaking space in the output
param += nodes.emphasis(' '+argname, u'\xa0'+argname)
paramlist += param
signode += paramlist
if const:
signode += addnodes.desc_addname(const, const)
return fullname
示例8: _handle_object_signature
def _handle_object_signature(self, sig, signode, m):
"Transform a Nim object into RST nodes."
name = m.groups()[0]
signode += addnodes.desc_type('object', 'object')
signode += addnodes.desc_name(name, name)
return name
示例9: _pseudo_parse_arglist
def _pseudo_parse_arglist(signode, arglist):
paramlist = desc_parameterlist()
param = addnodes.desc_type()
def foobar(argument, is_last, param):
parts = argument.split(':')
name = parts[0].split(' ')
if len(name) > 1:
param += addnodes.desc_type(name[0] + ' ', name[0] + ' ')
param += nodes.emphasis(' '.join(name[1:]) + ': ', ' '.join(name[1:]) + ': ')
else:
param += nodes.emphasis(name[0] + ': ', name[0] + ': ')
param += addnodes.desc_type(parts[-1], parts[-1])
if not is_last:
param += nodes.emphasis('; ', '; ')
arguments = arglist.split(';')
for argument in arguments[:-1]:
foobar(argument.strip(), False, param)
foobar(arguments[-1].strip(), True, param)
paramlist += param
signode += paramlist
示例10: handle_signature
def handle_signature(self, sig, signode):
try:
tag, name = sig.split()
except ValueError:
tag, name = None, sig
cache = _APP_CACHES.get(self.env.app, {})
key = {'struct': CursorKind.STRUCT_DECL}[tag], (name, )
if key in cache:
node, comment, start, end, members = cache[key]
signode += addnodes.desc_type(tag, tag + ' ')
signode += addnodes.desc_name(node.spelling, node.spelling)
self.content = ViewList()
for line in comment.splitlines():
self.content.append(line, '<unknown>')
self.content.append('', '<unknown>')
for (_, member_name), value in members.items():
member_node, member_comment, _, _, _ = value
self.content.append(
'.. c:member:: %s %s' % (member_node.type.spelling, member_node.spelling),
'<unknown>'
)
self.content.append('', '<unknown>')
for line in member_comment.splitlines():
self.content.append(' ' + line, '<unknown>')
self.content.append('', '<unknown>')
return sig
示例11: handle_signature
def handle_signature(self, sig, signode):
m = ks_sig_re.match(sig)
name = m.group('object')
current_struct = self.env.temp_data.get('ks:structure')
if m.group('prefix') is None:
if current_struct is not None:
fullname = current_struct + ':' + name
else:
struct = m.group('prefix').split(':')[-1]
fullname = struct + ':' + name
if struct is not None:
if struct != '':
signode += addnodes.desc_type(struct,struct+':')
signode += addnodes.desc_name(fullname, name)
args = m.group('args')
if args:
signode += addnodes.desc_parameterlist(args,args)
else:
signode += addnodes.desc_parameterlist()
return fullname
示例12: render
def render(self):
title = self.title()
rettype, name, arglist, const, signature = self.directive.parse_title(title)
target = self.directive.create_target(name)
# add a signature node
signode = addnodes.desc_signature(signature, '')
signode['first'] = False
signode += addnodes.desc_type('', '')
self.directive.add_return_type(signode[-1] , rettype)
name = self.directive.add_sig_name(signode, name)
self.directive.set_name(name)
self.directive.add_sig_args(signode, arglist, const)
self.directive.before_content()
description_nodes = self.description()
content_node = addnodes.desc_content('')
content_node += description_nodes
self.directive.after_content()
target.extend(signode)
term = self.node_factory.term("","", ids=[name], *target )
entry = self.node_factory.definition_list_item("",term, content_node)
return [entry]
示例13: handle_signature
def handle_signature(self, sig, signode):
"""
Transform a CFEngine 3 signature into RST nodes.
"""
sig_d = {}
m = cf3_sig_re.match(sig)
try:
sig_d['type'], sig_d['ns'], sig_d['id'], sig_d['args'] = m.groups()
except AttributeError:
raise ValueError
sig_d['ns'] = sig_d['ns'] or self.options.get(
'namespace', self.env.temp_data.get('cf3:namespace')
)
fullname = []
fn_app = fullname.append
fn_app(self.objtype + _FN_SEP)
if self.objtype in ('body', 'bundle'):
tnode = addnodes.desc_type('', '')
tnode += nodes.Text(self.objtype + _SP, self.objtype)
try:
sig_d['type'] = sig_d['type'].strip()
tnode += nodes.Text(sig_d['type'] + _SP, sig_d['type'])
fn_app(sig_d['type'] + _FN_SEP)
except AttributeError:
self.state_machine.reporter.warning(
'invalid %s definition: %s' % (self.objtype, sig),
line=self.lineno
)
signode += tnode
if sig_d['ns'] and sig_d['ns'] != 'default' \
and self.env.config.add_module_names:
signode += addnodes.desc_addname(
sig_d['ns'], sig_d['ns'] + _NS_SEP
)
signode += addnodes.desc_name(sig_d['id'], sig_d['id'])
fn_app(sig_d['id'])
signode['namespace'] = sig_d['ns']
signode['fullname'] = ''.join(fullname)
if self.objtype == 'class':
signode += addnodes.desc_name(_CL_MRK, _CL_MRK)
return ''.join(fullname), sig_d['ns']
if not sig_d['args'] and self.objtype == 'function':
signode += addnodes.desc_parameterlist()
return ''.join(fullname), sig_d['ns']
if sig_d['args']:
paramlist = addnodes.desc_parameterlist()
for arg in sig_d['args'].split(','):
arg = arg.strip()
paramlist += addnodes.desc_parameter(arg, arg)
signode += paramlist
return ''.join(fullname), sig_d['ns']
示例14: _handle_enum_signature
def _handle_enum_signature(self, sig, signode, m):
"Transform a Nim enum into RST nodes."
name, values = m.groups()
signode += addnodes.desc_type('enum', 'enum')
signode += addnodes.desc_name(name, name)
signode += addnodes.desc_addname(values, '= ' + values)
return name
示例15: p_expression_word
def p_expression_word(p):
'''expression : WORD
| WORD STAR
| WORD STAR STAR
| WORD LT WORD GT
| ENUM WORD
| VOID '''
p[0] = addnodes.desc_type(" ".join(p[1:]), " ".join(p[1:]))