Skip to content

Commit aac3dae

Browse files
author
Matt Morrison
committed
Merge pull request #1 from facelessuser/master
Add python3 function annotation support
2 parents 2e6793a + 2de9344 commit aac3dae

File tree

2 files changed

+166
-14
lines changed

2 files changed

+166
-14
lines changed

PythonImproved.tmLanguage

Lines changed: 165 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
33
<plist version="1.0">
44
<dict>
55
<key>bundleUUID</key>
@@ -16,7 +16,7 @@
1616
To make this your main Python language definition (in Sublime Text):
1717
1) Rename Packages/Python/Python.tmLanguage to something else with a different extension (like Python.tmLanguage.backup)
1818
2) Move this file and its README.md to Packages/Python/
19-
3) Search for "<string>PythonImproved</string>" and change it to just say Python (if you want) - this is what is displayed in ST2's various menus
19+
3) Search for "&lt;string&gt;PythonImproved&lt;/string&gt;" and change it to just say Python (if you want) - this is what is displayed in ST2's various menus
2020
4) Rename this file to Python.tmLanguage (if you want)
2121
Or (probably a better way):
2222
1) Open a .py file.
@@ -428,24 +428,14 @@
428428
</dict>
429429
</dict>
430430
<key>end</key>
431-
<string>(\))\s*(?:(\:)|(.*$\n?))</string>
431+
<string>(\:)</string>
432432
<key>endCaptures</key>
433433
<dict>
434434
<key>1</key>
435-
<dict>
436-
<key>name</key>
437-
<string>punctuation.definition.parameters.end.python</string>
438-
</dict>
439-
<key>2</key>
440435
<dict>
441436
<key>name</key>
442437
<string>punctuation.section.function.begin.python</string>
443438
</dict>
444-
<key>3</key>
445-
<dict>
446-
<key>name</key>
447-
<string>invalid.illegal.missing-section-begin.python</string>
448-
</dict>
449439
</dict>
450440
<key>name</key>
451441
<string>meta.function.python</string>
@@ -480,9 +470,13 @@
480470
<key>contentName</key>
481471
<string>meta.function.parameters.python</string>
482472
<key>end</key>
483-
<string>(?=\)\s*\:)</string>
473+
<string>(?=\)\s*(?:\:|-\&gt;))</string>
484474
<key>patterns</key>
485475
<array>
476+
<dict>
477+
<key>include</key>
478+
<string>#annotated_arguments</string>
479+
</dict>
486480
<dict>
487481
<key>include</key>
488482
<string>#keyword_arguments</string>
@@ -510,6 +504,32 @@
510504
</dict>
511505
</array>
512506
</dict>
507+
<dict>
508+
<key>begin</key>
509+
<string>(\))\s*(\-&gt;)</string>
510+
<key>beginCaptures</key>
511+
<dict>
512+
<key>1</key>
513+
<dict>
514+
<key>name</key>
515+
<string>punctuation.definition.parameters.end.python</string>
516+
</dict>
517+
<key>2</key>
518+
<dict>
519+
<key>name</key>
520+
<string>punctuation.separator.annotation.result.python</string>
521+
</dict>
522+
</dict>
523+
<key>end</key>
524+
<string>(?=\:)</string>
525+
<key>patterns</key>
526+
<array>
527+
<dict>
528+
<key>include</key>
529+
<string>$self</string>
530+
</dict>
531+
</array>
532+
</dict>
513533
</array>
514534
</dict>
515535
<dict>
@@ -1204,6 +1224,137 @@
12041224
</array>
12051225
<key>repository</key>
12061226
<dict>
1227+
<key>annotated_arguments</key>
1228+
<dict>
1229+
<key>begin</key>
1230+
<string>\b([a-zA-Z_][a-zA-Z_0-9]*)\s*(:)|(?=\()</string>
1231+
<key>beginCaptures</key>
1232+
<dict>
1233+
<key>1</key>
1234+
<dict>
1235+
<key>name</key>
1236+
<string>variable.parameter.function.python</string>
1237+
</dict>
1238+
<key>2</key>
1239+
<dict>
1240+
<key>name</key>
1241+
<string>punctuation.separator.annotation.python</string>
1242+
</dict>
1243+
</dict>
1244+
<key>end</key>
1245+
<string>\s*(?:(,)|(?=$\n?|[\)\:]))</string>
1246+
<key>endCaptures</key>
1247+
<dict>
1248+
<key>1</key>
1249+
<dict>
1250+
<key>name</key>
1251+
<string>punctuation.separator.parameters.python</string>
1252+
</dict>
1253+
</dict>
1254+
<key>patterns</key>
1255+
<array>
1256+
<dict>
1257+
<key>include</key>
1258+
<string>#annotated_group</string>
1259+
</dict>
1260+
<dict>
1261+
<key>match</key>
1262+
<string>=</string>
1263+
<key>name</key>
1264+
<string>keyword.operator.assignment.python</string>
1265+
</dict>
1266+
<dict>
1267+
<key>include</key>
1268+
<string>$self</string>
1269+
</dict>
1270+
</array>
1271+
</dict>
1272+
<key>annotated_group</key>
1273+
<dict>
1274+
<key>begin</key>
1275+
<string>(\()</string>
1276+
<key>beginCaptures</key>
1277+
<dict>
1278+
<key>1</key>
1279+
<dict>
1280+
<key>name</key>
1281+
<string>punctuation.definition.parameters-group.begin.python</string>
1282+
</dict>
1283+
</dict>
1284+
<key>end</key>
1285+
<string>(\))</string>
1286+
<key>endCaptures</key>
1287+
<dict>
1288+
<key>1</key>
1289+
<dict>
1290+
<key>name</key>
1291+
<string>punctuation.definition.parameters-group.end.python</string>
1292+
</dict>
1293+
</dict>
1294+
<key>patterns</key>
1295+
<array>
1296+
<dict>
1297+
<key>begin</key>
1298+
<string>\b([a-zA-Z_][a-zA-Z_0-9]*)\s*(:)</string>
1299+
<key>beginCaptures</key>
1300+
<dict>
1301+
<key>1</key>
1302+
<dict>
1303+
<key>name</key>
1304+
<string>variable.parameter.function.python</string>
1305+
</dict>
1306+
<key>2</key>
1307+
<dict>
1308+
<key>name</key>
1309+
<string>punctuation.separator.annotation.python</string>
1310+
</dict>
1311+
</dict>
1312+
<key>end</key>
1313+
<string>\s*(?:(,)|(?=$\n?|\)))</string>
1314+
<key>endCaptures</key>
1315+
<dict>
1316+
<key>1</key>
1317+
<dict>
1318+
<key>name</key>
1319+
<string>punctuation.separator.parameters.python</string>
1320+
</dict>
1321+
</dict>
1322+
<key>patterns</key>
1323+
<array>
1324+
<dict>
1325+
<key>include</key>
1326+
<string>$self</string>
1327+
</dict>
1328+
</array>
1329+
</dict>
1330+
<dict>
1331+
<key>begin</key>
1332+
<string>\b([a-zA-Z_][a-zA-Z_0-9]*)</string>
1333+
<key>beginCaptures</key>
1334+
<dict>
1335+
<key>1</key>
1336+
<dict>
1337+
<key>name</key>
1338+
<string>variable.parameter.function.python</string>
1339+
</dict>
1340+
</dict>
1341+
<key>end</key>
1342+
<string>\s*(?:(,)|(?=$\n?|\)))</string>
1343+
<key>endCaptures</key>
1344+
<dict>
1345+
<key>1</key>
1346+
<dict>
1347+
<key>name</key>
1348+
<string>punctuation.separator.parameters.python</string>
1349+
</dict>
1350+
</dict>
1351+
</dict>
1352+
<dict>
1353+
<key>include</key>
1354+
<string>#comments</string>
1355+
</dict>
1356+
</array>
1357+
</dict>
12071358
<key>builtin_exceptions</key>
12081359
<dict>
12091360
<key>match</key>

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ If you prefer to modify your own color scheme, here is a list of new/modified sc
2929
- `keyword.other.python` now only contains `assert` &mdash; `as`, `del`, `exec`, and `print` have been relocated
3030
- `support.type.exception.python` now matches any identifier that ends with `Exception` or `Error`, not just the built-in ones like `IndentationError` or `RuntimeException`, allowing for the highlighting of custom exceptions such as those included in third-party modules
3131
- Miscellaneous changes to `support.function.builtin.python` and `support.type.python` &mdash; a lot of personal judgement went in to deciding which word went where (for example, `list` is a built-in function, but it's also a type, so I put it in `type`), so if you have a good reason for disagreeing please tell me.
32+
- function annotation support for python3. New scopes added: `punctuation.separator.annotation.python`, `punctuation.separator.annotation.result.python`, `punctuation.definition.parameters-group.begin.python`., and `punctuation.definition.parameters-group.end.python`.
3233
- You can now have comments in multi-line function definitions:
3334

3435
```python

0 commit comments

Comments
 (0)