mirror of
https://github.com/neovim/neovim.git
synced 2026-03-28 03:12:00 +00:00
vim-patch:2cf18fc: runtime(python): Update syntax, improve pythonNumber pattern performance (#38263)
- Improve the performance of all pythonNumber patterns by unrolling
digit/underscore sequence loops.
- Split the float literal pattern into two simpler patterns.
fixes: vim/vim#19625 (Reported by James McCoy)
closes: vim/vim#19630
2cf18fcc24
Co-authored-by: Doug Kearns <dougkearns@gmail.com>
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
" 2025 Sep 25 by Vim Project: fix wrong type highlighting #18394
|
||||
" 2025 Dec 03 by Vim Project: highlight t-strings #18679
|
||||
" 2026 Jan 26 by Vim Project: highlight constants #18922
|
||||
" 2026 Mar 11 by Vim Project: fix number performance #19630
|
||||
" Credits: Neil Schemenauer <nas@python.ca>
|
||||
" Dmitry Vasiliev
|
||||
" Rob B
|
||||
@@ -270,16 +271,21 @@ syn match pythonEscape "\\$"
|
||||
" https://docs.python.org/reference/lexical_analysis.html#numeric-literals
|
||||
if !exists("python_no_number_highlight")
|
||||
" numbers (including complex)
|
||||
syn match pythonNumber "\<0[oO]\%(_\=\o\)\+\>"
|
||||
syn match pythonNumber "\<0[xX]\%(_\=\x\)\+\>"
|
||||
syn match pythonNumber "\<0[bB]\%(_\=[01]\)\+\>"
|
||||
syn match pythonNumber "\<\%([1-9]\%(_\=\d\)*\|0\+\%(_\=0\)*\)\>"
|
||||
syn match pythonNumber "\<\d\%(_\=\d\)*[jJ]\>"
|
||||
syn match pythonNumber "\<\d\%(_\=\d\)*[eE][+-]\=\d\%(_\=\d\)*[jJ]\=\>"
|
||||
syn match pythonNumber "\<0[oO]_\=\o\+\%(_\o\+\)*\>"
|
||||
syn match pythonNumber "\<0[xX]_\=\x\+\%(_\x\+\)*\>"
|
||||
syn match pythonNumber "\<0[bB]_\=[01]\+\%(_[01]\+\)*\>"
|
||||
syn match pythonNumber "\<\%([1-9]\d*\%(_\d\+\)*\|0\+\%(_0\+\)*\)\>"
|
||||
syn match pythonNumber "\<\d\+\%(_\d\+\)*[jJ]\>"
|
||||
syn match pythonNumber "\<\d\+\%(_\d\+\)*[eE][+-]\=\d\+\%(_\d\+\)*[jJ]\=\>"
|
||||
" \d\.
|
||||
syn match pythonNumber
|
||||
\ "\<\d\%(_\=\d\)*\.\%([eE][+-]\=\d\%(_\=\d\)*\)\=[jJ]\=\%(\W\|$\)\@="
|
||||
\ "\<\d\+\%(_\d\+\)*\.\%([eE][+-]\=\d\+\%(_\d\+\)*\)\=[jJ]\=\%(\W\|$\)\@="
|
||||
" \d\.\d
|
||||
syn match pythonNumber
|
||||
\ "\%(^\|\W\)\@1<=\%(\d\%(_\=\d\)*\)\=\.\d\%(_\=\d\)*\%([eE][+-]\=\d\%(_\=\d\)*\)\=[jJ]\=\>"
|
||||
\ "\<\d\+\%(_\d\+\)*\.\d\+\%(_\d\+\)*\%([eE][+-]\=\d\+\%(_\d\+\)*\)\=[jJ]\=\>"
|
||||
" \.\d
|
||||
syn match pythonNumber
|
||||
\ "\%(^\|\W\)\@1<=\.\d\+\%(_\d\+\)*\%([eE][+-]\=\d\+\%(_\d\+\)*\)\=[jJ]\=\>"
|
||||
endif
|
||||
|
||||
" Group the built-ins in the order in the 'Python Library Reference' for
|
||||
|
||||
Reference in New Issue
Block a user