-
Notifications
You must be signed in to change notification settings - Fork 10
Fix minlen of builtin commands #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Coverage remained the same at 84.016% when pulling cf0fe1bc7ab0e6c5c56a8083110b940dc6da3eb3 on fix-minlen into f607c09 on master. |
" create builtin command table
"
let s:ex_cmds_h = '/home/haya14busa/src/github.com/vim/vim/src/ex_cmds.h'
let s:Trie = {
\ 'data': {},
\ }
function! s:Trie.new() abort
return deepcopy(self)
endfunction
function! s:Trie.add(s) abort
let d = self.data
for c in split(a:s, '\zs')
if !has_key(d, c)
let d[c] = {}
endif
let d = d[c]
endfor
endfunction
function! s:Trie.in(s) abort
let d = self.data
for c in split(a:s, '\zs')
if has_key(d, c)
let d = d[c]
else
return v:false
endif
endfor
return v:true
endfunction
function! s:Trie.common(s) abort
let d = self.data
let common = []
for c in split(a:s, '\zs')
if has_key(d, c)
let common = add(common, c)
let d = d[c]
else
break
endif
endfor
return join(common, '')
endfunction
function! s:Trie.remove(s) abort
let d = self.data
let kss = [[]]
for c in split(a:s, '\zs')
if has_key(d, c)
let kss = add(kss, copy(kss[-1]) + [c])
let d = d[c]
else
return v:false
endif
endfor
let kss = kss[1:]
let kss = reverse(kss)
for ks in kss
let d = self.data
for [i, k] in map(copy(ks[:-2]), {i, k->[i,k]})
let pd = d
let nk = ks[i+1]
let d = d[k]
endfor
if empty(pd[k][nk])
unlet pd[k][nk]
else
return v:true
endif
endfor
return v:true
endfunction
function! s:test() abort
let t = s:Trie.new()
call t.add('vi')
call t.add('vim')
call t.add('neovim')
call t.add('vimtutor')
call t.add('vimgrep')
echo PP(t.data)
echo '---'
echo t.in('vi')
echo t.in('vimtu')
echo t.in('vimg')
echo t.in('vimgrepppp')
echo t.common('vimgrepppp')
echo t.common('hoge')
echo '---remove'
echo t.remove('vimgrep')
echo t.in('vimgrep')
echo t.data
echo '---'
endfunction
" call s:test()
function! s:gen(ex_cmds_h) abort
let lines = readfile(a:ex_cmds_h)
" { 'name': string, 'flags': string, 'minlen': int, 'parser': string}
let cmds = []
let trie = s:Trie.new()
let cumname = ''
for [i, line] in map(copy(lines), {i, l -> [i, l]})
if line =~# '^EX('
let name = matchstr(line, '"\zs.*\ze",')
let flags = matchstr(lines[i+1], '\t\+\zs.*\ze,$')
let minlen = len(trie.common(name)) + 1
call trie.add(name)
let cmd = {
\ 'name': name,
\ 'flags': flags,
\ 'minlen': minlen,
\ }
let cmds = add(cmds, cmd)
endif
endfor
return cmds
endfunction
let s:latest = s:gen(s:ex_cmds_h)
let s:vimlparser = vimlparser#import()
function! s:gen_new_builtin(existing, latest) abort
let existing_names = {}
for cmd in a:existing
let existing_names[cmd.name] = v:true
endfor
let newcmds = []
for cmd in filter(copy(a:latest), {_, c -> !has_key(existing_names, c.name)})
let newcmds = add(newcmds, extend(cmd, {'parser': 'parse_cmd_common'}))
endfor
return newcmds
endfunction
function! s:gen_viml(newcmds) abort
let lines = []
for c in a:newcmds
let lines = add(lines, ' \ ' . string(c))
endfor
return join(lines, "\n")
endfunction
" -- main
function! s:vimlparser_new_cmds() abort
let vimlparser = vimlparser#import()
let latest = s:gen(s:ex_cmds_h)
let new_cmds = s:gen_new_builtin(s:vimlparser.VimLParser.builtin_commands, s:latest)
echo s:gen_viml(new_cmds)
endfunction
" call s:vimlparser_new_cmds()
function! s:minlen_table() abort
let newtable = {}
for c in s:gen(s:ex_cmds_h)
let newtable[c.name] = c
endfor
let orig = vimlparser#import().VimLParser.builtin_commands
for c in orig
if !has_key(newtable, c.name)
echo 'skip: ' . c.name
continue
endif
let new = newtable[c.name]
if new.minlen != c.minlen
echo [c.minlen, ':' . c.name]
endif
endfor
endfunction
call s:minlen_table()
|
cf0fe1b
to
fa6208e
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
ref: #19