mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix #1513 highlights for function pointers in argument list of c:function
This commit is contained in:
@@ -39,6 +39,11 @@ c_funcptr_sig_re = re.compile(
|
|||||||
\( (.*) \) # arguments
|
\( (.*) \) # arguments
|
||||||
(\s+const)? $ # const specifier
|
(\s+const)? $ # const specifier
|
||||||
''', re.VERBOSE)
|
''', re.VERBOSE)
|
||||||
|
c_funcptr_arg_sig_re = re.compile(
|
||||||
|
r'''^\s*([^(,]+?) # return type
|
||||||
|
\( ([^()]+) \) \s* # name in parentheses
|
||||||
|
\( (.*) \) # arguments
|
||||||
|
''', re.VERBOSE)
|
||||||
c_funcptr_name_re = re.compile(r'^\(\s*\*\s*(.*?)\s*\)$')
|
c_funcptr_name_re = re.compile(r'^\(\s*\*\s*(.*?)\s*\)$')
|
||||||
|
|
||||||
|
|
||||||
@@ -80,6 +85,24 @@ class CObject(ObjectDescription):
|
|||||||
else:
|
else:
|
||||||
node += tnode
|
node += tnode
|
||||||
|
|
||||||
|
def _parse_arglist(self, arglist):
|
||||||
|
while True:
|
||||||
|
m = c_funcptr_arg_sig_re.match(arglist)
|
||||||
|
if m:
|
||||||
|
yield m.group()
|
||||||
|
arglist = c_funcptr_arg_sig_re.sub('', arglist)
|
||||||
|
if ',' in arglist:
|
||||||
|
_, arglist = arglist.split(',', 1)
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
if ',' in arglist:
|
||||||
|
arg, arglist = arglist.split(',', 1)
|
||||||
|
yield arg
|
||||||
|
else:
|
||||||
|
yield arglist
|
||||||
|
break
|
||||||
|
|
||||||
def handle_signature(self, sig, signode):
|
def handle_signature(self, sig, signode):
|
||||||
"""Transform a C signature into RST nodes."""
|
"""Transform a C signature into RST nodes."""
|
||||||
# first try the function pointer signature regex, it's more specific
|
# first try the function pointer signature regex, it's more specific
|
||||||
@@ -122,19 +145,23 @@ class CObject(ObjectDescription):
|
|||||||
paramlist = addnodes.desc_parameterlist()
|
paramlist = addnodes.desc_parameterlist()
|
||||||
arglist = arglist.replace('`', '').replace('\\ ', '') # remove markup
|
arglist = arglist.replace('`', '').replace('\\ ', '') # remove markup
|
||||||
# this messes up function pointer types, but not too badly ;)
|
# this messes up function pointer types, but not too badly ;)
|
||||||
args = arglist.split(',')
|
for arg in self._parse_arglist(arglist):
|
||||||
for arg in args:
|
|
||||||
arg = arg.strip()
|
arg = arg.strip()
|
||||||
param = addnodes.desc_parameter('', '', noemph=True)
|
param = addnodes.desc_parameter('', '', noemph=True)
|
||||||
try:
|
try:
|
||||||
ctype, argname = arg.rsplit(' ', 1)
|
m = c_funcptr_arg_sig_re.match(arg)
|
||||||
|
if m:
|
||||||
|
self._parse_type(param, m.group(1) + '(')
|
||||||
|
param += nodes.emphasis(m.group(2), m.group(2))
|
||||||
|
self._parse_type(param, ')(' + m.group(3) + ')')
|
||||||
|
else:
|
||||||
|
ctype, argname = arg.rsplit(' ', 1)
|
||||||
|
self._parse_type(param, ctype)
|
||||||
|
# separate by non-breaking space in the output
|
||||||
|
param += nodes.emphasis(' '+argname, u'\xa0'+argname)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
# no argument name given, only the type
|
# no argument name given, only the type
|
||||||
self._parse_type(param, arg)
|
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
|
paramlist += param
|
||||||
signode += paramlist
|
signode += paramlist
|
||||||
if const:
|
if const:
|
||||||
|
|||||||
Reference in New Issue
Block a user