diff --git a/vimdoc/parser.py b/vimdoc/parser.py index 66e9bdd..2b85da0 100644 --- a/vimdoc/parser.py +++ b/vimdoc/parser.py @@ -4,6 +4,7 @@ from vimdoc import error from vimdoc import regex +import re def IsComment(line): @@ -78,7 +79,16 @@ def ParseCodeLine(line): fmatch = regex.function_line.match(line) if fmatch: namespace, name, args = fmatch.groups() - return codeline.Function(name, namespace, regex.function_arg.findall(args)) + # https://stackoverflow.com/a/25471762 + args_list = re.split(r',\s*(?=(?:"[^"]*?(?: [^"]*)*))|,\s*(?=[^",]+(?:,|$))', args) + args_groupdicts = [regex.function_arg.match(x).groupdict() for x in args_list] + args_names = [] + for groupdict in args_groupdicts: + if groupdict.get('key') is not None and groupdict.get('value') is not None: + args_names.append(groupdict.get('key')) + elif groupdict.get('label') is not None: + args_names.append(groupdict.get('label')) + return codeline.Function(name, namespace, args_names) cmatch = regex.command_line.match(line) if cmatch: args, name = cmatch.groups() diff --git a/vimdoc/regex.py b/vimdoc/regex.py index 725fe28..4ef8cc1 100644 --- a/vimdoc/regex.py +++ b/vimdoc/regex.py @@ -378,6 +378,26 @@ def _DelimitedRegex(pattern): ) """, re.VERBOSE) -function_arg = re.compile(r'([a-zA-Z_][a-zA-Z0-9_]*|\.\.\.)') +function_arg = re.compile(r""" + # Match inputs like `bar = g:bar` or `wat = "woot"` or `foo = 41968` + ( + (?P[a-zA-Z_][a-zA-Z0-9_]*) + (\s*\=\s*) + # Could be within double or single quotes, or bare reference to a variable + (?P + ("[a-zA-Z0-9_:\.]*") + | ('[a-zA-Z0-9_:\.]*') + | ([a-zA-Z0-9_:\.]*) + ) + ) + | + # Match inputs like `oWoo_Hu` and `...` + (?P