Pārlūkot izejas kodu

Fix lambda and list/slices broken after type annotation support

Joongi Kim 7 gadus atpakaļ
vecāks
revīzija
0e3ba78aad
2 mainītis faili ar 18 papildinājumiem un 3 dzēšanām
  1. 10
    2
      syntax/python.vim
  2. 8
    1
      test.py

+ 10
- 2
syntax/python.vim Parādīt failu

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

+ 8
- 1
test.py Parādīt failu

@@ -8,9 +8,12 @@
8 8
 
9 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 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 17
 yield from
15 18
 
16 19
 def functionname
@@ -29,6 +32,7 @@ def myfunc(a: str, something_other,
29 32
            b: Callable[[str, str], int]) -> Any:
30 33
     myval: float
31 34
     mygood: Optional[int, Any] = b('wow', 'oops')
35
+    myarr: Sequence[int] = origarr[aa:bb]
32 36
     mykey = a
33 37
     wow = {
34 38
         mykey: this_should_not_be_type_anno[Any],
@@ -39,6 +43,9 @@ def myfunc(a: str, something_other,
39 43
         'b': 'zxcb',
40 44
         mykey: this_should_not_be_type_anno[Any],
41 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 51
 # Builtin objects.