{"action":"created","issue":{"url":"https://api.github.com/repos/haya14busa/go-vimlparser/issues/20","repository_url":"https://api.github.com/repos/haya14busa/go-vimlparser","labels_url":"https://api.github.com/repos/haya14busa/go-vimlparser/issues/20/labels{/name}","comments_url":"https://api.github.com/repos/haya14busa/go-vimlparser/issues/20/comments","events_url":"https://api.github.com/repos/haya14busa/go-vimlparser/issues/20/events","html_url":"https://github.com/haya14busa/go-vimlparser/pull/20","id":179621135,"number":20,"title":"Fix minlen of builtin commands","user":{"login":"haya14busa","id":3797062,"avatar_url":"https://avatars.githubusercontent.com/u/3797062?v=3","gravatar_id":"","url":"https://api.github.com/users/haya14busa","html_url":"https://github.com/haya14busa","followers_url":"https://api.github.com/users/haya14busa/followers","following_url":"https://api.github.com/users/haya14busa/following{/other_user}","gists_url":"https://api.github.com/users/haya14busa/gists{/gist_id}","starred_url":"https://api.github.com/users/haya14busa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/haya14busa/subscriptions","organizations_url":"https://api.github.com/users/haya14busa/orgs","repos_url":"https://api.github.com/users/haya14busa/repos","events_url":"https://api.github.com/users/haya14busa/events{/privacy}","received_events_url":"https://api.github.com/users/haya14busa/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-09-27T21:37:47Z","updated_at":"2016-09-27T21:44:45Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/haya14busa/go-vimlparser/pulls/20","html_url":"https://github.com/haya14busa/go-vimlparser/pull/20","diff_url":"https://github.com/haya14busa/go-vimlparser/pull/20.diff","patch_url":"https://github.com/haya14busa/go-vimlparser/pull/20.patch"},"body":"ref: #19"},"comment":{"url":"https://api.github.com/repos/haya14busa/go-vimlparser/issues/comments/250008396","html_url":"https://github.com/haya14busa/go-vimlparser/pull/20#issuecomment-250008396","issue_url":"https://api.github.com/repos/haya14busa/go-vimlparser/issues/20","id":250008396,"user":{"login":"haya14busa","id":3797062,"avatar_url":"https://avatars.githubusercontent.com/u/3797062?v=3","gravatar_id":"","url":"https://api.github.com/users/haya14busa","html_url":"https://github.com/haya14busa","followers_url":"https://api.github.com/users/haya14busa/followers","following_url":"https://api.github.com/users/haya14busa/following{/other_user}","gists_url":"https://api.github.com/users/haya14busa/gists{/gist_id}","starred_url":"https://api.github.com/users/haya14busa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/haya14busa/subscriptions","organizations_url":"https://api.github.com/users/haya14busa/orgs","repos_url":"https://api.github.com/users/haya14busa/repos","events_url":"https://api.github.com/users/haya14busa/events{/privacy}","received_events_url":"https://api.github.com/users/haya14busa/received_events","type":"User","site_admin":false},"created_at":"2016-09-27T21:44:45Z","updated_at":"2016-09-27T21:44:45Z","body":"<details>\r\n```vim\r\n\" create builtin command table\r\n\"\r\nlet s:ex_cmds_h = '/home/haya14busa/src/github.com/vim/vim/src/ex_cmds.h'\r\n\r\n\r\nlet s:Trie = {\r\n\\   'data': {},\r\n\\ }\r\n\r\nfunction! s:Trie.new() abort\r\n  return deepcopy(self)\r\nendfunction\r\n\r\nfunction! s:Trie.add(s) abort\r\n  let d = self.data\r\n  for c in split(a:s, '\\zs')\r\n    if !has_key(d, c)\r\n      let d[c] = {}\r\n    endif\r\n    let d = d[c]\r\n  endfor\r\nendfunction\r\n\r\nfunction! s:Trie.in(s) abort\r\n  let d = self.data\r\n  for c in split(a:s, '\\zs')\r\n    if has_key(d, c)\r\n      let d = d[c]\r\n    else\r\n      return v:false\r\n    endif\r\n  endfor\r\n  return v:true\r\nendfunction\r\n\r\nfunction! s:Trie.common(s) abort\r\n  let d = self.data\r\n  let common = []\r\n  for c in split(a:s, '\\zs')\r\n    if has_key(d, c)\r\n      let common = add(common, c)\r\n      let d = d[c]\r\n    else\r\n      break\r\n    endif\r\n  endfor\r\n  return join(common, '')\r\nendfunction\r\n\r\nfunction! s:Trie.remove(s) abort\r\n  let d = self.data\r\n  let kss = [[]]\r\n  for c in split(a:s, '\\zs')\r\n    if has_key(d, c)\r\n      let kss = add(kss, copy(kss[-1]) + [c])\r\n      let d = d[c]\r\n    else\r\n      return v:false\r\n    endif\r\n  endfor\r\n  let kss = kss[1:]\r\n  let kss = reverse(kss)\r\n  for ks in kss\r\n    let d = self.data\r\n    for [i, k] in map(copy(ks[:-2]), {i, k->[i,k]})\r\n      let pd = d\r\n      let nk = ks[i+1]\r\n      let d = d[k]\r\n    endfor\r\n    if empty(pd[k][nk])\r\n      unlet pd[k][nk]\r\n    else\r\n      return v:true\r\n    endif\r\n  endfor\r\n  return v:true\r\nendfunction\r\n\r\n\r\nfunction! s:test() abort\r\n  let t = s:Trie.new()\r\n  call t.add('vi')\r\n  call t.add('vim')\r\n  call t.add('neovim')\r\n  call t.add('vimtutor')\r\n  call t.add('vimgrep')\r\n  echo PP(t.data)\r\n\r\n  echo '---'\r\n  echo t.in('vi')\r\n  echo t.in('vimtu')\r\n  echo t.in('vimg')\r\n  echo t.in('vimgrepppp')\r\n  echo t.common('vimgrepppp')\r\n  echo t.common('hoge')\r\n  echo '---remove'\r\n  echo t.remove('vimgrep')\r\n  echo t.in('vimgrep')\r\n  echo t.data\r\n  echo '---'\r\nendfunction\r\n\" call s:test()\r\n\r\nfunction! s:gen(ex_cmds_h) abort\r\n  let lines = readfile(a:ex_cmds_h)\r\n\r\n  \" { 'name': string, 'flags': string, 'minlen': int, 'parser': string}\r\n  let cmds = []\r\n\r\n  let trie = s:Trie.new()\r\n\r\n  let cumname = ''\r\n  for [i, line] in map(copy(lines), {i, l -> [i, l]})\r\n    if line =~# '^EX('\r\n      let name = matchstr(line, '\"\\zs.*\\ze\",')\r\n      let flags = matchstr(lines[i+1], '\\t\\+\\zs.*\\ze,$')\r\n\r\n      let minlen = len(trie.common(name)) + 1\r\n      call trie.add(name)\r\n\r\n      let cmd = {\r\n      \\   'name': name,\r\n      \\   'flags': flags,\r\n      \\   'minlen': minlen,\r\n      \\ }\r\n      let cmds = add(cmds, cmd)\r\n    endif\r\n  endfor\r\n  return cmds\r\nendfunction\r\n\r\nlet s:latest = s:gen(s:ex_cmds_h)\r\n\r\nlet s:vimlparser = vimlparser#import()\r\n\r\nfunction! s:gen_new_builtin(existing, latest) abort\r\n  let existing_names = {}\r\n  for cmd in a:existing\r\n    let existing_names[cmd.name] = v:true\r\n  endfor\r\n  let newcmds = []\r\n  for cmd in filter(copy(a:latest), {_, c -> !has_key(existing_names, c.name)})\r\n    let newcmds = add(newcmds, extend(cmd, {'parser': 'parse_cmd_common'}))\r\n  endfor\r\n  return newcmds\r\nendfunction\r\n\r\n\r\nfunction! s:gen_viml(newcmds) abort\r\n  let lines = []\r\n  for c in a:newcmds\r\n    let lines = add(lines, '      \\ ' . string(c))\r\n  endfor\r\n  return join(lines, \"\\n\")\r\nendfunction\r\n\r\n\" -- main\r\n\r\nfunction! s:vimlparser_new_cmds() abort\r\n  let vimlparser = vimlparser#import()\r\n  let latest = s:gen(s:ex_cmds_h)\r\n  let new_cmds = s:gen_new_builtin(s:vimlparser.VimLParser.builtin_commands, s:latest)\r\n  echo s:gen_viml(new_cmds)\r\nendfunction\r\n\" call s:vimlparser_new_cmds()\r\n\r\nfunction! s:minlen_table() abort\r\n  let newtable = {}\r\n  for c in s:gen(s:ex_cmds_h)\r\n    let newtable[c.name] = c\r\n  endfor\r\n  let orig = vimlparser#import().VimLParser.builtin_commands\r\n\r\n  for c in orig\r\n    if !has_key(newtable, c.name)\r\n      echo 'skip: ' . c.name\r\n      continue\r\n    endif\r\n    let new = newtable[c.name]\r\n    if new.minlen != c.minlen\r\n      echo [c.minlen, ':' . c.name]\r\n    endif\r\n  endfor\r\nendfunction\r\ncall s:minlen_table()\r\n\r\n```\r\n</details>\r\n\r\n```\r\n[5, ':bufdo']\r\n[5, ':caddbuffer']\r\n[3, ':caddexpr']\r\n[8, ':diffthis']\r\n[3, ':keepmarks']\r\n[3, ':list']\r\n[4, ':lopen']\r\n[5, ':scriptnames']\r\n[3, ':simalt']\r\nskip: sniff\r\n[3, ':srewind']\r\n[5, ':tabdo']\r\n[5, ':windo']\r\n```"}}
{"actor":{"display_login":"haya14busa"}}