浏览代码

Add support for union operator ("|") in annotation

* An example to use this style: tarfaret library
Joongi Kim 8 年前
父节点
当前提交
09357048ac
共有 1 个文件被更改,包括 6 次插入2 次删除
  1. 6
    2
      syntax/python.vim

+ 6
- 2
syntax/python.vim 查看文件

173
 
173
 
174
 syn region pythonDictSetExpr matchgroup=pythonDictSetExpr start='{' end='}' contains=@pythonExpression
174
 syn region pythonDictSetExpr matchgroup=pythonDictSetExpr start='{' end='}' contains=@pythonExpression
175
 syn region pythonListSliceExpr matchgroup=pythonListSliceExpr start='\[' end='\]' contains=@pythonExpression
175
 syn region pythonListSliceExpr matchgroup=pythonListSliceExpr start='\[' end='\]' contains=@pythonExpression
176
-syn region pythonFuncArgs    matchgroup=pythonFuncArgs    start='(' end=')' contained contains=pythonTypeAnno,@pythonExpression
176
+syn region pythonFuncArgs    matchgroup=pythonFuncArgs    start='(' end=')' contained contains=@pythonTypeExpression,@pythonExpression
177
 
177
 
178
 if !s:Python2Syntax()
178
 if !s:Python2Syntax()
179
   if s:Enabled("g:python_highlight_type_annotations")
179
   if s:Enabled("g:python_highlight_type_annotations")
180
-    syn match pythonTypeAnno @:\s*['"]\?\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\%(\.\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\)*['"]\?@hs=s+1 display contained contains=pythonType,pythonString nextgroup=pythonTypeArgs
180
+    syn match pythonTypeAnno @:\s*['"]\?\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\%(\.\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\)*['"]\?@hs=s+1 display contained contains=pythonType,pythonString nextgroup=pythonTypeUnion,pythonTypeArgs
181
+    syn match pythonTypeUnion @\s*|\s*['"]\?\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\%(\.\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\)*['"]\?@ display contained contains=pythonType,pythonString nextgroup=pythonTypeUnion
181
     syn match pythonTypeAnnoReturn @->\s*['"]\?\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\%(\.\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\)*['"]\?@ display contains=pythonType,pythonString nextgroup=pythonTypeArgs
182
     syn match pythonTypeAnnoReturn @->\s*['"]\?\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\%(\.\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\)*['"]\?@ display contains=pythonType,pythonString nextgroup=pythonTypeArgs
182
     syn region pythonTypeArgs matchgroup=pythonTypeArgs start='\[' end='\]' display contained contains=pythonType,pythonString,pythonTypeArgs
183
     syn region pythonTypeArgs matchgroup=pythonTypeArgs start='\[' end='\]' display contained contains=pythonType,pythonString,pythonTypeArgs
183
     syn keyword pythonType Any AnyStr Callable ClassVar Tuple Union Optional Type TypeVar None contained
184
     syn keyword pythonType Any AnyStr Callable ClassVar Tuple Union Optional Type TypeVar None contained
209
   syn match   pythonStatement   "\<async\s\+for\>" display
210
   syn match   pythonStatement   "\<async\s\+for\>" display
210
 endif
211
 endif
211
 
212
 
213
+syn cluster pythonTypeExpression contains=pythonTypeAnno,pythonTypeUnion,pythonTypeArgs
214
+
212
 syn cluster pythonExpression contains=
215
 syn cluster pythonExpression contains=
213
             \ pythonFuncArgs,
216
             \ pythonFuncArgs,
214
             \ pythonDictSetExpr,
217
             \ pythonDictSetExpr,
641
   HiLink pythonExClass          Structure
644
   HiLink pythonExClass          Structure
642
 
645
 
643
   HiLink pythonTypeAnno         Optional
646
   HiLink pythonTypeAnno         Optional
647
+  HiLink pythonTypeUnion        Optional
644
   HiLink pythonTypeAnnoReturn   Optional
648
   HiLink pythonTypeAnnoReturn   Optional
645
   HiLink pythonTypeArgs         Optional
649
   HiLink pythonTypeArgs         Optional
646
   HiLink pythonType             Special
650
   HiLink pythonType             Special