Skip to content

Commit 2d5d68d

Browse files
committed
Add pythonic comments to multi-line regexp strings.
1 parent 42b9f93 commit 2d5d68d

File tree

4 files changed

+35
-6
lines changed

4 files changed

+35
-6
lines changed

grammars/MagicPython.YAML-tmLanguage

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ repository:
280280
endCaptures:
281281
'0': {name: punctuation.definition.string.end.python}
282282
patterns:
283-
- include: 'source.regexp.python'
283+
- include: '#regexp-multiline'
284284

285285
regexp-double-quoted-multi-line:
286286
name: string.regexp.quoted.triple.python
@@ -293,8 +293,13 @@ repository:
293293
'5': {name: punctuation.definition.string.begin.python}
294294
endCaptures:
295295
'0': {name: punctuation.definition.string.end.python}
296+
patterns:
297+
- include: '#regexp-multiline'
298+
299+
regexp-multiline:
296300
patterns:
297301
- include: 'source.regexp.python'
302+
- include: '#comments'
298303

299304
string:
300305
patterns:

grammars/MagicPython.cson

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ repository:
442442
name: "punctuation.definition.string.end.python"
443443
patterns: [
444444
{
445-
include: "source.regexp.python"
445+
include: "#regexp-multiline"
446446
}
447447
]
448448
"regexp-double-quoted-multi-line":
@@ -461,10 +461,19 @@ repository:
461461
endCaptures:
462462
"0":
463463
name: "punctuation.definition.string.end.python"
464+
patterns: [
465+
{
466+
include: "#regexp-multiline"
467+
}
468+
]
469+
"regexp-multiline":
464470
patterns: [
465471
{
466472
include: "source.regexp.python"
467473
}
474+
{
475+
include: "#comments"
476+
}
468477
]
469478
string:
470479
patterns: [

grammars/MagicPython.tmLanguage

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@
741741
<array>
742742
<dict>
743743
<key>include</key>
744-
<string>source.regexp.python</string>
744+
<string>#regexp-multiline</string>
745745
</dict>
746746
</array>
747747
</dict>
@@ -784,12 +784,26 @@
784784
<string>punctuation.definition.string.end.python</string>
785785
</dict>
786786
</dict>
787+
<key>patterns</key>
788+
<array>
789+
<dict>
790+
<key>include</key>
791+
<string>#regexp-multiline</string>
792+
</dict>
793+
</array>
794+
</dict>
795+
<key>regexp-multiline</key>
796+
<dict>
787797
<key>patterns</key>
788798
<array>
789799
<dict>
790800
<key>include</key>
791801
<string>source.regexp.python</string>
792802
</dict>
803+
<dict>
804+
<key>include</key>
805+
<string>#comments</string>
806+
</dict>
793807
</array>
794808
</dict>
795809
<key>string</key>

test/regexp/comments2.re

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
(?x)
22
foo (?#
33
comment 1
4-
)
5-
bar (?#comment 2)
4+
) bar
5+
baz (?#comment 2)
66

77

88

@@ -12,7 +12,8 @@ comment 1
1212
comment 1 : comment.regexp, source.regexp.python
1313
: comment.regexp, source.regexp.python
1414
) : comment.regexp, punctuation.comments.end.regexp, source.regexp.python
15-
bar : source.regexp.python
15+
bar : source.regexp.python
16+
baz : source.regexp.python
1617
(?# : comment.regexp, punctuation.comments.begin.regexp, source.regexp.python
1718
comment 2 : comment.regexp, source.regexp.python
1819
) : comment.regexp, punctuation.comments.end.regexp, source.regexp.python

0 commit comments

Comments
 (0)