Browse Source

Added support for brace escaping in str.format

Dmitry Vasiliev 15 years ago
parent
commit
a2208995a6
4 changed files with 16 additions and 7 deletions
  1. 3
    0
      CHANGES.txt
  2. 5
    2
      python.vim
  3. 6
    3
      python3.0.vim
  4. 2
    2
      test.py

+ 3
- 0
CHANGES.txt View File

@@ -1,5 +1,6 @@
1 1
 Revision 3.0.0 (2008-09-?):
2 2
 
3
+    - Updated support for str.format;
3 4
     - Added new builtins introduced in Python 2.6: "ascii", "exec",
4 5
       "memoryview", "print";
5 6
     - Removed builtins: "apply", "basestring", "buffer", "callable", "coerce",
@@ -8,7 +9,9 @@ Revision 3.0.0 (2008-09-?):
8 9
 
9 10
 Revision 2.6.2 (2008-09-?):
10 11
 
12
+    - Added "VMSError" exception;
11 13
     - Added support for b"..." syntax;
14
+    - Added support for str.format brace escaping;
12 15
 
13 16
 Revision 2.6.1 (2008-09-21):
14 17
 

+ 5
- 2
python.vim View File

@@ -193,12 +193,15 @@ endif
193 193
 
194 194
 if exists("python_highlight_string_format") && python_highlight_string_format != 0
195 195
   " str.format syntax
196
+  syn match pythonStrFormat "{{\|}}" contained containedin=pythonString,pythonUniString,pythonRawString,pythonUniRawString
196 197
   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
197 198
 endif
198 199
 
199 200
 if exists("python_highlight_string_templates") && python_highlight_string_templates != 0
200 201
   " 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
202 205
 endif
203 206
 
204 207
 if exists("python_highlight_doctests") && python_highlight_doctests != 0
@@ -264,7 +267,7 @@ if exists("python_highlight_exceptions") && python_highlight_exceptions != 0
264 267
   syn keyword pythonExClass	SystemError SystemExit TypeError
265 268
   syn keyword pythonExClass	UnboundLocalError UnicodeError
266 269
   syn keyword pythonExClass	UnicodeEncodeError UnicodeDecodeError
267
-  syn keyword pythonExClass	UnicodeTranslateError ValueError
270
+  syn keyword pythonExClass	UnicodeTranslateError ValueError VMSError
268 271
   syn keyword pythonExClass	WindowsError ZeroDivisionError
269 272
 
270 273
   syn keyword pythonExClass	Warning UserWarning BytesWarning DeprecationWarning

+ 6
- 3
python3.0.vim View File

@@ -186,12 +186,15 @@ endif
186 186
 
187 187
 if exists("python_highlight_string_format") && python_highlight_string_format != 0
188 188
   " 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
190 191
 endif
191 192
 
192 193
 if exists("python_highlight_string_templates") && python_highlight_string_templates != 0
193 194
   " 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
195 198
 endif
196 199
 
197 200
 if exists("python_highlight_doctests") && python_highlight_doctests != 0
@@ -252,7 +255,7 @@ if exists("python_highlight_exceptions") && python_highlight_exceptions != 0
252 255
   syn keyword pythonExClass	SystemError SystemExit TypeError
253 256
   syn keyword pythonExClass	UnboundLocalError UnicodeError
254 257
   syn keyword pythonExClass	UnicodeEncodeError UnicodeDecodeError
255
-  syn keyword pythonExClass	UnicodeTranslateError ValueError
258
+  syn keyword pythonExClass	UnicodeTranslateError ValueError VMSError
256 259
   syn keyword pythonExClass	WindowsError ZeroDivisionError
257 260
 
258 261
   syn keyword pythonExClass	Warning UserWarning BytesWarning DeprecationWarning

+ 2
- 2
test.py View File

@@ -75,9 +75,9 @@ b"test"
75 75
 
76 76
 " %f "
77 77
 
78
-"{0.name!r:b} {0[n]} {name!s:  }"
78
+"{0.name!r:b} {0[n]} {name!s:  } {{test}} {{}}"
79 79
 
80
-"${test} ${test ${test}aname"
80
+"${test} ${test ${test}aname $$$ $test+nope"
81 81
 
82 82
 # Doctests.
83 83