Skip to content

Commit

Permalink
Add support for default values in method signatures that contain brac…
Browse files Browse the repository at this point in the history
…kets
  • Loading branch information
djungelorm committed Jan 25, 2018
1 parent b0f3d38 commit ab8aef1
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGES.txt
@@ -1,3 +1,6 @@
v0.1.6
* Allow default values in method signatures to contain brackets

v0.1.5
* Support Sphinx >= 1.3
* Fix future deprecation in Sphinx 1.7
Expand Down
12 changes: 6 additions & 6 deletions sphinx_csharp/csharp.py
Expand Up @@ -30,7 +30,7 @@
r'\{\s*(get;)?\s*(set;)?\s*\}$')
PARAM_SIG_RE = re.compile(
r'^((?:(?:' + PARAM_MODIFIERS_RE +
r')\s+)*)([^\s]+)\s+([^\s]+)\s*(=\s*([^\s]+))?$')
r')\s+)*)([^\s]+)\s+([^\s]+)\s*(=\s*(.+))?$')
TYPE_SIG_RE = re.compile(r'^([^\s<\[]+)\s*(<.+>)?\s*(\[\])?$')
ATTR_SIG_RE = re.compile(r'^([^\s]+)(\s+\((.*)\))?$')
ParamTuple = namedtuple('ParamTuple', ['name', 'typ', 'default', 'modifiers'])
Expand All @@ -39,19 +39,19 @@
def split_sig(params):
"""
Split a list of parameters/types by commas,
whilst respecting angle brackets.
whilst respecting brackets.
For example:
String arg0, int arg2 = 1, Dictionary<int,int> arg3
=> ['String arg0', 'int arg2 = 1', 'Dictionary<int,int> arg3']
String arg0, int arg2 = 1, List<int> arg3 = [1, 2, 3]
=> ['String arg0', 'int arg2 = 1', 'List<int> arg3 = [1, 2, 3]']
"""
result = []
current = ''
level = 0
for char in params:
if char == '<':
if char in ('<', '{', '['):
level += 1
elif char == '>':
elif char in ('>', '}', ']'):
level -= 1
if char != ',' or level > 0:
current += char
Expand Down
3 changes: 2 additions & 1 deletion test/conf.py
Expand Up @@ -11,5 +11,6 @@

nitpick_ignore = [
('csharp:type', 'void'),
('csharp:type', 'T')
('csharp:type', 'T'),
('csharp:type', 'List')
]
4 changes: 4 additions & 0 deletions test/index.rst
Expand Up @@ -27,6 +27,10 @@

A method with a default argument value.

.. method:: void MyMethodDefaultArgs (int x, bool y = true, List<string> arg = [ "foo", "bar", "baz" ], bool z = false)

A method with default argument values.

.. method:: void MyMethodNoArgs ()

A method with no arguments.
Expand Down

0 comments on commit ab8aef1

Please sign in to comment.