Skip to content

Commit fa2ed6d

Browse files
committed
Adjust scope names for regular expression strings.
String with 'r' prefix are considered to contain regilar expressions, while 'R' strings are pure raw strings.
1 parent 9b1ab9a commit fa2ed6d

File tree

10 files changed

+303
-177
lines changed

10 files changed

+303
-177
lines changed

grammars/MagicPython.YAML-tmLanguage

Lines changed: 60 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -232,65 +232,71 @@ repository:
232232
'2': {name: storage.type.number.python}
233233

234234
regexp:
235-
name: string.regexp.python
236235
patterns:
237236
- include: '#regexp-single-quoted-multi-line'
238237
- include: '#regexp-double-quoted-multi-line'
239238
- include: '#regexp-single-quoted-single-line'
240239
- include: '#regexp-double-quoted-single-line'
241240

242241
regexp-single-quoted-single-line:
243-
name: string.quoted.single.raw.python
244-
begin: (\bR)(\')
242+
name: string.regexp.quoted.single.python
243+
begin: \b(([uU]r)|([bB]r)|(r[bB]?))(\')
245244
end: (\')|(?<!\\)(\n)
246245
beginCaptures:
247-
'1': {name: storage.type.string.python}
248-
'2': {name: punctuation.definition.string.begin.python}
246+
'2': {name: invalid.deprecated.prefix.python}
247+
'3': {name: storage.type.string.python}
248+
'4': {name: storage.type.string.python}
249+
'5': {name: punctuation.definition.string.begin.python}
249250
endCaptures:
250251
'1': {name: punctuation.definition.string.end.python}
251252
'2': {name: invalid.illegal.newline.python}
252253
patterns:
253254
- include: 'source.regexp.python'
254255

255256
regexp-double-quoted-single-line:
256-
name: string.quoted.double.raw.python
257-
begin: (\bR)(\")
257+
name: string.regexp.quoted.double.python
258+
begin: \b(([uU]r)|([bB]r)|(r[bB]?))(\")
258259
end: (\")|(?<!\\)(\n)
259260
beginCaptures:
260-
'1': {name: storage.type.string.python}
261-
'2': {name: punctuation.definition.string.begin.python}
261+
'2': {name: invalid.deprecated.prefix.python}
262+
'3': {name: storage.type.string.python}
263+
'4': {name: storage.type.string.python}
264+
'5': {name: punctuation.definition.string.begin.python}
262265
endCaptures:
263266
'1': {name: punctuation.definition.string.end.python}
264267
'2': {name: invalid.illegal.newline.python}
265268
patterns:
266269
- include: 'source.regexp.python'
267270

268271
regexp-single-quoted-multi-line:
269-
name: string.quoted.triple.raw.python
270-
begin: (\bR)(\'\'\')
272+
name: string.regexp.quoted.triple.python
273+
begin: \b(([uU]r)|([bB]r)|(r[bB]?))(\'\'\')
271274
end: \'\'\'
272275
beginCaptures:
273-
'1': {name: storage.type.string.python}
274-
'2': {name: punctuation.definition.string.begin.python}
276+
'2': {name: invalid.deprecated.prefix.python}
277+
'3': {name: storage.type.string.python}
278+
'4': {name: storage.type.string.python}
279+
'5': {name: punctuation.definition.string.begin.python}
275280
endCaptures:
276281
'0': {name: punctuation.definition.string.end.python}
277282
patterns:
278283
- include: 'source.regexp.python'
279284

280285
regexp-double-quoted-multi-line:
281-
name: string.quoted.triple.raw.python
282-
begin: (\bR)(\"\"\")
286+
name: string.regexp.quoted.triple.python
287+
begin: \b(([uU]r)|([bB]r)|(r[bB]?))(\"\"\")
283288
end: \"\"\"
284289
beginCaptures:
285-
'1': {name: storage.type.string.python}
286-
'2': {name: punctuation.definition.string.begin.python}
290+
'2': {name: invalid.deprecated.prefix.python}
291+
'3': {name: storage.type.string.python}
292+
'4': {name: storage.type.string.python}
293+
'5': {name: punctuation.definition.string.begin.python}
287294
endCaptures:
288295
'0': {name: punctuation.definition.string.end.python}
289296
patterns:
290297
- include: 'source.regexp.python'
291298

292299
string:
293-
name: string.python
294300
patterns:
295301
- include: '#string-single-quoted-multi-line'
296302
- include: '#string-double-quoted-multi-line'
@@ -311,11 +317,12 @@ repository:
311317

312318
string-single-quoted-single-line:
313319
name: string.quoted.single.python
314-
begin: (\b[uU])?(\')
320+
begin: (\b[rR](?=[uU]))?([uU])?(\')
315321
end: (\')|(?<!\\)(\n)
316322
beginCaptures:
317-
'1': {name: storage.type.string.python}
318-
'2': {name: punctuation.definition.string.begin.python}
323+
'1': {name: invalid.illegal.prefix.python}
324+
'2': {name: storage.type.string.python}
325+
'3': {name: punctuation.definition.string.begin.python}
319326
endCaptures:
320327
'1': {name: punctuation.definition.string.end.python}
321328
'2': {name: invalid.illegal.newline.python}
@@ -324,11 +331,12 @@ repository:
324331

325332
string-double-quoted-single-line:
326333
name: string.quoted.double.python
327-
begin: (\b[uU])?(\")
334+
begin: (\b[rR](?=[uU]))?([uU])?(\")
328335
end: (\")|(?<!\\)(\n)
329336
beginCaptures:
330-
'1': {name: storage.type.string.python}
331-
'2': {name: punctuation.definition.string.begin.python}
337+
'1': {name: invalid.illegal.prefix.python}
338+
'2': {name: storage.type.string.python}
339+
'3': {name: punctuation.definition.string.begin.python}
332340
endCaptures:
333341
'1': {name: punctuation.definition.string.end.python}
334342
'2': {name: invalid.illegal.newline.python}
@@ -337,23 +345,25 @@ repository:
337345

338346
string-single-quoted-multi-line:
339347
name: string.quoted.triple.python
340-
begin: (\b[uU])?(\'\'\')
348+
begin: (\b[rR](?=[uU]))?([uU])?(\'\'\')
341349
end: \'\'\'
342350
beginCaptures:
343-
'1': {name: storage.type.string.python}
344-
'2': {name: punctuation.definition.string.begin.python}
351+
'1': {name: invalid.illegal.prefix.python}
352+
'2': {name: storage.type.string.python}
353+
'3': {name: punctuation.definition.string.begin.python}
345354
endCaptures:
346355
'0': {name: punctuation.definition.string.end.python}
347356
patterns:
348357
- include: '#string-unicode-guts'
349358

350359
string-double-quoted-multi-line:
351360
name: string.quoted.triple.python
352-
begin: (\b[uU])?(\"\"\")
361+
begin: (\b[rR](?=[uU]))?([uU])?(\"\"\")
353362
end: \"\"\"
354363
beginCaptures:
355-
'1': {name: storage.type.string.python}
356-
'2': {name: punctuation.definition.string.begin.python}
364+
'1': {name: invalid.illegal.prefix.python}
365+
'2': {name: storage.type.string.python}
366+
'3': {name: punctuation.definition.string.begin.python}
357367
endCaptures:
358368
'0': {name: punctuation.definition.string.end.python}
359369
patterns:
@@ -416,11 +426,12 @@ repository:
416426

417427
string-raw-single-quoted-single-line:
418428
name: string.quoted.single.raw.python
419-
begin: (\br)(\')
429+
begin: \b(([uU]R)|(R))(\')
420430
end: (\')|(?<!\\)(\n)
421431
beginCaptures:
422-
'1': {name: storage.type.string.python}
423-
'2': {name: punctuation.definition.string.begin.python}
432+
'2': {name: invalid.deprecated.prefix.python}
433+
'3': {name: storage.type.string.python}
434+
'4': {name: punctuation.definition.string.begin.python}
424435
endCaptures:
425436
'1': {name: punctuation.definition.string.end.python}
426437
'2': {name: invalid.illegal.newline.python}
@@ -429,11 +440,12 @@ repository:
429440

430441
string-raw-double-quoted-single-line:
431442
name: string.quoted.double.raw.python
432-
begin: (\br)(\")
443+
begin: \b(([uU]R)|(R))(\")
433444
end: (\")|(?<!\\)(\n)
434445
beginCaptures:
435-
'1': {name: storage.type.string.python}
436-
'2': {name: punctuation.definition.string.begin.python}
446+
'2': {name: invalid.deprecated.prefix.python}
447+
'3': {name: storage.type.string.python}
448+
'4': {name: punctuation.definition.string.begin.python}
437449
endCaptures:
438450
'1': {name: punctuation.definition.string.end.python}
439451
'2': {name: invalid.illegal.newline.python}
@@ -442,23 +454,25 @@ repository:
442454

443455
string-raw-single-quoted-multi-line:
444456
name: string.quoted.triple.raw.python
445-
begin: (\br)(\'\'\')
457+
begin: \b(([uU]R)|(R))(\'\'\')
446458
end: \'\'\'
447459
beginCaptures:
448-
'1': {name: storage.type.string.python}
449-
'2': {name: punctuation.definition.string.begin.python}
460+
'2': {name: invalid.deprecated.prefix.python}
461+
'3': {name: storage.type.string.python}
462+
'4': {name: punctuation.definition.string.begin.python}
450463
endCaptures:
451464
'0': {name: punctuation.definition.string.end.python}
452465
patterns:
453466
- include: '#string-raw-guts'
454467

455468
string-raw-double-quoted-multi-line:
456469
name: string.quoted.triple.raw.python
457-
begin: (\br)(\"\"\")
470+
begin: \b(([uU]R)|(R))(\"\"\")
458471
end: \"\"\"
459472
beginCaptures:
460-
'1': {name: storage.type.string.python}
461-
'2': {name: punctuation.definition.string.begin.python}
473+
'2': {name: invalid.deprecated.prefix.python}
474+
'3': {name: storage.type.string.python}
475+
'4': {name: punctuation.definition.string.begin.python}
462476
endCaptures:
463477
'0': {name: punctuation.definition.string.end.python}
464478
patterns:
@@ -472,7 +486,7 @@ repository:
472486

473487
string-raw-bin-single-quoted-single-line:
474488
name: string.quoted.single.raw.python
475-
begin: (\b(?:[rR][bB]|[bB][rR]))(\')
489+
begin: (\b(?:R[bB]|[bB]R))(\')
476490
end: (\')|(?<!\\)(\n)
477491
beginCaptures:
478492
'1': {name: storage.type.string.python}
@@ -485,7 +499,7 @@ repository:
485499

486500
string-raw-bin-double-quoted-single-line:
487501
name: string.quoted.double.raw.python
488-
begin: (\b(?:[rR][bB]|[bB][rR]))(\")
502+
begin: (\b(?:R[bB]|[bB]R))(\")
489503
end: (\")|(?<!\\)(\n)
490504
beginCaptures:
491505
'1': {name: storage.type.string.python}
@@ -498,7 +512,7 @@ repository:
498512

499513
string-raw-bin-single-quoted-multi-line:
500514
name: string.quoted.triple.raw.python
501-
begin: (\b(?:[rR][bB]|[bB][rR]))(\'\'\')
515+
begin: (\b(?:R[bB]|[bB]R))(\'\'\')
502516
end: \'\'\'
503517
beginCaptures:
504518
'1': {name: storage.type.string.python}
@@ -510,7 +524,7 @@ repository:
510524

511525
string-raw-bin-double-quoted-multi-line:
512526
name: string.quoted.triple.raw.python
513-
begin: (\b(?:[rR][bB]|[bB][rR]))(\"\"\")
527+
begin: (\b(?:R[bB]|[bB]R))(\"\"\")
514528
end: \"\"\"
515529
beginCaptures:
516530
'1': {name: storage.type.string.python}

0 commit comments

Comments
 (0)