Skip to content

Commit ffbdace

Browse files
committed
Better scopes for "async def"; Add all built-in exceptions and warnings.
Also, stop highlighting 'AbracadabraError' as a built-in error class.
1 parent 64b9a46 commit ffbdace

File tree

2 files changed

+116
-42
lines changed

2 files changed

+116
-42
lines changed

PythonImproved-Unicode.YAML-tmLanguage

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,11 @@ patterns:
7777
match: \b(None|True|False|Ellipsis|NotImplemented)\b
7878

7979
- name: storage.modifier.declaration.python
80-
match: \b(global|nonlocal|async)\b
80+
match: \b(global|nonlocal)\b
8181

8282
- name: keyword.control.import.python
8383
match: \b(?:(import|from|as))\b
8484

85-
- comment: keywords that delimit flow blocks or alter flow from within a block
86-
name: keyword.control.flow.python
87-
match: \b(await|break|continue|elif|else|except|finally|for|if|pass|raise|return|try|while|with|yield)\b
88-
8985
- comment: keyword operators that evaluate to True or False
9086
name: keyword.operator.logical.python
9187
match: \b(and|in|is|not|or)\b
@@ -168,7 +164,7 @@ patterns:
168164
- include: '#entity_name_function'
169165

170166
- name: meta.function.python
171-
begin: \s*(def)\s+(?=[\p{Alpha}_][\p{Alnum}_]*\s*\()
167+
begin: \s*((?:async\s+)?def)\s+(?=[\p{Alpha}_][\p{Alnum}_]*\s*\()
172168
beginCaptures:
173169
'1': {name: storage.type.function.python}
174170
end: (\:)
@@ -203,7 +199,7 @@ patterns:
203199
- include: $self
204200

205201
- name: meta.function.python
206-
begin: \s*(def)\s+(?=[\p{Alpha}_][\p{Alnum}_]*)
202+
begin: \s*((?:async\s+)?def)\s+(?=[\p{Alpha}_][\p{Alnum}_]*)
207203
beginCaptures:
208204
'1': {name: storage.type.function.python}
209205
end: (\()|\s*($\n?|#.*$\n?)
@@ -217,6 +213,26 @@ patterns:
217213
patterns:
218214
- include: '#entity_name_function'
219215

216+
- match: \b(((?:async\s+)?def)|lambda)\b
217+
captures:
218+
'1': {name: storage.type.function.python}
219+
220+
-
221+
comment: |
222+
Keywords that delimit flow blocks or alter flow from within a
223+
block.
224+
225+
This block should be matched *after* meta.function.python to
226+
let 'async def' be matched *first*.
227+
228+
name: keyword.control.flow.python
229+
match: |
230+
(?x) \b(
231+
async | await | break | continue | elif | else | except | finally | for |
232+
if | pass | raise | return | try | while | with |
233+
(yield(?:\s+from)?)
234+
)\b
235+
220236
- name: meta.function.inline.python
221237
begin: (lambda)(?=\s+|:)
222238
beginCaptures:
@@ -350,10 +366,6 @@ patterns:
350366
patterns:
351367
- include: $self
352368

353-
- match: \b(def|lambda)\b
354-
captures:
355-
'1': {name: storage.type.function.python}
356-
357369
- match: \b(class)\b
358370
captures:
359371
'1': {name: storage.type.class.python}
@@ -474,7 +486,30 @@ repository:
474486

475487
builtin_exceptions:
476488
name: support.type.exception.python
477-
match: \b((Arithmetic|Assertion|Attribute|Buffer|EOF|Environment|FloatingPoint|IO|Import|Indentation|Index|Key|Lookup|Memory|Name|NotImplemented|OS|Overflow|Reference|Runtime|Standard|Syntax|System|Tab|Type|UnboundLocal|Unicode(Encode|Decode|Translate)?|Value|VMS|Windows|ZeroDivision|([\p{Alpha}_][\p{Alnum}_]*))?Error|((Pending)?Deprecation|Runtime|Syntax|User|Future|Import|Unicode|Bytes)?Warning|SystemExit|Stop(Async)?Iteration|NotImplemented|KeyboardInterrupt|GeneratorExit|([\p{Alpha}_][\p{Alnum}_]*)?Exception)\b
489+
match: |
490+
(?x) \b(
491+
(
492+
Arithmetic | Assertion | Attribute | Buffer | BlockingIO |
493+
BrokenPipe | ChildProcess |
494+
(Connection (Aborted | Refused | Reset)?) |
495+
EOF | Environment | FileExists | FileNotFound |
496+
FloatingPoint | IO | Import | Indentation | Index | Interrupted |
497+
IsADirectory | NotADirectory | Permission | ProcessLookup |
498+
Timeout |
499+
Key | Lookup | Memory | Name | NotImplemented | OS | Overflow |
500+
Reference | Runtime | Recursion | Standard | Syntax | System |
501+
Tab | Type | UnboundLocal | Unicode(Encode|Decode|Translate)? |
502+
Value | VMS | Windows | ZeroDivision
503+
)? Error
504+
|
505+
((Pending)?Deprecation | Runtime | Syntax | User | Future | Import |
506+
Unicode | Bytes | Resource
507+
)? Warning
508+
|
509+
SystemExit | Stop(Async)?Iteration | NotImplemented |
510+
KeyboardInterrupt |
511+
GeneratorExit | Exception
512+
)\b
478513
479514
builtin_functions:
480515
patterns:
@@ -629,7 +664,7 @@ repository:
629664

630665
illegal_names:
631666
name: invalid.illegal.name.python
632-
match: \b(and|as|assert|async|await|break|class|continue|def|del|elif|else|except|exec|finally|for|from|global|if|import|in|is|lambda|nonlocal|not|or|pass|print|raise|return|try|while|with|yield)\b
667+
match: \b(and|as|assert|await|break|class|continue|def|del|elif|else|except|exec|finally|for|from|global|if|import|in|is|lambda|nonlocal|not|or|pass|print|raise|return|try|while|with|yield)\b
633668

634669
keyword_arguments:
635670
begin: \b([\p{Alpha}_][\p{Alnum}_]*)\s*(=)(?!=)
@@ -1036,6 +1071,6 @@ repository:
10361071
author: Matt Morrison @MattDMo [email protected]
10371072
bundleUUID: 0F24FCF1-6543-4CC6-8B33-2EAED401FE3A
10381073
firstLineMatch: ^#!/.*\bpython[0-9.-]*\b
1039-
foldingStartMarker: ^\s*(def|class)\s+([.\p{Alnum}_ <]+)\s*(\((.*)\))?\s*:|\{\s*$|\(\s*$|\[\s*$|^\s*"""(?=.)(?!.*""")
1074+
foldingStartMarker: ^\s*(((?:async\s+)?def)|class)\s+([.\p{Alnum}_ <]+)\s*(\((.*)\))?\s*:|\{\s*$|\(\s*$|\[\s*$|^\s*"""(?=.)(?!.*""")
10401075
foldingStopMarker: ^\s*$|^\s*\}|^\s*\]|^\s*\)|^\s*"""\s*$
10411076
keyEquivalent: ^~P

PythonImproved-Unicode.tmLanguage

Lines changed: 67 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<key>firstLineMatch</key>
2424
<string>^#!/.*\bpython[0-9.-]*\b</string>
2525
<key>foldingStartMarker</key>
26-
<string>^\s*(def|class)\s+([.\p{Alnum}_ &lt;]+)\s*(\((.*)\))?\s*:|\{\s*$|\(\s*$|\[\s*$|^\s*"""(?=.)(?!.*""")</string>
26+
<string>^\s*(((?:async\s+)?def)|class)\s+([.\p{Alnum}_ &lt;]+)\s*(\((.*)\))?\s*:|\{\s*$|\(\s*$|\[\s*$|^\s*"""(?=.)(?!.*""")</string>
2727
<key>foldingStopMarker</key>
2828
<string>^\s*$|^\s*\}|^\s*\]|^\s*\)|^\s*"""\s*$</string>
2929
<key>keyEquivalent</key>
@@ -189,7 +189,7 @@
189189
</dict>
190190
<dict>
191191
<key>match</key>
192-
<string>\b(global|nonlocal|async)\b</string>
192+
<string>\b(global|nonlocal)\b</string>
193193
<key>name</key>
194194
<string>storage.modifier.declaration.python</string>
195195
</dict>
@@ -199,14 +199,6 @@
199199
<key>name</key>
200200
<string>keyword.control.import.python</string>
201201
</dict>
202-
<dict>
203-
<key>comment</key>
204-
<string>keywords that delimit flow blocks or alter flow from within a block</string>
205-
<key>match</key>
206-
<string>\b(elif|else|except|finally|for|if|try|while|with|break|continue|pass|raise|return|yield|await)\b</string>
207-
<key>name</key>
208-
<string>keyword.control.flow.python</string>
209-
</dict>
210202
<dict>
211203
<key>comment</key>
212204
<string>keyword operators that evaluate to True or False</string>
@@ -229,6 +221,12 @@
229221
<key>name</key>
230222
<string>invalid.deprecated.operator.python</string>
231223
</dict>
224+
<dict>
225+
<key>match</key>
226+
<string>(?&lt;!\.)(apply|buffer|coerce|intern)\s*(?=\()</string>
227+
<key>name</key>
228+
<string>invalid.deprecated.function.python</string>
229+
</dict>
232230
<dict>
233231
<key>match</key>
234232
<string>&lt;\=|&gt;\=|\=\=|&lt;|&gt;|\!\=</string>
@@ -429,7 +427,7 @@
429427
</dict>
430428
<dict>
431429
<key>begin</key>
432-
<string>\s*(def)\s+(?=[\p{Alpha}_][\p{Alnum}_]*\s*\()</string>
430+
<string>\s*((?:async\s+)?def)\s+(?=[\p{Alpha}_][\p{Alnum}_]*\s*\()</string>
433431
<key>beginCaptures</key>
434432
<dict>
435433
<key>1</key>
@@ -550,7 +548,7 @@
550548
</dict>
551549
<dict>
552550
<key>begin</key>
553-
<string>\s*(def)\s+(?=[\p{Alpha}_][\p{Alnum}_]*)</string>
551+
<string>\s*((?:async\s+)?def)\s+(?=[\p{Alpha}_][\p{Alnum}_]*)</string>
554552
<key>beginCaptures</key>
555553
<dict>
556554
<key>1</key>
@@ -595,6 +593,36 @@
595593
</dict>
596594
</array>
597595
</dict>
596+
<dict>
597+
<key>captures</key>
598+
<dict>
599+
<key>1</key>
600+
<dict>
601+
<key>name</key>
602+
<string>storage.type.function.python</string>
603+
</dict>
604+
</dict>
605+
<key>match</key>
606+
<string>\b(((?:async\s+)?def)|lambda)\b</string>
607+
</dict>
608+
<dict>
609+
<key>comment</key>
610+
<string>Keywords that delimit flow blocks or alter flow from within a
611+
block.
612+
613+
This block should be matched *after* meta.function.python to
614+
let 'async def' be matched *first*.
615+
</string>
616+
<key>match</key>
617+
<string>(?x) \b(
618+
async | await | break | continue | elif | else | except | finally | for |
619+
if | pass | raise | return | try | while | with |
620+
(yield(?:\s+from)?)
621+
)\b
622+
</string>
623+
<key>name</key>
624+
<string>keyword.control.flow.python</string>
625+
</dict>
598626
<dict>
599627
<key>begin</key>
600628
<string>(lambda)(?=\s+|:)</string>
@@ -993,18 +1021,6 @@
9931021
</dict>
9941022
</array>
9951023
</dict>
996-
<dict>
997-
<key>captures</key>
998-
<dict>
999-
<key>1</key>
1000-
<dict>
1001-
<key>name</key>
1002-
<string>storage.type.function.python</string>
1003-
</dict>
1004-
</dict>
1005-
<key>match</key>
1006-
<string>\b(def|lambda)\b</string>
1007-
</dict>
10081024
<dict>
10091025
<key>captures</key>
10101026
<dict>
@@ -1380,7 +1396,30 @@
13801396
<key>builtin_exceptions</key>
13811397
<dict>
13821398
<key>match</key>
1383-
<string>\b((Arithmetic|Assertion|Attribute|Buffer|EOF|Environment|FloatingPoint|IO|Import|Indentation|Index|Key|Lookup|Memory|Name|NotImplemented|OS|Overflow|Reference|Runtime|Standard|Syntax|System|Tab|Type|UnboundLocal|Unicode(Encode|Decode|Translate)?|Value|VMS|Windows|ZeroDivision|([\p{Alpha}_][\p{Alnum}_]*))?Error|((Pending)?Deprecation|Runtime|Syntax|User|Future|Import|Unicode|Bytes)?Warning|SystemExit|StopIteration|NotImplemented|KeyboardInterrupt|GeneratorExit|([\p{Alpha}_][\p{Alnum}_]*)?Exception)\b</string>
1399+
<string>(?x) \b(
1400+
(
1401+
Arithmetic | Assertion | Attribute | Buffer | BlockingIO |
1402+
BrokenPipe | ChildProcess |
1403+
(Connection (Aborted | Refused | Reset)?) |
1404+
EOF | Environment | FileExists | FileNotFound |
1405+
FloatingPoint | IO | Import | Indentation | Index | Interrupted |
1406+
IsADirectory | NotADirectory | Permission | ProcessLookup |
1407+
Timeout |
1408+
Key | Lookup | Memory | Name | NotImplemented | OS | Overflow |
1409+
Reference | Runtime | Recursion | Standard | Syntax | System |
1410+
Tab | Type | UnboundLocal | Unicode(Encode|Decode|Translate)? |
1411+
Value | VMS | Windows | ZeroDivision
1412+
)? Error
1413+
|
1414+
((Pending)?Deprecation | Runtime | Syntax | User | Future | Import |
1415+
Unicode | Bytes | Resource
1416+
)? Warning
1417+
|
1418+
SystemExit | Stop(Async)?Iteration | NotImplemented |
1419+
KeyboardInterrupt |
1420+
GeneratorExit | Exception
1421+
)\b
1422+
</string>
13841423
<key>name</key>
13851424
<string>support.type.exception.python</string>
13861425
</dict>
@@ -1390,7 +1429,7 @@
13901429
<array>
13911430
<dict>
13921431
<key>begin</key>
1393-
<string>(?&lt;!\.)(__import__|ascii|abs|all|any|apply|bin|bool|buffer|bytearray|bytes|callable|chr|classmethod|cmp|coerce|compile|complex|copyright|credits|delattr|dict|dir|divmod|enumerate|eval|exec|execfile|exit|file|filter|float|format|frozenset|getattr|globals|hasattr|hash|help|hex|id|input|int|intern|isinstance|issubclass|iter|len|license|list|locals|long|map|max|memoryview|min|next|object|oct|open|ord|pow|print|property|quit|range|raw_input|reduce|reload|repr|reversed|round|set|setattr|slice|sorted|staticmethod|str|sum|super|tuple|type|unicode|unichr|vars|xrange|zip)\s*(?=\()</string>
1432+
<string>(?&lt;!\.)(__import__|abs|all|any|ascii|basestring|bin|bool|bytearray|bytes|callable|chr|classmethod|cmp|compile|complex|delattr|dict|dir|divmod|enumerate|eval|exec|execfile|file|filter|float|format|frozenset|getattr|globals|hasattr|hash|help|hex|id|input|int|isinstance|issubclass|iter|len|list|locals|long|map|max|memoryview|min|next|object|oct|open|ord|pow|print|property|range|raw_input|reduce|reload|repr|reversed|round|set|setattr|slice|sorted|staticmethod|str|sum|super|tuple|type|unichr|unicode|vars|xrange|zip)\s*(?=\()</string>
13941433
<key>beginCaptures</key>
13951434
<dict>
13961435
<key>1</key>
@@ -1866,7 +1905,7 @@
18661905
<key>illegal_names</key>
18671906
<dict>
18681907
<key>match</key>
1869-
<string>\b(and|as|assert|async|await|break|class|continue|def|del|elif|else|except|exec|finally|for|from|global|if|import|in|is|lambda|nonlocal|not|or|pass|print|raise|return|try|while|with|yield)\b</string>
1908+
<string>\b(and|as|assert|await|break|class|continue|def|del|elif|else|except|exec|finally|for|from|global|if|import|in|is|lambda|nonlocal|not|or|pass|print|raise|return|try|while|with|yield)\b</string>
18701909
<key>name</key>
18711910
<string>invalid.illegal.name.python</string>
18721911
</dict>
@@ -1938,7 +1977,7 @@
19381977
<key>comment</key>
19391978
<string>these methods have magic interpretation by python and are generally called indirectly through syntactic constructs</string>
19401979
<key>match</key>
1941-
<string>(\.)?\b(__(?:abs|add|and|bool|call|ceil|cmp|coerce|complex|contains|copy|deepcopy|del|delattr|delete|delitem|delslice|dir|div|divmod|enter|eq|exit|float|floor|floordiv|format|ge|get|getattr|getattribute|getinitargs|getitem|getnewargs|getslice|getstate|gt|hash|hex|iadd|iand|idiv|ifloordiv|ilshift|imod|imul|index|init|instancecheck|int|invert|ior|ipow|irshift|isub|iter|itruediv|ixor|le|len|long|lshift|lt|missing|mod|mul|ne|neg|new|nonzero|oct|or|pos|pow|radd|rand|rdiv|rdivmod|reduce|reduce_ex|repr|reversed|rfloordiv|rlshift|rmod|rmul|ror|round|rpow|rrshift|rshift|rsub|rtruediv|rxor|set|setattr|setitem|setslice|setstate|sizeof|str|sub|subclasscheck|truediv|trunc|unicode|xor)__)\b</string>
1980+
<string>(\.)?\b(__(?:abs|add|and|bool|call|ceil|cmp|complex|contains|copy|deepcopy|del|delattr|delete|delitem|delslice|dir|div|divmod|enter|eq|exit|float|floor|floordiv|format|ge|get|getattr|getattribute|getinitargs|getitem|getnewargs|getslice|getstate|gt|hash|hex|iadd|iand|idiv|ifloordiv|ilshift|imod|imul|index|init|instancecheck|int|invert|ior|ipow|irshift|isub|iter|itruediv|ixor|le|len|long|lshift|lt|missing|mod|mul|ne|neg|new|nonzero|oct|or|pos|pow|radd|rand|rdiv|rdivmod|reduce|reduce_ex|repr|reversed|rfloordiv|rlshift|rmod|rmul|ror|round|rpow|rrshift|rshift|rsub|rtruediv|rxor|set|setattr|setitem|setslice|setstate|sizeof|str|sub|subclasscheck|truediv|trunc|unicode|xor)__)\b</string>
19421981
</dict>
19431982
<key>magic_variable_names</key>
19441983
<dict>

0 commit comments

Comments
 (0)