Browse Source

Added support for non-ASCII identifiers

Dmitry Vasiliev 15 years ago
parent
commit
64749a3a88
4 changed files with 61 additions and 57 deletions
  1. 4
    2
      CHANGES.txt
  2. 0
    5
      TODO.txt
  3. 49
    46
      python3.0.vim
  4. 8
    4
      test.py

+ 4
- 2
CHANGES.txt View File

@@ -1,6 +1,8 @@
1
-Revision 3.0.0 (2008-09-?):
1
+Revision 3.0.0 (2008-12-07):
2 2
 
3
-    - Removed trailing 'L' support for all numbers;
3
+    - Added support for non-ASCII identifiers;
4
+    - Added support for new text strings and binary data (bytes);
5
+    - Updated support for numeric literals;
4 6
     - Updated support for str.format;
5 7
     - Added new builtins introduced in Python 2.6: "ascii", "exec",
6 8
       "memoryview", "print";

+ 0
- 5
TODO.txt View File

@@ -1,11 +1,6 @@
1 1
 Now
2 2
 ===
3 3
 
4
-- (Python 3.0) non-ASCII identifiers. Also str.format should be updated;
5
-
6
-- (Python 3.0) support for b"..." syntax and remove u"..." syntax. Also all
7
-  escapes need to be updated;
8
-
9 4
 Later
10 5
 =====
11 6
 

+ 49
- 46
python3.0.vim View File

@@ -2,9 +2,9 @@
2 2
 " Language:	Python
3 3
 " Maintainer:	Dmitry Vasiliev <dima@hlabs.spb.ru>
4 4
 " URL:		http://www.hlabs.spb.ru/vim/python.vim
5
-" Last Change:	2008-09-21
5
+" Last Change:	2008-12-07
6 6
 " Filenames:	*.py
7
-" Version:	2.6.1
7
+" Version:	3.0.0
8 8
 "
9 9
 " Based on python.vim (from Vim 6.1 distribution)
10 10
 " by Neil Schemenauer <nas@python.ca>
@@ -103,7 +103,7 @@ syn keyword pythonStatement	lambda yield
103 103
 syn keyword pythonStatement	with nonlocal
104 104
 syn keyword pythonStatement	False None True
105 105
 syn keyword pythonStatement	def class nextgroup=pythonFunction skipwhite
106
-syn match   pythonFunction	"[a-zA-Z_][a-zA-Z0-9_]*" display contained
106
+syn match   pythonFunction	"\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" display contained
107 107
 syn keyword pythonRepeat	for while
108 108
 syn keyword pythonConditional	if elif else
109 109
 syn keyword pythonImport	import from
@@ -116,7 +116,7 @@ syn match   pythonDecorator	"@" display nextgroup=pythonFunction skipwhite
116 116
 " Comments
117 117
 syn match   pythonComment	"#.*$" display contains=pythonTodo,@Spell
118 118
 syn match   pythonRun		"\%^#!.*$"
119
-syn match   pythonCoding	"\%^.*\(\n.*\)\?#.*coding[:=]\s*[0-9A-Za-z-_.]\+.*$"
119
+syn match   pythonCoding	"\%^.*\%(\n.*\)\?#.*coding[:=]\s*[0-9A-Za-z-_.]\+.*$"
120 120
 syn keyword pythonTodo		TODO FIXME XXX contained
121 121
 
122 122
 " Errors
@@ -128,7 +128,7 @@ syn match pythonError		"[=]\{3,}" display
128 128
 " TODO: Mixing spaces and tabs also may be used for pretty formatting multiline
129 129
 " statements. For now I don't know how to work around this.
130 130
 if exists("python_highlight_indent_errors") && python_highlight_indent_errors != 0
131
-  syn match pythonIndentError	"^\s*\( \t\|\t \)\s*\S"me=e-1 display
131
+  syn match pythonIndentError	"^\s*\%( \t\|\t \)\s*\S"me=e-1 display
132 132
 endif
133 133
 
134 134
 " Trailing space errors
@@ -142,25 +142,18 @@ syn region pythonString		start=+"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+
142 142
 syn region pythonString		start=+"""+ end=+"""+ keepend contains=pythonEscape,pythonEscapeError,pythonDocTest2,pythonSpaceError,@Spell
143 143
 syn region pythonString		start=+'''+ end=+'''+ keepend contains=pythonEscape,pythonEscapeError,pythonDocTest,pythonSpaceError,@Spell
144 144
 
145
-syn match  pythonEscape		+\\[abfnrtv'"\\]+ display contained
146
-syn match  pythonEscape		"\\\o\o\=\o\=" display contained
145
+syn match  pythonEscape		    +\\[abfnrtv'"\\]+ display contained
146
+syn match  pythonEscape		    "\\\o\o\=\o\=" display contained
147 147
 syn match  pythonEscapeError	"\\\o\{,2}[89]" display contained
148
-syn match  pythonEscape		"\\x\x\{2}" display contained
148
+syn match  pythonEscape		    "\\x\x\{2}" display contained
149 149
 syn match  pythonEscapeError	"\\x\x\=\X" display contained
150
-syn match  pythonEscape		"\\$"
151
-
152
-" Unicode strings
153
-syn region pythonUniString	start=+[uU]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError,@Spell
154
-syn region pythonUniString	start=+[uU]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError,@Spell
155
-syn region pythonUniString	start=+[uU]"""+ end=+"""+ keepend contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError,pythonDocTest2,pythonSpaceError,@Spell
156
-syn region pythonUniString	start=+[uU]'''+ end=+'''+ keepend contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError,pythonDocTest,pythonSpaceError,@Spell
157
-
158
-syn match  pythonUniEscape	"\\u\x\{4}" display contained
159
-syn match  pythonUniEscapeError	"\\u\x\{,3}\X" display contained
160
-syn match  pythonUniEscape	"\\U\x\{8}" display contained
161
-syn match  pythonUniEscapeError	"\\U\x\{,7}\X" display contained
162
-syn match  pythonUniEscape	"\\N{[A-Z ]\+}" display contained
163
-syn match  pythonUniEscapeError	"\\N{[^A-Z ]\+}" display contained
150
+syn match  pythonEscape		    "\\$"
151
+syn match  pythonEscape         "\\u\x\{4}" display contained
152
+syn match  pythonEscapeError	"\\u\x\{,3}\X" display contained
153
+syn match  pythonEscape	        "\\U\x\{8}" display contained
154
+syn match  pythonEscapeError	"\\U\x\{,7}\X" display contained
155
+syn match  pythonEscape	        "\\N{[A-Z ]\+}" display contained
156
+syn match  pythonEscapeError	"\\N{[^A-Z ]\+}" display contained
164 157
 
165 158
 " Raw strings
166 159
 syn region pythonRawString	start=+[rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,@Spell
@@ -170,32 +163,39 @@ syn region pythonRawString	start=+[rR]'''+ end=+'''+ keepend contains=pythonDocT
170 163
 
171 164
 syn match pythonRawEscape	+\\['"]+ display transparent contained
172 165
 
173
-" Unicode raw strings
174
-syn region pythonUniRawString	start=+[uU][rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,pythonUniRawEscape,pythonUniRawEscapeError,@Spell
175
-syn region pythonUniRawString	start=+[uU][rR]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape,pythonUniRawEscape,pythonUniRawEscapeError,@Spell
176
-syn region pythonUniRawString	start=+[uU][rR]"""+ end=+"""+ keepend contains=pythonUniRawEscape,pythonUniRawEscapeError,pythonDocTest2,pythonSpaceError,@Spell
177
-syn region pythonUniRawString	start=+[uU][rR]'''+ end=+'''+ keepend contains=pythonUniRawEscape,pythonUniRawEscapeError,pythonDocTest,pythonSpaceError,@Spell
166
+" Bytes
167
+syn region pythonBytes		start=+[bB]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonBytesContent,pythonBytesError,pythonBytesEscape,pythonBytesEscapeError,@Spell
168
+syn region pythonBytes		start=+[bB]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonBytesContent,pythonBytesError,pythonBytesEscape,pythonBytesEscapeError,@Spell
169
+syn region pythonBytes		start=+[bB]"""+ end=+"""+ keepend contains=pythonBytesContent,pythonBytesError,pythonBytesEscape,pythonBytesEscapeError,pythonDocTest2,pythonSpaceError,@Spell
170
+syn region pythonBytes		start=+[bB]'''+ end=+'''+ keepend contains=pythonBytesContent,pythonBytesError,pythonBytesEscape,pythonBytesEscapeError,pythonDocTest,pythonSpaceError,@Spell
171
+
172
+syn match pythonBytesContent    "[\u0001-\u007f]\+" display contained
173
+syn match pythonBytesError    "[^\u0001-\u007f]\+" display contained
178 174
 
179
-syn match  pythonUniRawEscape		"\([^\\]\(\\\\\)*\)\@<=\\u\x\{4}" display contained
180
-syn match  pythonUniRawEscapeError	"\([^\\]\(\\\\\)*\)\@<=\\u\x\{,3}\X" display contained
175
+syn match pythonBytesEscape	    +\\[abfnrtv'"\\]+ display contained
176
+syn match pythonBytesEscape	    "\\\o\o\=\o\=" display contained
177
+syn match pythonBytesEscapeError	"\\\o\{,2}[89]" display contained
178
+syn match pythonBytesEscape	    "\\x\x\{2}" display contained
179
+syn match pythonBytesEscapeError	"\\x\x\=\X" display contained
180
+syn match pythonBytesEscape	    "\\$"
181 181
 
182 182
 if exists("python_highlight_string_formatting") && python_highlight_string_formatting != 0
183 183
   " String formatting
184
-  syn match pythonStrFormatting	"%\(([^)]\+)\)\=[-#0 +]*\d*\(\.\d\+\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonUniString,pythonRawString,pythonUniRawString
185
-  syn match pythonStrFormatting	"%[-#0 +]*\(\*\|\d\+\)\=\(\.\(\*\|\d\+\)\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonUniString,pythonRawString,pythonUniRawString
184
+  syn match pythonStrFormatting	"%\%(([^)]\+)\)\=[-#0 +]*\d*\%(\.\d\+\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonRawString
185
+  syn match pythonStrFormatting	"%[-#0 +]*\%(\*\|\d\+\)\=\%(\.\%(\*\|\d\+\)\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonRawString
186 186
 endif
187 187
 
188 188
 if exists("python_highlight_string_format") && python_highlight_string_format != 0
189 189
   " str.format syntax
190
-  syn match pythonStrFormat "{{\|}}" contained containedin=pythonString,pythonUniString,pythonRawString,pythonUniRawString
191
-  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
+  syn match pythonStrFormat "{{\|}}" contained containedin=pythonString,pythonRawString
191
+  syn match pythonStrFormat	"{\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)\%(\.\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_*\)\|\[\%(\d\+\|[^!:\}]\+\)\]\)*\%(![rsa]\)\=\%(:\%({\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)}\|\%([^}]\=[<>=^]\)\=[ +-]\=#\=0\=\d*\%(\.\d\+\)\=[bcdeEfFgGnoxX%]\=\)\=\)\=}" contained containedin=pythonString,pythonRawString
192 192
 endif
193 193
 
194 194
 if exists("python_highlight_string_templates") && python_highlight_string_templates != 0
195 195
   " String templates
196
-  syn match pythonStrTemplate	"\$\$" contained containedin=pythonString,pythonUniString,pythonRawString,pythonUniRawString
197
-  syn match pythonStrTemplate	"\${[a-zA-Z_][a-zA-Z0-9_]*}" contained containedin=pythonString,pythonUniString,pythonRawString,pythonUniRawString
198
-  syn match pythonStrTemplate	"\$[a-zA-Z_][a-zA-Z0-9_]*" contained containedin=pythonString,pythonUniString,pythonRawString,pythonUniRawString
196
+  syn match pythonStrTemplate	"\$\$" contained containedin=pythonString,pythonRawString
197
+  syn match pythonStrTemplate	"\${[a-zA-Z_][a-zA-Z0-9_]*}" contained containedin=pythonString,pythonRawString
198
+  syn match pythonStrTemplate	"\$[a-zA-Z_][a-zA-Z0-9_]*" contained containedin=pythonString,pythonRawString
199 199
 endif
200 200
 
201 201
 if exists("python_highlight_doctests") && python_highlight_doctests != 0
@@ -211,11 +211,14 @@ syn match   pythonHexNumber	"\<0[xX]\x\+\>" display
211 211
 syn match   pythonOctNumber "\<0[oO]\o\+\>" display
212 212
 syn match   pythonBinNumber "\<0[bB][01]\+\>" display
213 213
 
214
-syn match   pythonNumber	"\<\d\+[jJ]\=\>" display
214
+syn match   pythonNumber	"\<0\>" display
215
+syn match   pythonNumber	"\<[1-9]\d\+\>" display
216
+syn match   pythonNumber	"\<\d\+[jJ]\>" display
217
+syn match   pythonNumberError	"\<0\d\+\>" display
215 218
 
216
-syn match   pythonFloat		"\.\d\+\([eE][+-]\=\d\+\)\=[jJ]\=\>" display
219
+syn match   pythonFloat		"\.\d\+\%([eE][+-]\=\d\+\)\=[jJ]\=\>" display
217 220
 syn match   pythonFloat		"\<\d\+[eE][+-]\=\d\+[jJ]\=\>" display
218
-syn match   pythonFloat		"\<\d\+\.\d*\([eE][+-]\=\d\+\)\=[jJ]\=" display
221
+syn match   pythonFloat		"\<\d\+\.\d*\%([eE][+-]\=\d\+\)\=[jJ]\=" display
219 222
 
220 223
 syn match   pythonOctError	"\<0[oO]\=\o*[8-9]\d*\>" display
221 224
 syn match   pythonBinError	"\<0[bB][01]*[2-9]\d*\>" display
@@ -303,16 +306,15 @@ if version >= 508 || !exists("did_python_syn_inits")
303 306
   HiLink pythonSpaceError	Error
304 307
 
305 308
   HiLink pythonString		String
306
-  HiLink pythonUniString	String
307 309
   HiLink pythonRawString	String
308
-  HiLink pythonUniRawString	String
309
-
310 310
   HiLink pythonEscape			Special
311 311
   HiLink pythonEscapeError		Error
312
-  HiLink pythonUniEscape		Special
313
-  HiLink pythonUniEscapeError		Error
314
-  HiLink pythonUniRawEscape		Special
315
-  HiLink pythonUniRawEscapeError	Error
312
+
313
+  HiLink pythonBytes		    String
314
+  HiLink pythonBytesContent	    String
315
+  HiLink pythonBytesError	    Error
316
+  HiLink pythonBytesEscape		Special
317
+  HiLink pythonBytesEscapeError	Error
316 318
 
317 319
   HiLink pythonStrFormatting	Special
318 320
   HiLink pythonStrFormat    	Special
@@ -326,6 +328,7 @@ if version >= 508 || !exists("did_python_syn_inits")
326 328
   HiLink pythonOctNumber	Number
327 329
   HiLink pythonBinNumber	Number
328 330
   HiLink pythonFloat		Float
331
+  HiLink pythonNumberError  Error
329 332
   HiLink pythonOctError	    Error
330 333
   HiLink pythonHexError		Error
331 334
   HiLink pythonBinError		Error

+ 8
- 4
test.py View File

@@ -11,7 +11,9 @@
11 11
 with break continue del exec return pass print raise global assert lambda yield
12 12
 for while if elif else import from as try except finally and in is not or
13 13
 def functionname
14
-class classname
14
+class Classname
15
+def функция
16
+class Класс
15 17
 
16 18
 # Builtin objects.
17 19
 
@@ -48,11 +50,11 @@ RuntimeWarning FutureWarning OverflowWarning ImportWarning UnicodeWarning
48 50
 
49 51
 # Numbers
50 52
 
51
-0 0x1f 077 .3 12.34 100L 0j 0j 34.2E-3 0b10 0o77 0xfffffffL 0L
53
+0 0x1f .3 12.34 0j 0j 34.2E-3 0b10 0o77
52 54
 
53 55
 # Erroneous numbers
54 56
 
55
-08 0xk 0x  0b102 0o78
57
+077 100L 0xfffffffL 0L 08 0xk 0x  0b102 0o78
56 58
 
57 59
 # Strings
58 60
 
@@ -67,10 +69,12 @@ RuntimeWarning FutureWarning OverflowWarning ImportWarning UnicodeWarning
67 69
 " \a\b\c\"\'\n\r \x34\077 \08 \xag"
68 70
 r" \" \' "
69 71
 
70
-u"test"
72
+"testтест"
71 73
 
72 74
 b"test"
73 75
 
76
+b"тестtest"
77
+
74 78
 # Formattings
75 79
 
76 80
 " %f "