Skip to content

Commit 013c9ff

Browse files
committed
syntax: Fix function args
1 parent 32de302 commit 013c9ff

File tree

1 file changed

+11
-36
lines changed

1 file changed

+11
-36
lines changed

syntax/python.vim

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ syn keyword pythonOperator and in is not or
7878
" we provide a dummy group here to avoid crashing pyrex.vim.
7979
syn keyword pythonInclude import
8080
syn keyword pythonImport import
81-
syn match pythonIdentifier '\v[a-zA-Z_][a-zA-Z0-9_]*' nextgroup=FunctionParameters
81+
syn match pythonIdentifier '\v[a-zA-Z_][a-zA-Z0-9_]*' nextgroup=pythonFunctionArgs
8282
syn match pythonRaiseFromStatement '\<from\>'
8383
syn match pythonImport '^\s*\zsfrom\>'
8484

@@ -89,53 +89,28 @@ if s:Python2Syntax()
8989
syn keyword pythonStatement print
9090
endif
9191
syn keyword pythonImport as
92-
syn match pythonFunction '[a-zA-Z_][a-zA-Z0-9_]*' nextgroup=FunctionParameters display contained
92+
syn match pythonFunction '[a-zA-Z_][a-zA-Z0-9_]*' nextgroup=pythonFunctionArgs display contained
9393
else
9494
syn keyword pythonStatement as nonlocal
9595
syn match pythonStatement '\v\.@<!<await>'
96-
syn match pythonFunction '[a-zA-Z_][a-zA-Z0-9_]*' nextgroup=FunctionParameters display contained
96+
syn match pythonFunction '[a-zA-Z_][a-zA-Z0-9_]*' nextgroup=pythonFunctionArgs display contained
9797
syn match pythonStatement '\<async\s\+def\>' nextgroup=pythonFunction skipwhite
9898
syn match pythonStatement '\<async\s\+with\>'
9999
syn match pythonStatement '\<async\s\+for\>'
100100
syn cluster pythonExpression contains=pythonStatement,pythonRepeat,pythonConditional,pythonOperator,pythonNumber,pythonHexNumber,pythonOctNumber,pythonBinNumber,pythonFloat,pythonString,pythonBytes,pythonBoolean,pythonBuiltinObj,pythonBuiltinFunc
101101
endif
102102

103-
syn region FunctionParameters start='(\zs' end='\ze)' display contains=
104-
\ FunctionParameters,
105-
\ OptionalParameters,
106-
\ pythonRepeat,
107-
\ pythonClassVar,
108-
\ pythonConditional,
109-
\ pythonComment,
110-
\ pythonOperator,
111-
\ pythonNumber,
112-
\ pythonNumberError,
113-
\ pythonFloat,
114-
\ pythonHexNumber,
115-
\ pythonStatement,
116-
\ pythonOctNumber,
117-
\ pythonString,
118-
\ pythonRawString,
119-
\ pythonUniString,
120-
\ pythonExClass,
121-
\ pythonUniRawString,
122-
\ pythonNumber,
123-
\ pythonRawString,
124-
\ pythonBytes,
125-
\ pythonBuiltinObj,
126-
\ pythonNone,
127-
\ pythonBuiltinFunc,
128-
\ pythonBoolean nextgroup=pythonRaiseFromStatement display contained
129-
syn match OptionalParameters /\i\+\ze=/ display contained
103+
syn region pythonFunctionArgs start='('rs=s+1 end=')'re=e-1 contains=pythonFunctionArgs,pythonFunctionKwargs,pythonRepeat,pythonClassVar,pythonConditional,pythonComment,pythonOperator,pythonNumber,pythonNumberError,pythonFloat,pythonHexNumber,pythonStatement,pythonOctNumber,pythonString,pythonRawString,pythonUniString,pythonExClass,pythonUniRawString,pythonNumber,pythonRawString,pythonBytes,pythonBuiltinObj,pythonNone,pythonBuiltinFunc,pythonBoolean nextgroup=pythonRaiseFromStatement display contained
104+
syn match pythonFunctionKwargs /\i\+\ze=/ display contained
130105
"
131106
" Decorators (new in Python 2.4)
132107
"
133108

134109
syn match pythonDecorator '^\s*\zs@' display nextgroup=pythonDottedName skipwhite
135110
if s:Python2Syntax()
136-
syn match pythonDottedName '[a-zA-Z_][a-zA-Z0-9_]*\%(\.[a-zA-Z_][a-zA-Z0-9_]*\)*' display contained nextgroup=FunctionParameters
111+
syn match pythonDottedName '[a-zA-Z_][a-zA-Z0-9_]*\%(\.[a-zA-Z_][a-zA-Z0-9_]*\)*' display contained nextgroup=pythonFunctionArgs
137112
else
138-
syn match pythonDottedName '\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\%(\.\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\)*' display contained nextgroup=FunctionParameters
113+
syn match pythonDottedName '\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\%(\.\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\)*' display contained nextgroup=pythonFunctionArgs
139114
endif
140115
syn match pythonDot '\.' display containedin=pythonDottedName
141116

@@ -357,7 +332,7 @@ if s:Enabled('g:python_highlight_builtin_objs')
357332
syn keyword pythonNone None
358333
syn keyword pythonBoolean True False
359334
syn keyword pythonBuiltinObj Ellipsis NotImplemented
360-
syn match pythonBuiltinObj '\v\.@<!<%(object|bool|int|float|tuple|str|list|dict|set|frozenset|bytearray|bytes)>' nextgroup=FunctionParameters
335+
syn match pythonBuiltinObj '\v\.@<!<%(object|bool|int|float|tuple|str|list|dict|set|frozenset|bytearray|bytes)>' nextgroup=pythonFunctionArgs
361336
syn keyword pythonBuiltinObj __debug__ __doc__ __file__ __name__ __package__
362337
syn keyword pythonBuiltinObj __loader__ __spec__ __path__ __cached__
363338
endif
@@ -378,7 +353,7 @@ if s:Enabled('g:python_highlight_builtin_funcs')
378353
let s:funcs_re .= '|ascii|exec|memoryview|print'
379354
endif
380355

381-
execute 'syn match pythonBuiltinFunc ''\v\.@<!\zs<%(' . s:funcs_re . ')>\ze\('' nextgroup=FunctionParameters'
356+
execute 'syn match pythonBuiltinFunc ''\v\.@<!\zs<%(' . s:funcs_re . ')>\ze\('' nextgroup=pythonFunctionArgs'
382357
unlet s:funcs_re
383358
endif
384359

@@ -395,7 +370,7 @@ if s:Enabled('g:python_highlight_exceptions')
395370
let s:exs_re .= '|BlockingIOError|ChildProcessError|ConnectionError|BrokenPipeError|ConnectionAbortedError|ConnectionRefusedError|ConnectionResetError|FileExistsError|FileNotFoundError|InterruptedError|IsADirectoryError|NotADirectoryError|PermissionError|ProcessLookupError|TimeoutError|StopAsyncIteration|ResourceWarning'
396371
endif
397372

398-
execute 'syn match pythonExClass ''\v\.@<!\zs<%(' . s:exs_re . ')>'' nextgroup=FunctionParameters'
373+
execute 'syn match pythonExClass ''\v\.@<!\zs<%(' . s:exs_re . ')>'' nextgroup=pythonFunctionArgs'
399374
unlet s:exs_re
400375
endif
401376

@@ -488,7 +463,7 @@ if v:version >= 508 || !exists('did_python_syn_inits')
488463

489464
HiLink pythonExClass Structure
490465
HiLink pythonClassVar Identifier
491-
HiLink OptionalParameters Identifier
466+
HiLink pythonFunctionKwargs Identifier
492467

493468
delcommand HiLink
494469
endif

0 commit comments

Comments
 (0)