Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion vimdoc/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from vimdoc import error
from vimdoc import regex
import re


def IsComment(line):
Expand Down Expand Up @@ -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()
Expand Down
22 changes: 21 additions & 1 deletion vimdoc/regex.py
Original file line number Diff line number Diff line change
Expand Up @@ -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<key>[a-zA-Z_][a-zA-Z0-9_]*)
(\s*\=\s*)
# Could be within double or single quotes, or bare reference to a variable
(?P<value>
("[a-zA-Z0-9_:\.]*")
| ('[a-zA-Z0-9_:\.]*')
| ([a-zA-Z0-9_:\.]*)
)
)
|
# Match inputs like `oWoo_Hu` and `...`
(?P<label>
# Any word that starts with letters, may end with numbers, or contain underscore
[a-zA-Z_][a-zA-Z0-9_]*
# Or literal three periods
|\.\.\.
)
""", re.VERBOSE)

list_item = re.compile(r'^\s*([*+-]|\d+\.)\s+')