Skip to content

Commit e13309e

Browse files
committed
More refined fstring regexps.
1 parent 34c12b0 commit e13309e

18 files changed

+3593
-420
lines changed

Diff for: grammars/MagicPython.cson

+1,048-98
Large diffs are not rendered by default.

Diff for: grammars/MagicPython.tmLanguage

+2,060-203
Large diffs are not rendered by default.

Diff for: grammars/MagicRegExp.cson

+42-10
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,30 @@ patterns: [
1212
]
1313
repository:
1414
"regexp-base-expression":
15+
patterns: [
16+
{
17+
include: "#regexp-quantifier"
18+
}
19+
{
20+
include: "#regexp-base-common"
21+
}
22+
]
23+
"fregexp-base-expression":
24+
patterns: [
25+
{
26+
include: "#fregexp-quantifier"
27+
}
28+
{
29+
include: "#fstring-formatting-braces"
30+
}
31+
{
32+
match: "\\{.*?\\}"
33+
}
34+
{
35+
include: "#regexp-base-common"
36+
}
37+
]
38+
"regexp-base-common":
1539
patterns: [
1640
{
1741
name: "support.other.match.any.regexp"
@@ -36,17 +60,25 @@ repository:
3660
{
3761
include: "#regexp-escape-sequence"
3862
}
39-
{
40-
name: "keyword.operator.quantifier.regexp"
41-
match: '''
42-
(?x)
43-
\\{(
44-
\\d+ | \\d+,(\\d+)? | ,\\d+
45-
)\\}
46-
47-
'''
48-
}
4963
]
64+
"regexp-quantifier":
65+
name: "keyword.operator.quantifier.regexp"
66+
match: '''
67+
(?x)
68+
\\{(
69+
\\d+ | \\d+,(\\d+)? | ,\\d+
70+
)\\}
71+
72+
'''
73+
"fregexp-quantifier":
74+
name: "keyword.operator.quantifier.regexp"
75+
match: '''
76+
(?x)
77+
\\{\\{(
78+
\\d+ | \\d+,(\\d+)? | ,\\d+
79+
)\\}\\}
80+
81+
'''
5082
"regexp-backreference-number":
5183
name: "meta.backreference.regexp"
5284
match: "(\\\\[1-9]\\d?)"

Diff for: grammars/MagicRegExp.tmLanguage

+55-7
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,42 @@
2323
<key>repository</key>
2424
<dict>
2525
<key>regexp-base-expression</key>
26+
<dict>
27+
<key>patterns</key>
28+
<array>
29+
<dict>
30+
<key>include</key>
31+
<string>#regexp-quantifier</string>
32+
</dict>
33+
<dict>
34+
<key>include</key>
35+
<string>#regexp-base-common</string>
36+
</dict>
37+
</array>
38+
</dict>
39+
<key>fregexp-base-expression</key>
40+
<dict>
41+
<key>patterns</key>
42+
<array>
43+
<dict>
44+
<key>include</key>
45+
<string>#fregexp-quantifier</string>
46+
</dict>
47+
<dict>
48+
<key>include</key>
49+
<string>#fstring-formatting-braces</string>
50+
</dict>
51+
<dict>
52+
<key>match</key>
53+
<string>\{.*?\}</string>
54+
</dict>
55+
<dict>
56+
<key>include</key>
57+
<string>#regexp-base-common</string>
58+
</dict>
59+
</array>
60+
</dict>
61+
<key>regexp-base-common</key>
2662
<dict>
2763
<key>patterns</key>
2864
<array>
@@ -60,17 +96,29 @@
6096
<key>include</key>
6197
<string>#regexp-escape-sequence</string>
6298
</dict>
63-
<dict>
64-
<key>name</key>
65-
<string>keyword.operator.quantifier.regexp</string>
66-
<key>match</key>
67-
<string>(?x)
99+
</array>
100+
</dict>
101+
<key>regexp-quantifier</key>
102+
<dict>
103+
<key>name</key>
104+
<string>keyword.operator.quantifier.regexp</string>
105+
<key>match</key>
106+
<string>(?x)
68107
\{(
69108
\d+ | \d+,(\d+)? | ,\d+
70109
)\}
71110
</string>
72-
</dict>
73-
</array>
111+
</dict>
112+
<key>fregexp-quantifier</key>
113+
<dict>
114+
<key>name</key>
115+
<string>keyword.operator.quantifier.regexp</string>
116+
<key>match</key>
117+
<string>(?x)
118+
\{\{(
119+
\d+ | \d+,(\d+)? | ,\d+
120+
)\}\}
121+
</string>
74122
</dict>
75123
<key>regexp-backreference-number</key>
76124
<dict>

Diff for: grammars/src/MagicPython.syntax.yaml

+133-64
Original file line numberDiff line numberDiff line change
@@ -35,31 +35,147 @@ repository:
3535
- file: 'regexp.inc.syntax.yaml'
3636
vars:
3737
prefix: 'single-one-'
38+
basename: 'regexp'
3839
marker: "|(?=\\')"
3940
nested: ''
4041
guard: "|((?=(?<!\\\\)\\n))"
4142

4243
- file: 'regexp.inc.syntax.yaml'
4344
vars:
4445
prefix: 'single-three-'
46+
basename: 'regexp'
4547
marker: "|(?=\\'\\'\\')"
4648
nested: "- include: '#comments-string-single-three'"
4749
guard: ""
4850

4951
- file: 'regexp.inc.syntax.yaml'
5052
vars:
5153
prefix: 'double-one-'
54+
basename: 'regexp'
5255
marker: '|(?=")'
5356
nested: ''
5457
guard: "|((?=(?<!\\\\)\\n))"
5558

5659
- file: 'regexp.inc.syntax.yaml'
5760
vars:
5861
prefix: 'double-three-'
62+
basename: 'regexp'
5963
marker: '|(?=""")'
6064
nested: "- include: '#comments-string-double-three'"
6165
guard: ""
6266

67+
- file: 'regexp.wrapper.syntax.yaml'
68+
vars:
69+
scopename: string.regexp.quoted.single.python
70+
prefix: 'single-one-'
71+
basename: 'regexp'
72+
nested: ''
73+
modifier: '[bB]'
74+
bquote: "(\\')"
75+
equote: "(\\')|(?<!\\\\)(\\n)"
76+
77+
- file: 'regexp.wrapper.syntax.yaml'
78+
vars:
79+
scopename: string.regexp.quoted.multi.python
80+
prefix: 'single-three-'
81+
basename: 'regexp'
82+
nested: "- include: '#comments-string-single-three'"
83+
modifier: '[bB]'
84+
bquote: "(\\'\\'\\')"
85+
equote: "(\\'\\'\\')"
86+
87+
- file: 'regexp.wrapper.syntax.yaml'
88+
vars:
89+
scopename: string.regexp.quoted.single.python
90+
prefix: 'double-one-'
91+
basename: 'regexp'
92+
nested: ''
93+
modifier: '[bB]'
94+
bquote: '(")'
95+
equote: '(")|(?<!\\)(\n)'
96+
97+
- file: 'regexp.wrapper.syntax.yaml'
98+
vars:
99+
scopename: string.regexp.quoted.multi.python
100+
prefix: 'double-three-'
101+
basename: 'regexp'
102+
nested: "- include: '#comments-string-double-three'"
103+
modifier: '[bB]'
104+
bquote: '(""")'
105+
equote: '(""")'
106+
107+
- file: 'regexp.inc.syntax.yaml'
108+
vars:
109+
prefix: 'single-one-'
110+
basename: 'fregexp'
111+
marker: "|(?=\\')"
112+
nested: ''
113+
guard: "|((?=(?<!\\\\)\\n))"
114+
115+
- file: 'regexp.inc.syntax.yaml'
116+
vars:
117+
prefix: 'single-three-'
118+
basename: 'fregexp'
119+
marker: "|(?=\\'\\'\\')"
120+
nested: "- include: '#comments-string-single-three'"
121+
guard: ""
122+
123+
- file: 'regexp.inc.syntax.yaml'
124+
vars:
125+
prefix: 'double-one-'
126+
basename: 'fregexp'
127+
marker: '|(?=")'
128+
nested: ''
129+
guard: "|((?=(?<!\\\\)\\n))"
130+
131+
- file: 'regexp.inc.syntax.yaml'
132+
vars:
133+
prefix: 'double-three-'
134+
basename: 'fregexp'
135+
marker: '|(?=""")'
136+
nested: "- include: '#comments-string-double-three'"
137+
guard: ""
138+
139+
- file: 'regexp.wrapper.syntax.yaml'
140+
vars:
141+
scopename: string.regexp.quoted.single.python
142+
prefix: 'single-one-'
143+
basename: 'fregexp'
144+
nested: ''
145+
modifier: '[fF]'
146+
bquote: "(\\')"
147+
equote: "(\\')|(?<!\\\\)(\\n)"
148+
149+
- file: 'regexp.wrapper.syntax.yaml'
150+
vars:
151+
scopename: string.regexp.quoted.multi.python
152+
prefix: 'single-three-'
153+
basename: 'fregexp'
154+
nested: "- include: '#comments-string-single-three'"
155+
modifier: '[fF]'
156+
bquote: "(\\'\\'\\')"
157+
equote: "(\\'\\'\\')"
158+
159+
- file: 'regexp.wrapper.syntax.yaml'
160+
vars:
161+
scopename: string.regexp.quoted.single.python
162+
prefix: 'double-one-'
163+
basename: 'fregexp'
164+
nested: ''
165+
modifier: '[fF]'
166+
bquote: '(")'
167+
equote: '(")|(?<!\\)(\n)'
168+
169+
- file: 'regexp.wrapper.syntax.yaml'
170+
vars:
171+
scopename: string.regexp.quoted.multi.python
172+
prefix: 'double-three-'
173+
basename: 'fregexp'
174+
nested: "- include: '#comments-string-double-three'"
175+
modifier: '[fF]'
176+
bquote: '(""")'
177+
equote: '(""")'
178+
63179
- file: 'pystring.inc.syntax.yaml'
64180
vars:
65181
line: single
@@ -509,68 +625,14 @@ repository:
509625

510626
regexp:
511627
patterns:
512-
- include: '#regexp-single-quoted-multi-line'
513-
- include: '#regexp-double-quoted-multi-line'
514-
- include: '#regexp-single-quoted-single-line'
515-
- include: '#regexp-double-quoted-single-line'
516-
517-
regexp-single-quoted-single-line:
518-
name: string.regexp.quoted.single.python
519-
begin: \b(([uU]r)|([bBfF]r)|(r[bBfF]?))(\')
520-
end: (\')|(?<!\\)(\n)
521-
beginCaptures:
522-
'2': {name: invalid.deprecated.prefix.python}
523-
'3': {name: storage.type.string.python}
524-
'4': {name: storage.type.string.python}
525-
'5': {name: punctuation.definition.string.begin.python}
526-
endCaptures:
527-
'1': {name: punctuation.definition.string.end.python}
528-
'2': {name: invalid.illegal.newline.python}
529-
patterns:
530-
- include: '#single-one-regexp-expression'
531-
532-
regexp-double-quoted-single-line:
533-
name: string.regexp.quoted.single.python
534-
begin: \b(([uU]r)|([bBfF]r)|(r[bBfF]?))(\")
535-
end: (\")|(?<!\\)(\n)
536-
beginCaptures:
537-
'2': {name: invalid.deprecated.prefix.python}
538-
'3': {name: storage.type.string.python}
539-
'4': {name: storage.type.string.python}
540-
'5': {name: punctuation.definition.string.begin.python}
541-
endCaptures:
542-
'1': {name: punctuation.definition.string.end.python}
543-
'2': {name: invalid.illegal.newline.python}
544-
patterns:
545-
- include: '#double-one-regexp-expression'
546-
547-
regexp-single-quoted-multi-line:
548-
name: string.regexp.quoted.multi.python
549-
begin: \b(([uU]r)|([bBfF]r)|(r[bBfF]?))(\'\'\')
550-
end: \'\'\'
551-
beginCaptures:
552-
'2': {name: invalid.deprecated.prefix.python}
553-
'3': {name: storage.type.string.python}
554-
'4': {name: storage.type.string.python}
555-
'5': {name: punctuation.definition.string.begin.python}
556-
endCaptures:
557-
'0': {name: punctuation.definition.string.end.python}
558-
patterns:
559-
- include: '#single-three-regexp-expression'
560-
561-
regexp-double-quoted-multi-line:
562-
name: string.regexp.quoted.multi.python
563-
begin: \b(([uU]r)|([bBfF]r)|(r[bBfF]?))(\"\"\")
564-
end: \"\"\"
565-
beginCaptures:
566-
'2': {name: invalid.deprecated.prefix.python}
567-
'3': {name: storage.type.string.python}
568-
'4': {name: storage.type.string.python}
569-
'5': {name: punctuation.definition.string.begin.python}
570-
endCaptures:
571-
'0': {name: punctuation.definition.string.end.python}
572-
patterns:
573-
- include: '#double-three-regexp-expression'
628+
- include: '#regexp-single-three-line'
629+
- include: '#regexp-double-three-line'
630+
- include: '#regexp-single-one-line'
631+
- include: '#regexp-double-one-line'
632+
- include: '#fregexp-single-three-line'
633+
- include: '#fregexp-double-three-line'
634+
- include: '#fregexp-single-one-line'
635+
- include: '#fregexp-double-one-line'
574636

575637
string:
576638
patterns:
@@ -718,14 +780,21 @@ repository:
718780
(?x) \{ [^'"}\n]*? \} (?=.*?\})
719781
720782
fstring-formatting:
783+
patterns:
784+
- include: '#fstring-formatting-braces'
785+
- include: '#fstring-formatting-singe-brace'
786+
787+
fstring-formatting-braces:
721788
patterns:
722789
- comment: empty braces are illegal
723790
name: invalid.illegal.brace.python
724791
match: ({\s*?})
725792
- name: constant.character.escape.python
726793
match: ({{|}})
727-
- name: invalid.illegal.brace.python
728-
match: (}(?!}))
794+
795+
fstring-formatting-singe-brace:
796+
name: invalid.illegal.brace.python
797+
match: (}(?!}))
729798

730799
import:
731800
comment: |

0 commit comments

Comments
 (0)