Skip to content

Commit a220899

Browse files
committed
Added support for brace escaping in str.format
1 parent 9c1c35f commit a220899

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Revision 3.0.0 (2008-09-?):
22

3+
- Updated support for str.format;
34
- Added new builtins introduced in Python 2.6: "ascii", "exec",
45
"memoryview", "print";
56
- Removed builtins: "apply", "basestring", "buffer", "callable", "coerce",
@@ -8,7 +9,9 @@ Revision 3.0.0 (2008-09-?):
89

910
Revision 2.6.2 (2008-09-?):
1011

12+
- Added "VMSError" exception;
1113
- Added support for b"..." syntax;
14+
- Added support for str.format brace escaping;
1215

1316
Revision 2.6.1 (2008-09-21):
1417

python.vim

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,15 @@ endif
193193

194194
if exists("python_highlight_string_format") && python_highlight_string_format != 0
195195
" str.format syntax
196+
syn match pythonStrFormat "{{\|}}" contained containedin=pythonString,pythonUniString,pythonRawString,pythonUniRawString
196197
syn match pythonStrFormat "{\([a-zA-Z_][a-zA-Z0-9_]*\|\d\+\)\(\.[a-zA-Z_][a-zA-Z0-9_]*\|\[\(\d\+\|[^!:\}]\+\)\]\)*\(![rs]\)\=\(:\({\([a-zA-Z_][a-zA-Z0-9_]*\|\d\+\)}\|\([^}]\=[<>=^]\)\=[ +-]\=#\=0\=\d*\(\.\d\+\)\=[bcdeEfFgGnoxX%]\=\)\=\)\=}" contained containedin=pythonString,pythonUniString,pythonRawString,pythonUniRawString
197198
endif
198199

199200
if exists("python_highlight_string_templates") && python_highlight_string_templates != 0
200201
" String templates
201-
syn match pythonStrTemplate "\$\(\$\|{[a-zA-Z_][a-zA-Z0-9_]*}\|[a-zA-Z_][a-zA-Z0-9_]*\)" contained containedin=pythonString,pythonUniString,pythonRawString,pythonUniRawString
202+
syn match pythonStrTemplate "\$\$" contained containedin=pythonString,pythonUniString,pythonRawString,pythonUniRawString
203+
syn match pythonStrTemplate "\${[a-zA-Z_][a-zA-Z0-9_]*}" contained containedin=pythonString,pythonUniString,pythonRawString,pythonUniRawString
204+
syn match pythonStrTemplate "\$[a-zA-Z_][a-zA-Z0-9_]*" contained containedin=pythonString,pythonUniString,pythonRawString,pythonUniRawString
202205
endif
203206

204207
if exists("python_highlight_doctests") && python_highlight_doctests != 0
@@ -264,7 +267,7 @@ if exists("python_highlight_exceptions") && python_highlight_exceptions != 0
264267
syn keyword pythonExClass SystemError SystemExit TypeError
265268
syn keyword pythonExClass UnboundLocalError UnicodeError
266269
syn keyword pythonExClass UnicodeEncodeError UnicodeDecodeError
267-
syn keyword pythonExClass UnicodeTranslateError ValueError
270+
syn keyword pythonExClass UnicodeTranslateError ValueError VMSError
268271
syn keyword pythonExClass WindowsError ZeroDivisionError
269272

270273
syn keyword pythonExClass Warning UserWarning BytesWarning DeprecationWarning

python3.0.vim

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,15 @@ endif
186186

187187
if exists("python_highlight_string_format") && python_highlight_string_format != 0
188188
" str.format syntax
189-
syn match pythonStrFormat "{\([a-zA-Z_][a-zA-Z0-9_]*\|\d\+\)\(\.[a-zA-Z_][a-zA-Z0-9_]*\|\[\(\d\+\|[^!:\}]\+\)\]\)*\(![rs]\)\=\(:\({\([a-zA-Z_][a-zA-Z0-9_]*\|\d\+\)}\|\([^}]\=[<>=^]\)\=[ +-]\=#\=0\=\d*\(\.\d\+\)\=[bcdeEfFgGnoxX%]\=\)\=\)\=}" contained containedin=pythonString,pythonUniString,pythonRawString,pythonUniRawString
189+
syn match pythonStrFormat "{{\|}}" contained containedin=pythonString,pythonUniString,pythonRawString,pythonUniRawString
190+
syn match pythonStrFormat "{\([a-zA-Z_][a-zA-Z0-9_]*\|\d\+\)\(\.[a-zA-Z_][a-zA-Z0-9_]*\|\[\(\d\+\|[^!:\}]\+\)\]\)*\(![rsa]\)\=\(:\({\([a-zA-Z_][a-zA-Z0-9_]*\|\d\+\)}\|\([^}]\=[<>=^]\)\=[ +-]\=#\=0\=\d*\(\.\d\+\)\=[bcdeEfFgGnoxX%]\=\)\=\)\=}" contained containedin=pythonString,pythonUniString,pythonRawString,pythonUniRawString
190191
endif
191192

192193
if exists("python_highlight_string_templates") && python_highlight_string_templates != 0
193194
" String templates
194-
syn match pythonStrTemplate "\$\(\$\|{[a-zA-Z_][a-zA-Z0-9_]*}\|[a-zA-Z_][a-zA-Z0-9_]*\)" contained containedin=pythonString,pythonUniString,pythonRawString,pythonUniRawString
195+
syn match pythonStrTemplate "\$\$" contained containedin=pythonString,pythonUniString,pythonRawString,pythonUniRawString
196+
syn match pythonStrTemplate "\${[a-zA-Z_][a-zA-Z0-9_]*}" contained containedin=pythonString,pythonUniString,pythonRawString,pythonUniRawString
197+
syn match pythonStrTemplate "\$[a-zA-Z_][a-zA-Z0-9_]*" contained containedin=pythonString,pythonUniString,pythonRawString,pythonUniRawString
195198
endif
196199

197200
if exists("python_highlight_doctests") && python_highlight_doctests != 0
@@ -252,7 +255,7 @@ if exists("python_highlight_exceptions") && python_highlight_exceptions != 0
252255
syn keyword pythonExClass SystemError SystemExit TypeError
253256
syn keyword pythonExClass UnboundLocalError UnicodeError
254257
syn keyword pythonExClass UnicodeEncodeError UnicodeDecodeError
255-
syn keyword pythonExClass UnicodeTranslateError ValueError
258+
syn keyword pythonExClass UnicodeTranslateError ValueError VMSError
256259
syn keyword pythonExClass WindowsError ZeroDivisionError
257260

258261
syn keyword pythonExClass Warning UserWarning BytesWarning DeprecationWarning

test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ class classname
7575

7676
" %f "
7777

78-
"{0.name!r:b} {0[n]} {name!s: }"
78+
"{0.name!r:b} {0[n]} {name!s: } {{test}} {{}}"
7979

80-
"${test} ${test ${test}aname"
80+
"${test} ${test ${test}aname $$$ $test+nope"
8181

8282
# Doctests.
8383

0 commit comments

Comments
 (0)