Skip to content

Commit 48f978a

Browse files
committed
remove another pass and refactor regexp
1 parent 8fdc5e0 commit 48f978a

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

after/syntax/css.vim

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -469,14 +469,25 @@ function! s:CreateSynMatch(color, pattern)
469469
return ''
470470
endfunction
471471

472+
let s:_funcname = '\(rgb\|hsl\)a\?'
473+
let s:_numval = '\(\d\{1,3}%\?\)'
474+
let s:_ws_ = '\s*'
475+
let s:_listsep = s:_ws_ . ',' . s:_ws_
476+
let s:_otherargs_ = '\%(,[^)]*\)\?'
477+
let s:_funcexpr = s:_funcname . '[(]' . s:_numval . s:_listsep . s:_numval . s:_listsep . s:_numval . s:_ws_ . s:_otherargs_ . '[)]'
478+
let s:_hexcolor = '#\(\x\{3}\|\x\{6}\)\>'
479+
let s:_grammar = s:_funcexpr . '\|' . s:_hexcolor
472480
function! s:ParseScreen()
473-
" N.B. these substitute() calls are here just for the side effect
481+
" N.B. this substitute() call is here just for the side effect
474482
" of invoking s:CreateSynMatch during substitution -- because
475483
" match() and friends do not allow finding all matches in a single
476484
" scan without examining the start of the string over and over
477-
call substitute( substitute( join( getline('w0','w$'), "\n" ),
478-
\ '#\(\x\{3}\|\x\{6}\)\>', '\=s:CreateSynMatch(submatch(1), submatch(0))', 'g' ),
479-
\ '\(rgb\|hsl\)a\?(\s*\(\d\{1,3}%\?\)\s*,\s*\(\d\{1,3}%\?\)\s*,\s*\(\d\{1,3}%\?\)\s*\%(,[^)]*\)\?)', '\=s:CreateSynMatch(submatch(1) == "rgb" ? s:RGB2Color(submatch(2),submatch(3),submatch(4)) : s:HSL2Color(submatch(2),submatch(3),submatch(4)), submatch(0))', 'g' )
485+
call substitute( join( getline('w0','w$'), "\n" ), s:_grammar,
486+
\ '\=s:CreateSynMatch(('
487+
\ . ' submatch(1) == "rgb" ? s:RGB2Color(submatch(2),submatch(3),submatch(4)) :'
488+
\ . ' submatch(1) == "hsl" ? s:HSL2Color(submatch(2),submatch(3),submatch(4)) :'
489+
\ . ' submatch(5)'
490+
\ . '), submatch(0))', 'g' )
480491
endfunction
481492

482493
call s:ParseScreen()

0 commit comments

Comments
 (0)