Hi,

I think that if I use the cpp domain function (or member) directive to
match a class destructor like:

   .. cpp:function:: mynamespace::MyClass::~MyClass()

or

   .. cpp:member:: mynamespace::MyClass::~MyClass()

I get an error like:

   /path/to/simpletest/source/index.rst:26: WARNING: Invalid
definition: expected name [error at 22]
  mynamespace::MyClass::~MyClass()

My I might be doing it all wrong, but I think this is because of the
following regex:

http://bitbucket.org/birkenfeld/sphinx/src/d2f55686ba48/sphinx/domains/cpp.py#cl-26

which reads:

 _identifier_re = re.compile(r'\b(~?[a-zA-Z_][a-zA-Z0-9_]*)\b')

which tries to optionally match the "~" at the start of a word, but
when there is a "~" the "\b" is no longer at the start of a word
boundary, as words are only [a-zA-Z0-9_], which is why I think it
fails for me. The following python sessions shows an investigation and
possible solution.

>>> import re
>>> _identifier_re = re.compile(r'\b(~?[a-zA-Z_][a-zA-Z0-9_]*)\b')
>>> function = "MyClass::function"
>>> constructor = "MyClass::MyClass"
>>> destructor = "MyClass::~MyClass"
>>> print function[9]
f
>>> print constructor[9]
M
>>> print destructor[9]
~
>>> _identifier_re.match( function, 9 ).group(1)
'function'
>>> _identifier_re.match( constructor, 9 ).group(1)
'MyClass'
>>> _identifier_re.match( destructor, 9 ).group(1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'group'
>>> new_identifier_re = re.compile(r'(~?\b[a-zA-Z_][a-zA-Z0-9_]*)\b')
>>> new_identifier_re.match( function, 9 )
<_sre.SRE_Match object at 0x7ffcb18902d8>
>>> new_identifier_re.match( function, 9 ).group(1)
'function'
>>> new_identifier_re.match( constructor, 9 ).group(1)
'MyClass'
>>> new_identifier_re.match( destructor, 9 ).group(1)
'~MyClass'

Not confident enough with regexes to know if that is the best
solution, but hopefully worth considering.

Sorry to not fork and patch on bitbucket but my main computer access
is behind a company proxy and I'm not sure how to setup hg around
that.

Cheers,
Michael

-- 
You received this message because you are subscribed to the Google Groups 
"sphinx-dev" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sphinx-dev?hl=en.

Reply via email to