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

+ 5
- 2
python.vim View File

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

+ 6
- 3
python3.0.vim View File

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

+ 2
- 2
test.py View File

75
 
75
 
76
 " %f "
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
 # Doctests.
82
 # Doctests.
83
 
83