Skip to content

Commit

Permalink
fix: parse kind and upkind correctly
Browse files Browse the repository at this point in the history
and move the parsing work into parentheses definition parsing phase
rearranged zsh parentheses highlight
  • Loading branch information
91khr committed Dec 3, 2021
1 parent ae4a9da commit aabe91a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
18 changes: 8 additions & 10 deletions autoload/rainbow.vim
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,23 @@ fun s:resolve_parenthesis_with(init_state, p)
elseif k == 'contained'
let contained = 1
elseif k == 'kind'
let kind = v
let kind = s:trim(v)
let kind = kind == '' ? [''] : split(kind, ',', 1)->uniq()
elseif k == 'upkind'
let upkind = v
let upkind = s:trim(v)
let upkind = upkind == '' ? [] : split(upkind, ',', 1)->uniq()
else
let paren .= s
endif
endfor
call extend(upkind, kind)
let rst = [paren, contained, containedin, contains_prefix, contains, op, kind, upkind]
"echom json_encode(rst)
return rst
endfun

fun s:resolve_parenthesis_from_config(config)
return s:resolve_parenthesis_with(['', 0, '', a:config.contains_prefix, '', a:config.operators, '', ''], a:config.parentheses_options)
return s:resolve_parenthesis_with(['', 0, '', a:config.contains_prefix, '', a:config.operators, [''], []], a:config.parentheses_options)
endfun

fun s:synID(prefix, group, lv, id)
Expand All @@ -62,17 +65,12 @@ fun rainbow#syn(config)
let kindlist = {}
for id in range(len(conf.parentheses))
let [paren, contained, containedin, contains_prefix, contains, op, kind, upkind] = s:resolve_parenthesis_with(glob_paran_opts, conf.parentheses[id])
let kind = split(kind, ',')
if kind == []
let kind = ['']
endif
for k in kind
if !has_key(kindlist, k)
let kindlist[k] = []
endif
let kindlist[k] = []
endif
call add(kindlist[k], id)
endfor
let upkind = split(upkind, ',', 1)->extend(kind)->uniq()
for lv in range(cycle)
let uplv = ((lv + cycle - 1) % cycle)
let [rid, pid, upid] = [s:synID(prefix, 'r', lv, id), s:synID(prefix, 'p', lv, id), upkind->mapnew('"@".s:synGroupID(prefix, "Regions", uplv, v:val)')->join(',')]
Expand Down
10 changes: 6 additions & 4 deletions autoload/rainbow_main.vim
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@ let s:rainbow_conf = {
\ 'parentheses': ['start=/(/ end=/)/', 'start=/{/ end=/}/', 'start=/\v\[\ze($|!(\=*\[))/ end=/\]/'],
\ },
\ 'zsh': {
\ 'parentheses': ['start=/((/ end=/))/ kind=arithQuote upkind=,', 'start=/\v\(\ze($|[^(])/ end=/)/',
\ 'start=/(/ end=/)/ contained containedin=zshMathSubst upkind=arithQuote',
\ 'start=/\$\zs((/ end=/))/ contained containedin=zshMathSubst upkind=arithQuote',
\ 'parentheses': [
\ 'start=/((/ end=/))/ kind=arithQuote upkind=,',
\ 'start=/\$((/ end=/))/ kind=arithQuote',
\ 'start=/(/ end=/)/ contained kind=arithInner upkind=arithQuote',
\ 'start=/\v\(\ze($|[^(])/ end=/)/',
\ 'start=/\V[[/ end=/]]/', 'start=/\v\[\ze($|[^[])/ end=/]/',
\ 'start=/{/ end=/}/']
\ 'start=/{/ end=/}/'],
\ },
\ 'perl': {
\ 'syn_name_prefix': 'perlBlockFoldRainbow',
Expand Down

0 comments on commit aabe91a

Please sign in to comment.