diff options
| author | Jon Waltman <jonathan.waltman@gmail.com> | 2012-11-10 23:37:42 -0600 |
|---|---|---|
| committer | Jon Waltman <jonathan.waltman@gmail.com> | 2012-11-10 23:37:42 -0600 |
| commit | 54734b4220674fe8bc07da0fa9765e6ea161590c (patch) | |
| tree | ea40dfaab5c82390ec795f8ca5fb547039ff4c49 | |
| parent | f7f70cf8034ef485e0c54d9a1b2c03be7535369f (diff) | |
| download | sphinx-54734b4220674fe8bc07da0fa9765e6ea161590c.tar.gz | |
Closes #681: Allow nested parentheses in C++ signatures (patch by Vadim and Jim Naslund)
| -rw-r--r-- | sphinx/domains/cpp.py | 38 | ||||
| -rw-r--r-- | tests/test_cpp_domain.py | 17 |
2 files changed, 43 insertions, 12 deletions
diff --git a/sphinx/domains/cpp.py b/sphinx/domains/cpp.py index a6392c1c..31daa1f6 100644 --- a/sphinx/domains/cpp.py +++ b/sphinx/domains/cpp.py @@ -760,17 +760,33 @@ class DefinitionParser(object): self.skip_ws() if self.match(_string_re): return self.matched_text - idx1 = self.definition.find(',', self.pos) - idx2 = self.definition.find(')', self.pos) - if idx1 < 0: - idx = idx2 - elif idx2 < 0: - idx = idx1 - else: - idx = min(idx1, idx2) - if idx < 0: - self.fail('unexpected end in default expression') - rv = self.definition[self.pos:idx] + paren_stack_depth = 0 + max_pos = len(self.definition) + rv_start = self.pos + while 1: + idx0 = self.definition.find('(', self.pos) + idx1 = self.definition.find(',', self.pos) + idx2 = self.definition.find(')', self.pos) + if idx0 < 0: + idx0 = max_pos + if idx1 < 0: + idx1 = max_pos + if idx2 < 0: + idx2 = max_pos + idx = min(idx0, idx1, idx2) + if idx >= max_pos: + self.fail('unexpected end in default expression') + if idx == idx0: + paren_stack_depth += 1 + elif idx == idx2: + paren_stack_depth -= 1 + if paren_stack_depth < 0: + break + elif paren_stack_depth == 0: + break + self.pos = idx+1 + + rv = self.definition[rv_start:idx] self.pos = idx return rv diff --git a/tests/test_cpp_domain.py b/tests/test_cpp_domain.py index 3ab8ece4..bd8aafa7 100644 --- a/tests/test_cpp_domain.py +++ b/tests/test_cpp_domain.py @@ -11,7 +11,7 @@ from util import * -from sphinx.domains.cpp import DefinitionParser +from sphinx.domains.cpp import DefinitionParser, DefinitionError def parse(name, string): @@ -73,6 +73,21 @@ def test_type_definitions(): x = 'module::myclass foo[n]' assert unicode(parse('member_object', x)) == x + x = 'int foo(Foo f=Foo(double(), std::make_pair(int(2), double(3.4))))' + assert unicode(parse('function', x)) == x + + x = 'int foo(A a=x(a))' + assert unicode(parse('function', x)) == x + + x = 'int foo(B b=x(a)' + raises(DefinitionError, parse, 'function', x) + + x = 'int foo)C c=x(a))' + raises(DefinitionError, parse, 'function', x) + + x = 'int foo(D d=x(a' + raises(DefinitionError, parse, 'function', x) + def test_bases(): x = 'A' |
