Browse Source

Fix lambda and list/slices broken after type annotation support

Joongi Kim 7 years ago
parent
commit
0e3ba78aad
2 changed files with 18 additions and 3 deletions
  1. 10
    2
      syntax/python.vim
  2. 8
    1
      test.py

+ 10
- 2
syntax/python.vim View File

154
 syn keyword pythonStatement     exec return
154
 syn keyword pythonStatement     exec return
155
 syn keyword pythonStatement     pass raise
155
 syn keyword pythonStatement     pass raise
156
 syn keyword pythonStatement     global assert
156
 syn keyword pythonStatement     global assert
157
-syn keyword pythonStatement     lambda
158
 syn keyword pythonStatement     with
157
 syn keyword pythonStatement     with
159
 syn keyword pythonStatement     def class nextgroup=pythonFunction skipwhite
158
 syn keyword pythonStatement     def class nextgroup=pythonFunction skipwhite
160
 syn keyword pythonRepeat        for while
159
 syn keyword pythonRepeat        for while
166
 syn match   pythonIdentifier    "\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" nextgroup=pythonFuncArgs,pythonTypeAnno display
165
 syn match   pythonIdentifier    "\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" nextgroup=pythonFuncArgs,pythonTypeAnno display
167
 syn keyword pythonException     try except finally
166
 syn keyword pythonException     try except finally
168
 syn keyword pythonOperator      and in is not or
167
 syn keyword pythonOperator      and in is not or
168
+syn match pythonLambdaExpr   "\<lambda[^:]*:"he=s+6 display nextgroup=@pythonExpression
169
+"syn keyword pythonStatement     lambda
169
 
170
 
170
 syn region pythonDictSetExpr matchgroup=pythonDictSetExpr start='{' end='}' contains=@pythonExpression
171
 syn region pythonDictSetExpr matchgroup=pythonDictSetExpr start='{' end='}' contains=@pythonExpression
172
+syn region pythonListSliceExpr matchgroup=pythonListSliceExpr start='\[' end='\]' contains=@pythonExpression
171
 syn region pythonFuncArgs    matchgroup=pythonFuncArgs    start='(' end=')' contained contains=pythonTypeAnno,@pythonExpression
173
 syn region pythonFuncArgs    matchgroup=pythonFuncArgs    start='(' end=')' contained contains=pythonTypeAnno,@pythonExpression
172
 
174
 
173
 syn match pythonTypeAnno ":\s*\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*"hs=s+1 display contained contains=pythonType nextgroup=pythonTypeArgs
175
 syn match pythonTypeAnno ":\s*\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*"hs=s+1 display contained contains=pythonType nextgroup=pythonTypeArgs
174
-syn match pythonTypeAnnoReturn "->\s*\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*"hs=s+2,he=e-1 display contains=pythonType nextgroup=pythonTypeArgs
176
+syn match pythonTypeAnnoReturn "->\s*\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" display contains=pythonType nextgroup=pythonTypeArgs
175
 syn region pythonTypeArgs matchgroup=pythonTypeArgs start='\[' end='\]' display contained contains=pythonType,pythonTypeArgs
177
 syn region pythonTypeArgs matchgroup=pythonTypeArgs start='\[' end='\]' display contained contains=pythonType,pythonTypeArgs
176
 syn keyword pythonType Any AnyStr Callable ClassVar Tuple Union Optional Type TypeVar None contained
178
 syn keyword pythonType Any AnyStr Callable ClassVar Tuple Union Optional Type TypeVar None contained
177
 syn keyword pythonType AbstractSet MutableSet Mapping MutableMapping Sequence MutableSequence ByteString Deque List contained
179
 syn keyword pythonType AbstractSet MutableSet Mapping MutableMapping Sequence MutableSequence ByteString Deque List contained
203
 syn cluster pythonExpression contains=
205
 syn cluster pythonExpression contains=
204
             \ pythonFuncArgs,
206
             \ pythonFuncArgs,
205
             \ pythonDictSetExpr,
207
             \ pythonDictSetExpr,
208
+            \ pythonListSliceExpr,
209
+            \ pythonLambdaExpr,
206
             \ pythonStatement,
210
             \ pythonStatement,
207
             \ pythonRepeat,
211
             \ pythonRepeat,
208
             \ pythonConditional,
212
             \ pythonConditional,
225
 
229
 
226
 syn cluster pythonFExpression contains=
230
 syn cluster pythonFExpression contains=
227
             \ pythonStatement,
231
             \ pythonStatement,
232
+            \ pythonDictSetExpr,
233
+            \ pythonListSliceExpr,
234
+            \ pythonLambdaExpr,
228
             \ pythonRepeat,
235
             \ pythonRepeat,
229
             \ pythonConditional,
236
             \ pythonConditional,
230
             \ pythonOperator,
237
             \ pythonOperator,
559
   endif
566
   endif
560
 
567
 
561
   HiLink pythonStatement        Statement
568
   HiLink pythonStatement        Statement
569
+  HiLink pythonLambdaExpr       Statement
562
   HiLink pythonImport           Include
570
   HiLink pythonImport           Include
563
   HiLink pythonFunction         Function
571
   HiLink pythonFunction         Function
564
   HiLink pythonConditional      Conditional
572
   HiLink pythonConditional      Conditional

+ 8
- 1
test.py View File

8
 
8
 
9
 # Keywords.
9
 # Keywords.
10
 
10
 
11
-with break continue del exec return pass print raise global assert lambda yield
11
+with break continue del exec return pass print raise global assert yield
12
 for while if elif else import from as try except finally and in is not or
12
 for while if elif else import from as try except finally and in is not or
13
 
13
 
14
+lambda: a + 1
15
+lambda x, y: x + y
16
+
14
 yield from
17
 yield from
15
 
18
 
16
 def functionname
19
 def functionname
29
            b: Callable[[str, str], int]) -> Any:
32
            b: Callable[[str, str], int]) -> Any:
30
     myval: float
33
     myval: float
31
     mygood: Optional[int, Any] = b('wow', 'oops')
34
     mygood: Optional[int, Any] = b('wow', 'oops')
35
+    myarr: Sequence[int] = origarr[aa:bb]
32
     mykey = a
36
     mykey = a
33
     wow = {
37
     wow = {
34
         mykey: this_should_not_be_type_anno[Any],
38
         mykey: this_should_not_be_type_anno[Any],
39
         'b': 'zxcb',
43
         'b': 'zxcb',
40
         mykey: this_should_not_be_type_anno[Any],
44
         mykey: this_should_not_be_type_anno[Any],
41
     }, b=mydata['a'])
45
     }, b=mydata['a'])
46
+    vanilla_lambda = lambda x, y: myval + 1.0
47
+    call_with_lambda(lambda x, y: myval + 1.0)
48
+    call_with_slice(mydata[range_start:range_end])
42
 
49
 
43
 
50
 
44
 # Builtin objects.
51
 # Builtin objects.