Skip to content

Commit 2097171

Browse files
author
MattDMo
committed
changes to constants, raw/regex strings, magic functions
* can now differentiate between raw-regex strings (r"...") and raw strings (R"..."). raw-regex will include regex syntax highlighting, raw-only will not. Addresses #25 * fixed `constant.other.allcaps` to not highlight capital letters just before `.`, `(`, `'`, or `"`. * magic function definitions are now properly highlighted again. Fixes #51 (small problem - both names and calls are scoped as name...)
1 parent d6d8e22 commit 2097171

File tree

4 files changed

+757
-274
lines changed

4 files changed

+757
-274
lines changed

PythonImproved.YAML-tmLanguage

Lines changed: 168 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ uuid: 11B0273F-0284-4483-B17B-4B8D0A9294CC
88

99
patterns:
1010
- name: support.type.ellipsis.python
11-
match: (\.{3})
11+
match: (?<!^from\s|^import\s)(\.{3})
1212

1313
- name: support.ipython.in.python
1414
match: (^In \[(\d+)\]\:)
@@ -22,10 +22,9 @@ patterns:
2222

2323
- include: '#comments'
2424

25-
- comment: Match identifiers in ALL_CAPS as constants, except when followed by . or
26-
(.
25+
- comment: Match identifiers in ALL_CAPS as constants, except when followed by `.`, `(`, `'`, or `"`.
2726
name: constant.other.allcaps.python
28-
match: \b([\p{Upper}_][\p{Upper}\p{Digit}_]*)\b(?![\.\(])
27+
match: \b([\p{Upper}_][\p{Upper}\p{Digit}_]*)\b(?![\.\(\'\"])
2928

3029
- name: constant.numeric.integer.long.hexadecimal.python
3130
match: \b(?i:(0x\h+)L)
@@ -779,8 +778,8 @@ repository:
779778
See also http://www.rafekettler.com/magicmethods.html'
780779
match: |-
781780
(?x)
782-
(\.)?
783-
\b (
781+
(def|\.)?
782+
\s*\b(
784783
__(?:
785784
abs | add | aenter | aexit | aiter | and | anext | await | bool |
786785
bytes | call | ceil | cmp | coerce | complex | contains | copy |
@@ -799,7 +798,7 @@ repository:
799798
setstate | sizeof | str | sub | subclasscheck | truediv | trunc |
800799
unicode | xor)
801800
__)
802-
\b\s*(?!(\(.*:\n(\s*\#.*)?$))
801+
\b
803802
captures:
804803
'2': {name: support.function.magic.name.python}
805804

@@ -951,9 +950,8 @@ repository:
951950

952951
string_quoted_double:
953952
patterns:
954-
- comment: single quoted unicode-raw string
955-
name: string.quoted.double.block.unicode-raw-regex.python
956-
begin: ([uU][rR])(""")
953+
- name: string.quoted.double.block.unicode-raw-regex.python
954+
begin: ([uU]r)(""")
957955
beginCaptures:
958956
'1': {name: storage.type.string.python}
959957
'2': {name: punctuation.definition.string.begin.python}
@@ -963,12 +961,20 @@ repository:
963961
'2': {name: meta.empty-string.double.python}
964962
patterns:
965963
- include: '#constant_placeholder'
966-
- include: '#escaped_unicode_char'
967-
- include: '#escaped_char'
968964
- include: '#regular_expressions'
969-
- comment: single quoted bytes-raw string
970-
name: string.quoted.double.block.bytes-raw-regex.python
971-
begin: ([bB][rR])(""")
965+
- name: string.quoted.double.block.unicode-raw.python
966+
begin: ([uU]R)(""")
967+
beginCaptures:
968+
'1': {name: storage.type.string.python}
969+
'2': {name: punctuation.definition.string.begin.python}
970+
end: ((?<=""")(")""|""")
971+
endCaptures:
972+
'1': {name: punctuation.definition.string.end.python}
973+
'2': {name: meta.empty-string.double.python}
974+
patterns:
975+
- include: '#constant_placeholder'
976+
- name: string.quoted.double.block.bytes-raw-regex.python
977+
begin: ([bB]r)(""")
972978
beginCaptures:
973979
'1': {name: storage.type.string.python}
974980
'2': {name: punctuation.definition.string.begin.python}
@@ -978,12 +984,20 @@ repository:
978984
'2': {name: meta.empty-string.double.python}
979985
patterns:
980986
- include: '#constant_placeholder'
981-
- include: '#escaped_char'
982-
- include: '#escaped_unicode_char'
983987
- include: '#regular_expressions'
984-
- comment: double quoted raw string
985-
name: string.quoted.double.block.raw-regex.python
986-
begin: ([rR])(""")
988+
- name: string.quoted.double.block.bytes-raw.python
989+
begin: ([bB]R)(""")
990+
beginCaptures:
991+
'1': {name: storage.type.string.python}
992+
'2': {name: punctuation.definition.string.begin.python}
993+
end: ((?<=""")(")""|""")
994+
endCaptures:
995+
'1': {name: punctuation.definition.string.end.python}
996+
'2': {name: meta.empty-string.double.python}
997+
patterns:
998+
- include: '#constant_placeholder'
999+
- name: string.quoted.double.block.raw-regex.python
1000+
begin: (r)(""")
9871001
beginCaptures:
9881002
'1': {name: storage.type.string.python}
9891003
'2': {name: punctuation.definition.string.begin.python}
@@ -993,9 +1007,18 @@ repository:
9931007
'2': {name: meta.empty-string.double.python}
9941008
patterns:
9951009
- include: '#constant_placeholder'
996-
- include: '#escaped_char'
997-
- include: '#escaped_unicode_char'
9981010
- include: '#regular_expressions'
1011+
- name: string.quoted.double.block.raw.python
1012+
begin: (R)(""")
1013+
beginCaptures:
1014+
'1': {name: storage.type.string.python}
1015+
'2': {name: punctuation.definition.string.begin.python}
1016+
end: ((?<=""")(")""|""")
1017+
endCaptures:
1018+
'1': {name: punctuation.definition.string.end.python}
1019+
'2': {name: meta.empty-string.double.python}
1020+
patterns:
1021+
- include: '#constant_placeholder'
9991022
- comment: double quoted unicode string
10001023
name: string.quoted.double.block.unicode.python
10011024
begin: ([uU])(""")
@@ -1022,10 +1045,10 @@ repository:
10221045
'2': {name: meta.empty-string.double.python}
10231046
patterns:
10241047
- include: '#constant_placeholder'
1048+
- include: '#escaped_unicode_char'
10251049
- include: '#escaped_char'
1026-
- comment: double-quoted raw string
1027-
name: string.quoted.double.single-line.unicode-raw-regex.python
1028-
begin: ([uU][rR])(")
1050+
- name: string.quoted.double.single-line.unicode-raw-regex.python
1051+
begin: ([uU]r)(")
10291052
beginCaptures:
10301053
'1': {name: storage.type.string.python}
10311054
'2': {name: punctuation.definition.string.begin.python}
@@ -1036,12 +1059,21 @@ repository:
10361059
'3': {name: invalid.illegal.unclosed-string.python}
10371060
patterns:
10381061
- include: '#constant_placeholder'
1039-
- include: '#escaped_unicode_char'
1040-
- include: '#escaped_char'
10411062
- include: '#regular_expressions'
1042-
- comment: double-quoted raw string
1043-
name: string.quoted.double.single-line.bytes-raw-regex.python
1044-
begin: ([bB][rR])(")
1063+
- name: string.quoted.double.single-line.unicode-raw.python
1064+
begin: ([uU]R)(")
1065+
beginCaptures:
1066+
'1': {name: storage.type.string.python}
1067+
'2': {name: punctuation.definition.string.begin.python}
1068+
end: ((?<=")(")|")|(\n)
1069+
endCaptures:
1070+
'1': {name: punctuation.definition.string.end.python}
1071+
'2': {name: meta.empty-string.double.python}
1072+
'3': {name: invalid.illegal.unclosed-string.python}
1073+
patterns:
1074+
- include: '#constant_placeholder'
1075+
- name: string.quoted.double.single-line.bytes-raw-regex.python
1076+
begin: ([bB]r)(")
10451077
beginCaptures:
10461078
'1': {name: storage.type.string.python}
10471079
'2': {name: punctuation.definition.string.begin.python}
@@ -1052,12 +1084,21 @@ repository:
10521084
'3': {name: invalid.illegal.unclosed-string.python}
10531085
patterns:
10541086
- include: '#constant_placeholder'
1055-
- include: '#escaped_char'
1056-
- include: '#escaped_unicode_char'
10571087
- include: '#regular_expressions'
1058-
- comment: double-quoted raw string
1059-
name: string.quoted.double.single-line.raw-regex.python
1060-
begin: ([rR])(")
1088+
- name: string.quoted.double.single-line.bytes-raw.python
1089+
begin: ([bB]R)(")
1090+
beginCaptures:
1091+
'1': {name: storage.type.string.python}
1092+
'2': {name: punctuation.definition.string.begin.python}
1093+
end: ((?<=")(")|")|(\n)
1094+
endCaptures:
1095+
'1': {name: punctuation.definition.string.end.python}
1096+
'2': {name: meta.empty-string.double.python}
1097+
'3': {name: invalid.illegal.unclosed-string.python}
1098+
patterns:
1099+
- include: '#constant_placeholder'
1100+
- name: string.quoted.double.single-line.raw-regex.python
1101+
begin: (r)(")
10611102
beginCaptures:
10621103
'1': {name: storage.type.string.python}
10631104
'2': {name: punctuation.definition.string.begin.python}
@@ -1068,9 +1109,19 @@ repository:
10681109
'3': {name: invalid.illegal.unclosed-string.python}
10691110
patterns:
10701111
- include: '#constant_placeholder'
1071-
- include: '#escaped_char'
1072-
- include: '#escaped_unicode_char'
10731112
- include: '#regular_expressions'
1113+
- name: string.quoted.double.single-line.raw.python
1114+
begin: (R)(")
1115+
beginCaptures:
1116+
'1': {name: storage.type.string.python}
1117+
'2': {name: punctuation.definition.string.begin.python}
1118+
end: ((?<=")(")|")|(\n)
1119+
endCaptures:
1120+
'1': {name: punctuation.definition.string.end.python}
1121+
'2': {name: meta.empty-string.double.python}
1122+
'3': {name: invalid.illegal.unclosed-string.python}
1123+
patterns:
1124+
- include: '#constant_placeholder'
10741125
- comment: double quoted unicode string
10751126
name: string.quoted.double.single-line.unicode.python
10761127
begin: ([uU])(")
@@ -1099,8 +1150,8 @@ repository:
10991150
'3': {name: invalid.illegal.unclosed-string.python}
11001151
patterns:
11011152
- include: '#constant_placeholder'
1102-
- include: '#escaped_char'
11031153
- include: '#escaped_unicode_char'
1154+
- include: '#escaped_char'
11041155
- comment: double quoted string
11051156
name: string.quoted.double.block.python
11061157
begin: (""")
@@ -1137,9 +1188,8 @@ repository:
11371188
'1': {name: punctuation.definition.string.begin.python}
11381189
'2': {name: punctuation.definition.string.end.python}
11391190
'3': {name: meta.empty-string.single.python}
1140-
- comment: single quoted unicode-raw string
1141-
name: string.quoted.single.block.unicode-raw-regex.python
1142-
begin: ([uU][rR])(''')
1191+
- name: string.quoted.single.block.unicode-raw-regex.python
1192+
begin: ([uU]r)(''')
11431193
beginCaptures:
11441194
'1': {name: storage.type.string.python}
11451195
'2': {name: punctuation.definition.string.begin.python}
@@ -1149,12 +1199,20 @@ repository:
11491199
'2': {name: meta.empty-string.single.python}
11501200
patterns:
11511201
- include: '#constant_placeholder'
1152-
- include: '#escaped_unicode_char'
1153-
- include: '#escaped_char'
11541202
- include: '#regular_expressions'
1155-
- comment: single quoted bytes-raw string
1156-
name: string.quoted.single.block.bytes-raw-regex.python
1157-
begin: ([bB][rR])(''')
1203+
- name: string.quoted.single.block.unicode-raw.python
1204+
begin: ([uU]R)(''')
1205+
beginCaptures:
1206+
'1': {name: storage.type.string.python}
1207+
'2': {name: punctuation.definition.string.begin.python}
1208+
end: ((?<=''')(')''|''')
1209+
endCaptures:
1210+
'1': {name: punctuation.definition.string.end.python}
1211+
'2': {name: meta.empty-string.single.python}
1212+
patterns:
1213+
- include: '#constant_placeholder'
1214+
- name: string.quoted.single.block.bytes-raw-regex.python
1215+
begin: ([bB]r)(''')
11581216
beginCaptures:
11591217
'1': {name: storage.type.string.python}
11601218
'2': {name: punctuation.definition.string.begin.python}
@@ -1164,12 +1222,20 @@ repository:
11641222
'2': {name: meta.empty-string.single.python}
11651223
patterns:
11661224
- include: '#constant_placeholder'
1167-
- include: '#escaped_char'
1168-
- include: '#escaped_unicode_char'
11691225
- include: '#regular_expressions'
1170-
- comment: single quoted raw string
1171-
name: string.quoted.single.block.raw-regex.python
1172-
begin: ([rR])(''')
1226+
- name: string.quoted.single.block.bytes-raw.python
1227+
begin: ([bB]R)(''')
1228+
beginCaptures:
1229+
'1': {name: storage.type.string.python}
1230+
'2': {name: punctuation.definition.string.begin.python}
1231+
end: ((?<=''')(')''|''')
1232+
endCaptures:
1233+
'1': {name: punctuation.definition.string.end.python}
1234+
'2': {name: meta.empty-string.single.python}
1235+
patterns:
1236+
- include: '#constant_placeholder'
1237+
- name: string.quoted.single.block.raw-regex.python
1238+
begin: (r)(''')
11731239
beginCaptures:
11741240
'1': {name: storage.type.string.python}
11751241
'2': {name: punctuation.definition.string.begin.python}
@@ -1179,11 +1245,19 @@ repository:
11791245
'2': {name: meta.empty-string.single.python}
11801246
patterns:
11811247
- include: '#constant_placeholder'
1182-
- include: '#escaped_char'
1183-
- include: '#escaped_unicode_char'
11841248
- include: '#regular_expressions'
1185-
- comment: single quoted unicode string
1186-
name: string.quoted.single.block.unicode.python
1249+
- name: string.quoted.single.block.raw.python
1250+
begin: (R)(''')
1251+
beginCaptures:
1252+
'1': {name: storage.type.string.python}
1253+
'2': {name: punctuation.definition.string.begin.python}
1254+
end: ((?<=''')(')''|''')
1255+
endCaptures:
1256+
'1': {name: punctuation.definition.string.end.python}
1257+
'2': {name: meta.empty-string.single.python}
1258+
patterns:
1259+
- include: '#constant_placeholder'
1260+
- name: string.quoted.single.block.unicode.python
11871261
begin: ([uU])(''')
11881262
beginCaptures:
11891263
'1': {name: storage.type.string.python}
@@ -1210,9 +1284,8 @@ repository:
12101284
- include: '#constant_placeholder'
12111285
- include: '#escaped_char'
12121286
- include: '#escaped_unicode_char'
1213-
- comment: single quoted unicode-raw string
1214-
name: string.quoted.single.single-line.unicode-raw-regex.python
1215-
begin: ([uU][rR])(')
1287+
- name: string.quoted.single.single-line.unicode-raw-regex.python
1288+
begin: ([uU]r)(')
12161289
beginCaptures:
12171290
'1': {name: storage.type.string.python}
12181291
'2': {name: punctuation.definition.string.begin.python}
@@ -1222,12 +1295,20 @@ repository:
12221295
'2': {name: invalid.illegal.unclosed-string.python}
12231296
patterns:
12241297
- include: '#constant_placeholder'
1225-
- include: '#escaped_unicode_char'
1226-
- include: '#escaped_char'
12271298
- include: '#regular_expressions'
1228-
- comment: single quoted bytes-raw string
1229-
name: string.quoted.single.single-line.bytes-raw-regex.python
1230-
begin: ([bB][rR])(')
1299+
- name: string.quoted.single.single-line.unicode-raw.python
1300+
begin: ([uU]R)(')
1301+
beginCaptures:
1302+
'1': {name: storage.type.string.python}
1303+
'2': {name: punctuation.definition.string.begin.python}
1304+
end: (')|(\n)
1305+
endCaptures:
1306+
'1': {name: punctuation.definition.string.end.python}
1307+
'2': {name: invalid.illegal.unclosed-string.python}
1308+
patterns:
1309+
- include: '#constant_placeholder'
1310+
- name: string.quoted.single.single-line.bytes-raw-regex.python
1311+
begin: ([bB]r)(')
12311312
beginCaptures:
12321313
'1': {name: storage.type.string.python}
12331314
'2': {name: punctuation.definition.string.begin.python}
@@ -1237,12 +1318,20 @@ repository:
12371318
'2': {name: invalid.illegal.unclosed-string.python}
12381319
patterns:
12391320
- include: '#constant_placeholder'
1240-
- include: '#escaped_char'
1241-
- include: '#escaped_unicode_char'
12421321
- include: '#regular_expressions'
1243-
- comment: single quoted raw string
1244-
name: string.quoted.single.single-line.raw-regex.python
1245-
begin: ([rR])(')
1322+
- name: string.quoted.single.single-line.bytes-raw.python
1323+
begin: ([bB]R)(')
1324+
beginCaptures:
1325+
'1': {name: storage.type.string.python}
1326+
'2': {name: punctuation.definition.string.begin.python}
1327+
end: (')|(\n)
1328+
endCaptures:
1329+
'1': {name: punctuation.definition.string.end.python}
1330+
'2': {name: invalid.illegal.unclosed-string.python}
1331+
patterns:
1332+
- include: '#constant_placeholder'
1333+
- name: string.quoted.single.single-line.raw-regex.python
1334+
begin: (r)(')
12461335
beginCaptures:
12471336
'1': {name: storage.type.string.python}
12481337
'2': {name: punctuation.definition.string.begin.python}
@@ -1252,9 +1341,18 @@ repository:
12521341
'2': {name: invalid.illegal.unclosed-string.python}
12531342
patterns:
12541343
- include: '#constant_placeholder'
1255-
- include: '#escaped_char'
1256-
- include: '#escaped_unicode_char'
12571344
- include: '#regular_expressions'
1345+
- name: string.quoted.single.single-line.raw.python
1346+
begin: (R)(')
1347+
beginCaptures:
1348+
'1': {name: storage.type.string.python}
1349+
'2': {name: punctuation.definition.string.begin.python}
1350+
end: (')|(\n)
1351+
endCaptures:
1352+
'1': {name: punctuation.definition.string.end.python}
1353+
'2': {name: invalid.illegal.unclosed-string.python}
1354+
patterns:
1355+
- include: '#constant_placeholder'
12581356
- comment: single quoted unicode string
12591357
name: string.quoted.single.single-line.unicode.python
12601358
begin: ([uU])(')

0 commit comments

Comments
 (0)