Skip to content

Commit 5b5f388

Browse files
committed
Make raw f-strings consistent.
Any f-string allows variable interpolation, that includes a raw f-string. Make all raw prefixes (`r` or `R`) behave the same way in combination with `f` prefix. Fixes #186
1 parent db32a0d commit 5b5f388

19 files changed

+546
-3434
lines changed

Diff for: grammars/MagicPython.cson

+2-908
Large diffs are not rendered by default.

Diff for: grammars/MagicPython.tmLanguage

+2-1,786
Large diffs are not rendered by default.

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

-80
Original file line numberDiff line numberDiff line change
@@ -103,82 +103,6 @@ repository:
103103
bquote: '(""")'
104104
equote: '(""")'
105105

106-
- file: 'regexp.inc.syntax.yaml'
107-
vars:
108-
prefix: 'single-one-'
109-
basename: 'fregexp'
110-
marker: "|(?=\\')"
111-
nested: ''
112-
guard: "|((?=(?<!\\\\)\\n))"
113-
114-
- file: 'regexp.inc.syntax.yaml'
115-
vars:
116-
prefix: 'single-three-'
117-
basename: 'fregexp'
118-
marker: "|(?=\\'\\'\\')"
119-
nested: "- include: '#comments-string-single-three'"
120-
guard: ""
121-
122-
- file: 'regexp.inc.syntax.yaml'
123-
vars:
124-
prefix: 'double-one-'
125-
basename: 'fregexp'
126-
marker: '|(?=")'
127-
nested: ''
128-
guard: "|((?=(?<!\\\\)\\n))"
129-
130-
- file: 'regexp.inc.syntax.yaml'
131-
vars:
132-
prefix: 'double-three-'
133-
basename: 'fregexp'
134-
marker: '|(?=""")'
135-
nested: "- include: '#comments-string-double-three'"
136-
guard: ""
137-
138-
- file: 'regexp.wrapper.syntax.yaml'
139-
vars:
140-
scopename: string.regexp.quoted.single.python
141-
string.interpolated.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-
string.interpolated.python
153-
prefix: 'single-three-'
154-
basename: 'fregexp'
155-
nested: "- include: '#comments-string-single-three'"
156-
modifier: '[fF]'
157-
bquote: "(\\'\\'\\')"
158-
equote: "(\\'\\'\\')"
159-
160-
- file: 'regexp.wrapper.syntax.yaml'
161-
vars:
162-
scopename: string.regexp.quoted.single.python
163-
string.interpolated.python
164-
prefix: 'double-one-'
165-
basename: 'fregexp'
166-
nested: ''
167-
modifier: '[fF]'
168-
bquote: '(")'
169-
equote: '(")|(?<!\\)(\n)'
170-
171-
- file: 'regexp.wrapper.syntax.yaml'
172-
vars:
173-
scopename: string.regexp.quoted.multi.python
174-
string.interpolated.python
175-
prefix: 'double-three-'
176-
basename: 'fregexp'
177-
nested: "- include: '#comments-string-double-three'"
178-
modifier: '[fF]'
179-
bquote: '(""")'
180-
equote: '(""")'
181-
182106
- file: 'pystring.inc.syntax.yaml'
183107
vars:
184108
line: single
@@ -700,10 +624,6 @@ repository:
700624
- include: '#regexp-double-three-line'
701625
- include: '#regexp-single-one-line'
702626
- include: '#regexp-double-one-line'
703-
- include: '#fregexp-single-three-line'
704-
- include: '#fregexp-double-three-line'
705-
- include: '#fregexp-single-one-line'
706-
- include: '#fregexp-double-one-line'
707627

708628
string:
709629
patterns:

Diff for: grammars/src/pyfstring.inc.syntax.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ fstring-normf-quoted-${line}-line:
5151

5252
fstring-raw-quoted-${line}-line:
5353
name: meta.fstring.python
54-
begin: (\b(?:[R][fF]|[fF][R]))(${marker})
54+
begin: (\b(?:[rR][fF]|[fF][rR]))(${marker})
5555
end: (\2)${guard}
5656
beginCaptures:
5757
'1': {name: storage.type.string.python

Diff for: misc/example.py

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ async def coroutine(db:aio_db.DatabaseConnection) -> List[str]:
2222
async with db.transaction():
2323
result = await db.query(...)
2424
print(f'Result: {result!r} {a=} {b=!r}')
25+
print(Rf'data: {c=}')
26+
print(rf'data: {c=}')
2527

2628
mapping = None # type: Dict[int, Any] # PEP 484
2729

Diff for: test/atom-spec/python-spec.js

+335-409
Large diffs are not rendered by default.

Diff for: test/fstrings/empty2.py

+19-17
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,22 @@
77
88
99
10-
rf : source.python, storage.type.string.python, string.interpolated.python, string.regexp.quoted.single.python
11-
" : punctuation.definition.string.begin.python, source.python, string.interpolated.python, string.regexp.quoted.single.python
12-
{ : constant.character.format.placeholder.other.python, source.python, string.interpolated.python, string.regexp.quoted.single.python
13-
} : constant.character.format.placeholder.other.python, source.python, string.interpolated.python, string.regexp.quoted.single.python
14-
: source.python, string.interpolated.python, string.regexp.quoted.single.python
15-
{ : constant.character.format.placeholder.other.python, source.python, string.interpolated.python, string.regexp.quoted.single.python
16-
: invalid.illegal.brace.python, source.python, string.interpolated.python, string.regexp.quoted.single.python
17-
} : constant.character.format.placeholder.other.python, source.python, string.interpolated.python, string.regexp.quoted.single.python
18-
" : punctuation.definition.string.end.python, source.python, string.interpolated.python, string.regexp.quoted.single.python
19-
rf : source.python, storage.type.string.python, string.interpolated.python, string.regexp.quoted.multi.python
20-
""" : punctuation.definition.string.begin.python, source.python, string.interpolated.python, string.regexp.quoted.multi.python
21-
{ : constant.character.format.placeholder.other.python, source.python, string.interpolated.python, string.regexp.quoted.multi.python
22-
} : constant.character.format.placeholder.other.python, source.python, string.interpolated.python, string.regexp.quoted.multi.python
23-
{ : constant.character.format.placeholder.other.python, source.python, string.interpolated.python, string.regexp.quoted.multi.python
24-
: invalid.illegal.brace.python, source.python, string.interpolated.python, string.regexp.quoted.multi.python
25-
} : constant.character.format.placeholder.other.python, source.python, string.interpolated.python, string.regexp.quoted.multi.python
26-
""" : punctuation.definition.string.end.python, source.python, string.interpolated.python, string.regexp.quoted.multi.python
10+
rf : meta.fstring.python, source.python, storage.type.string.python, string.interpolated.python, string.quoted.raw.single.python
11+
" : meta.fstring.python, punctuation.definition.string.begin.python, source.python, string.quoted.raw.single.python
12+
{ : constant.character.format.placeholder.other.python, meta.fstring.python, source.python
13+
} : constant.character.format.placeholder.other.python, meta.fstring.python, source.python
14+
: meta.fstring.python, source.python, string.interpolated.python, string.quoted.raw.single.python
15+
{ : constant.character.format.placeholder.other.python, meta.fstring.python, source.python
16+
: invalid.illegal.brace.python, meta.fstring.python, source.python
17+
} : constant.character.format.placeholder.other.python, meta.fstring.python, source.python
18+
" : meta.fstring.python, punctuation.definition.string.end.python, source.python, string.interpolated.python, string.quoted.raw.single.python
19+
rf : meta.fstring.python, source.python, storage.type.string.python, string.interpolated.python, string.quoted.raw.multi.python
20+
""" : meta.fstring.python, punctuation.definition.string.begin.python, source.python, string.quoted.raw.multi.python
21+
{ : constant.character.format.placeholder.other.python, meta.fstring.python, source.python
22+
} : constant.character.format.placeholder.other.python, meta.fstring.python, source.python
23+
: meta.fstring.python, source.python, string.interpolated.python, string.quoted.raw.multi.python
24+
{ : constant.character.format.placeholder.other.python, meta.fstring.python, source.python
25+
: invalid.illegal.brace.python, meta.fstring.python, source.python
26+
} : constant.character.format.placeholder.other.python, meta.fstring.python, source.python
27+
: meta.fstring.python, source.python, string.interpolated.python, string.quoted.raw.multi.python
28+
""" : meta.fstring.python, punctuation.definition.string.end.python, source.python, string.interpolated.python, string.quoted.raw.multi.python

Diff for: test/fstrings/fraw1.py

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
a = fr'[a-z]'
2+
a = Fr'[a-z]'
3+
a = rf'[a-z]'
4+
a = rF'[a-z]'
5+
6+
7+
8+
9+
a : source.python
10+
: source.python
11+
= : keyword.operator.assignment.python, source.python
12+
: source.python
13+
fr : meta.fstring.python, source.python, storage.type.string.python, string.interpolated.python, string.quoted.raw.single.python
14+
' : meta.fstring.python, punctuation.definition.string.begin.python, source.python, string.quoted.raw.single.python
15+
[a-z] : meta.fstring.python, source.python, string.interpolated.python, string.quoted.raw.single.python
16+
' : meta.fstring.python, punctuation.definition.string.end.python, source.python, string.interpolated.python, string.quoted.raw.single.python
17+
a : source.python
18+
: source.python
19+
= : keyword.operator.assignment.python, source.python
20+
: source.python
21+
Fr : meta.fstring.python, source.python, storage.type.string.python, string.interpolated.python, string.quoted.raw.single.python
22+
' : meta.fstring.python, punctuation.definition.string.begin.python, source.python, string.quoted.raw.single.python
23+
[a-z] : meta.fstring.python, source.python, string.interpolated.python, string.quoted.raw.single.python
24+
' : meta.fstring.python, punctuation.definition.string.end.python, source.python, string.interpolated.python, string.quoted.raw.single.python
25+
a : source.python
26+
: source.python
27+
= : keyword.operator.assignment.python, source.python
28+
: source.python
29+
rf : meta.fstring.python, source.python, storage.type.string.python, string.interpolated.python, string.quoted.raw.single.python
30+
' : meta.fstring.python, punctuation.definition.string.begin.python, source.python, string.quoted.raw.single.python
31+
[a-z] : meta.fstring.python, source.python, string.interpolated.python, string.quoted.raw.single.python
32+
' : meta.fstring.python, punctuation.definition.string.end.python, source.python, string.interpolated.python, string.quoted.raw.single.python
33+
a : source.python
34+
: source.python
35+
= : keyword.operator.assignment.python, source.python
36+
: source.python
37+
rF : meta.fstring.python, source.python, storage.type.string.python, string.interpolated.python, string.quoted.raw.single.python
38+
' : meta.fstring.python, punctuation.definition.string.begin.python, source.python, string.quoted.raw.single.python
39+
[a-z] : meta.fstring.python, source.python, string.interpolated.python, string.quoted.raw.single.python
40+
' : meta.fstring.python, punctuation.definition.string.end.python, source.python, string.interpolated.python, string.quoted.raw.single.python

Diff for: test/fstrings/fraw2.py

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
rf'fo{{2}}'
2+
rf"fo{{2}}"
3+
rf'''fo{{2}}'''
4+
rf"""fo{{2}}"""
5+
6+
7+
8+
9+
rf : meta.fstring.python, source.python, storage.type.string.python, string.interpolated.python, string.quoted.raw.single.python
10+
' : meta.fstring.python, punctuation.definition.string.begin.python, source.python, string.quoted.raw.single.python
11+
fo : meta.fstring.python, source.python, string.interpolated.python, string.quoted.raw.single.python
12+
{{ : constant.character.escape.python, meta.fstring.python, source.python
13+
2 : meta.fstring.python, source.python, string.interpolated.python, string.quoted.raw.single.python
14+
}} : constant.character.escape.python, meta.fstring.python, source.python
15+
' : meta.fstring.python, punctuation.definition.string.end.python, source.python, string.interpolated.python, string.quoted.raw.single.python
16+
rf : meta.fstring.python, source.python, storage.type.string.python, string.interpolated.python, string.quoted.raw.single.python
17+
" : meta.fstring.python, punctuation.definition.string.begin.python, source.python, string.quoted.raw.single.python
18+
fo : meta.fstring.python, source.python, string.interpolated.python, string.quoted.raw.single.python
19+
{{ : constant.character.escape.python, meta.fstring.python, source.python
20+
2 : meta.fstring.python, source.python, string.interpolated.python, string.quoted.raw.single.python
21+
}} : constant.character.escape.python, meta.fstring.python, source.python
22+
" : meta.fstring.python, punctuation.definition.string.end.python, source.python, string.interpolated.python, string.quoted.raw.single.python
23+
rf : meta.fstring.python, source.python, storage.type.string.python, string.interpolated.python, string.quoted.raw.multi.python
24+
''' : meta.fstring.python, punctuation.definition.string.begin.python, source.python, string.quoted.raw.multi.python
25+
fo : meta.fstring.python, source.python, string.interpolated.python, string.quoted.raw.multi.python
26+
{{ : constant.character.escape.python, meta.fstring.python, source.python
27+
2 : meta.fstring.python, source.python, string.interpolated.python, string.quoted.raw.multi.python
28+
}} : constant.character.escape.python, meta.fstring.python, source.python
29+
''' : meta.fstring.python, punctuation.definition.string.end.python, source.python, string.interpolated.python, string.quoted.raw.multi.python
30+
rf : meta.fstring.python, source.python, storage.type.string.python, string.interpolated.python, string.quoted.raw.multi.python
31+
""" : meta.fstring.python, punctuation.definition.string.begin.python, source.python, string.quoted.raw.multi.python
32+
fo : meta.fstring.python, source.python, string.interpolated.python, string.quoted.raw.multi.python
33+
{{ : constant.character.escape.python, meta.fstring.python, source.python
34+
2 : meta.fstring.python, source.python, string.interpolated.python, string.quoted.raw.multi.python
35+
}} : constant.character.escape.python, meta.fstring.python, source.python
36+
""" : meta.fstring.python, punctuation.definition.string.end.python, source.python, string.interpolated.python, string.quoted.raw.multi.python

Diff for: test/fstrings/fraw3.py

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
rf'fo{2}'
2+
rf"fo{2}"
3+
rf'''fo{2}'''
4+
rf"""fo{2}"""
5+
6+
7+
8+
9+
rf : meta.fstring.python, source.python, storage.type.string.python, string.interpolated.python, string.quoted.raw.single.python
10+
' : meta.fstring.python, punctuation.definition.string.begin.python, source.python, string.quoted.raw.single.python
11+
fo : meta.fstring.python, source.python, string.interpolated.python, string.quoted.raw.single.python
12+
{ : constant.character.format.placeholder.other.python, meta.fstring.python, source.python
13+
2 : constant.numeric.dec.python, meta.fstring.python, source.python
14+
} : constant.character.format.placeholder.other.python, meta.fstring.python, source.python
15+
' : meta.fstring.python, punctuation.definition.string.end.python, source.python, string.interpolated.python, string.quoted.raw.single.python
16+
rf : meta.fstring.python, source.python, storage.type.string.python, string.interpolated.python, string.quoted.raw.single.python
17+
" : meta.fstring.python, punctuation.definition.string.begin.python, source.python, string.quoted.raw.single.python
18+
fo : meta.fstring.python, source.python, string.interpolated.python, string.quoted.raw.single.python
19+
{ : constant.character.format.placeholder.other.python, meta.fstring.python, source.python
20+
2 : constant.numeric.dec.python, meta.fstring.python, source.python
21+
} : constant.character.format.placeholder.other.python, meta.fstring.python, source.python
22+
" : meta.fstring.python, punctuation.definition.string.end.python, source.python, string.interpolated.python, string.quoted.raw.single.python
23+
rf : meta.fstring.python, source.python, storage.type.string.python, string.interpolated.python, string.quoted.raw.multi.python
24+
''' : meta.fstring.python, punctuation.definition.string.begin.python, source.python, string.quoted.raw.multi.python
25+
fo : meta.fstring.python, source.python, string.interpolated.python, string.quoted.raw.multi.python
26+
{ : constant.character.format.placeholder.other.python, meta.fstring.python, source.python
27+
2 : constant.numeric.dec.python, meta.fstring.python, source.python
28+
} : constant.character.format.placeholder.other.python, meta.fstring.python, source.python
29+
''' : meta.fstring.python, punctuation.definition.string.end.python, source.python, string.interpolated.python, string.quoted.raw.multi.python
30+
rf : meta.fstring.python, source.python, storage.type.string.python, string.interpolated.python, string.quoted.raw.multi.python
31+
""" : meta.fstring.python, punctuation.definition.string.begin.python, source.python, string.quoted.raw.multi.python
32+
fo : meta.fstring.python, source.python, string.interpolated.python, string.quoted.raw.multi.python
33+
{ : constant.character.format.placeholder.other.python, meta.fstring.python, source.python
34+
2 : constant.numeric.dec.python, meta.fstring.python, source.python
35+
} : constant.character.format.placeholder.other.python, meta.fstring.python, source.python
36+
""" : meta.fstring.python, punctuation.definition.string.end.python, source.python, string.interpolated.python, string.quoted.raw.multi.python

0 commit comments

Comments
 (0)