Skip to content

Commit f8d6b63

Browse files
committedFeb 17, 2017
support underscores in numbers
mostly taken from hdima/python-syntax#60
1 parent f6aa2f6 commit f8d6b63

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed
 

Diff for: ‎syntax/python.vim

+21-12
Original file line numberDiff line numberDiff line change
@@ -318,28 +318,37 @@ if s:Python2Syntax()
318318

319319
syn match pythonOctError '\<0[oO]\=\o*[8-9]\d*[lL]\=\>' display
320320
syn match pythonBinError '\<0[bB][01]*[2-9]\d*[lL]\=\>' display
321+
322+
syn match pythonFloat '\.\d\+\%([eE][+-]\=\d\+\)\=[jJ]\=\>' display
323+
syn match pythonFloat '\<\d\+[eE][+-]\=\d\+[jJ]\=\>' display
324+
syn match pythonFloat '\<\d\+\.\d*\%([eE][+-]\=\d\+\)\=[jJ]\=' display
321325
else
322-
syn match pythonHexError '\<0[xX]\x*[g-zG-Z]\x*\>' display
323326
syn match pythonOctError '\<0[oO]\=\o*\D\+\d*\>' display
327+
" pythonHexError comes after pythonOctError so that 0xffffl is pythonHexError
328+
syn match pythonHexError '\<0[xX]\x*[g-zG-Z]\x*\>' display
324329
syn match pythonBinError '\<0[bB][01]*\D\+\d*\>' display
325330

326-
syn match pythonHexNumber '\<0[xX]\x\+\>' display
327-
syn match pythonOctNumber '\<0[oO]\o\+\>' display
328-
syn match pythonBinNumber '\<0[bB][01]\+\>' display
331+
syn match pythonHexNumber '\<0[xX][_0-9a-fA-F]*\x\>' display
332+
syn match pythonOctNumber '\<0[oO][_0-7]*\o\>' display
333+
syn match pythonBinNumber '\<0[bB][_01]*[01]\>' display
329334

330-
syn match pythonNumberError '\<\d\+\D\>' display
331-
syn match pythonNumberError '\<0\d\+\>' display
335+
syn match pythonNumberError '\<\d[_0-9]*\D\>' display
336+
syn match pythonNumberError '\<0[_0-9]\+\>' display
337+
syn match pythonNumberError '\<0_x\S*\>' display
338+
syn match pythonNumberError '\<0[bBxXoO][_0-9a-fA-F]*_\>' display
339+
syn match pythonNumberError '\<\d[_0-9]*_\>' display
332340
syn match pythonNumber '\<\d\>' display
333-
syn match pythonNumber '\<[1-9]\d\+\>' display
334-
syn match pythonNumber '\<\d\+[jJ]\>' display
341+
syn match pythonNumber '\<[1-9][_0-9]*\d\>' display
342+
syn match pythonNumber '\<\d[jJ]\>' display
343+
syn match pythonNumber '\<[1-9][_0-9]*\d[jJ]\>' display
335344

336345
syn match pythonOctError '\<0[oO]\=\o*[8-9]\d*\>' display
337346
syn match pythonBinError '\<0[bB][01]*[2-9]\d*\>' display
338-
endif
339347

340-
syn match pythonFloat '\.\d\+\%([eE][+-]\=\d\+\)\=[jJ]\=\>' display
341-
syn match pythonFloat '\<\d\+[eE][+-]\=\d\+[jJ]\=\>' display
342-
syn match pythonFloat '\<\d\+\.\d*\%([eE][+-]\=\d\+\)\=[jJ]\=' display
348+
syn match pythonFloat '\.\d\%([_0-9]*\d\)\=\%([eE][+-]\=\d\%([_0-9]*\d\)\=\)\=[jJ]\=\>' display
349+
syn match pythonFloat '\<\d\%([_0-9]*\d\)\=[eE][+-]\=\d\%([_0-9]*\d\)\=[jJ]\=\>' display
350+
syn match pythonFloat '\<\d\%([_0-9]*\d\)\=\.\d\%([_0-9]*\d\)\=\%([eE][+-]\=\d\%([_0-9]*\d\)\=\)\=[jJ]\=' display
351+
endif
343352

344353
"
345354
" Builtin objects and types

0 commit comments

Comments
 (0)
Please sign in to comment.