Add odin support, closes #544

This commit is contained in:
Adam Stankiewicz
2020-09-10 16:38:32 +02:00
parent 9243367ba3
commit 05ff14bfda
10 changed files with 265 additions and 62 deletions

View File

@@ -7,4 +7,4 @@ test:
@ scripts/test @ scripts/test
dev: dev:
@ (ls && find scripts) | DEV=1 entr bash -c 'make && make test' @ echo "packages.yaml\nheuristics.yaml\nscripts/test\nscripts/build\nscripts/test_extensions.vim" | DEV=1 entr bash -c 'make && make test'

View File

@@ -7,7 +7,7 @@ A collection of language packs for Vim.
> One to rule them all, one to find them, one to bring them all and in the darkness bind them. > One to rule them all, one to find them, one to bring them all and in the darkness bind them.
- It **won't affect your startup time**, as scripts are loaded only on demand\*. - It **won't affect your startup time**, as scripts are loaded only on demand\*.
- It **installs and updates 120+ times faster** than the <!--Package Count-->195<!--/Package Count--> packages it consists of. - It **installs and updates 120+ times faster** than the <!--Package Count-->196<!--/Package Count--> packages it consists of.
- It is more secure because scripts loaded for all extensions are generated by vim-polyglot (ftdetect). - It is more secure because scripts loaded for all extensions are generated by vim-polyglot (ftdetect).
- Solid syntax and indentation support (other features skipped). Only the best language packs. - Solid syntax and indentation support (other features skipped). Only the best language packs.
- All unnecessary files are ignored (like enormous documentation from php support). - All unnecessary files are ignored (like enormous documentation from php support).
@@ -169,6 +169,7 @@ If you need full functionality of any plugin, please use it directly with your p
- [objc](https://github.com/b4winckler/vim-objc) - [objc](https://github.com/b4winckler/vim-objc)
- [ocaml](https://github.com/rgrinberg/vim-ocaml) - [ocaml](https://github.com/rgrinberg/vim-ocaml)
- [octave](https://github.com/McSinyx/vim-octave) - [octave](https://github.com/McSinyx/vim-octave)
- [odin](https://github.com/Tetralux/odin.vim)
- [opencl](https://github.com/petRUShka/vim-opencl) - [opencl](https://github.com/petRUShka/vim-opencl)
- [perl](https://github.com/vim-perl/vim-perl) - [perl](https://github.com/vim-perl/vim-perl)
- [pgsql](https://github.com/lifepillar/pgsql.vim) - [pgsql](https://github.com/lifepillar/pgsql.vim)

View File

@@ -4,9 +4,9 @@ set cpo&vim
func! polyglot#Heuristics() func! polyglot#Heuristics()
" Try to detect filetype from shebang " Try to detect filetype from shebang
let filetype = polyglot#Shebang() let l:filetype = polyglot#Shebang()
if filetype != "" if l:filetype != ""
exec "setf " . filetype exec "setf " . l:filetype
return 1 return 1
endif endif
@@ -88,41 +88,37 @@ let s:r_envflag = '%(\S\+=\S\+\|-[iS]\|--ignore-environment\|--split-string\)'
let s:r_env = '^\%(\' . s:r_envflag . '\s\+\)*\(\S\+\)' let s:r_env = '^\%(\' . s:r_envflag . '\s\+\)*\(\S\+\)'
func! polyglot#Shebang() func! polyglot#Shebang()
let line1 = getline(1) let l:line1 = getline(1)
if line1 !~# "^#!" if l:line1 !~# "^#!"
return return
endif endif
let pathrest = matchlist(line1, s:r_hashbang) let l:pathrest = matchlist(l:line1, s:r_hashbang)
if len(pathrest) == 0 if len(l:pathrest) == 0
return return
endif endif
let [_, path, rest; __] = pathrest let [_, l:path, l:rest; __] = l:pathrest
let script = split(path, "/")[-1] let l:script = split(l:path, "/")[-1]
if len(script) == 0 if l:script == "env"
return let l:argspath = matchlist(l:rest, s:r_env)
endif if len(l:argspath) == 0
if script == "env"
let argspath = matchlist(rest, s:r_env)
if len(argspath) == 0
return return
endif endif
let script = argspath[1] let l:script = l:argspath[1]
endif endif
if has_key(s:interpreters, script) if has_key(s:interpreters, l:script)
return s:interpreters[script] return s:interpreters[l:script]
endif endif
for interpreter in keys(s:interpreters) for interpreter in keys(s:interpreters)
if script =~# '^' . interpreter if l:script =~# '^' . interpreter
return s:interpreters[interpreter] return s:interpreters[interpreter]
endif endif
endfor endfor

View File

@@ -144,6 +144,7 @@ let s:globs = {
\ 'ocpbuild': '*.ocp', \ 'ocpbuild': '*.ocp',
\ 'ocpbuildroot': '*.root', \ 'ocpbuildroot': '*.root',
\ 'octave': '*.oct,*.m', \ 'octave': '*.oct,*.m',
\ 'odin': '*.odin',
\ 'omake': '*.om,OMakefile,OMakeroot,OMakeroot.in', \ 'omake': '*.om,OMakefile,OMakeroot,OMakeroot.in',
\ 'opam': '*.opam,*.opam.template,opam', \ 'opam': '*.opam,*.opam.template,opam',
\ 'opencl': '*.cl,*.opencl', \ 'opencl': '*.cl,*.opencl',

View File

@@ -1908,6 +1908,10 @@ if !has_key(s:disabled_packages, 'dosini')
au BufNewFile,BufRead php.ini-* call s:StarSetf('dosini') au BufNewFile,BufRead php.ini-* call s:StarSetf('dosini')
endif endif
if !has_key(s:disabled_packages, 'odin')
au BufNewFile,BufRead *.odin setf odin
endif
" end filetypes " end filetypes

41
indent/odin.vim Normal file
View File

@@ -0,0 +1,41 @@
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'odin') == -1
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
setlocal nosmartindent
setlocal nolisp
setlocal autoindent
setlocal indentexpr=GetOdinIndent(v:lnum)
if exists("*GetOdinIndent")
finish
endif
function! GetOdinIndent(lnum)
let prev = prevnonblank(a:lnum-1)
if prev == 0
return 0
endif
let prevline = getline(prev)
let line = getline(a:lnum)
let ind = indent(prev)
if prevline =~ '[({]\s*$'
let ind += &sw
endif
if line =~ '^\s*[)}]'
let ind -= &sw
endif
return ind
endfunction
endif

View File

@@ -1827,3 +1827,9 @@ filetypes:
- '*/etc/yum.repos.d/*' - '*/etc/yum.repos.d/*'
ignored_warnings: ignored_warnings:
- php.ini - php.ini
---
name: odin
remote: Tetralux/odin.vim
filetypes:
- name: odin
linguist: Odin

View File

@@ -97,25 +97,6 @@ def load_data()
[packages, transform_patterns(heuristics)] [packages, transform_patterns(heuristics)]
end end
def parallel(*procs)
threads = procs.map { |p| Thread.new { method(p).call } }
threads.map(&:join).map(&:value)
end
def read_strings(data, keys, print=false)
if data.is_a?(Hash)
data.flat_map do |key, val|
read_strings(val, keys, keys.include?(key))
end
elsif data.is_a?(Array)
data.flat_map { |d| read_strings(d, keys, print) }
elsif data.is_a?(String)
print ? [data] : []
else
[]
end
end
def patterns_to_vim_patterns(patterns) def patterns_to_vim_patterns(patterns)
stdin, stdout, stderr = Open3.popen3('vim', '-V', '--clean', '/dev/stdin', '-es', '-c', "echo expand('%:p:h') | source #{__dir__}/eregex.vim", '-c', "for line in range(0, line('$')) | call setline(line, ExtendedRegex2VimRegex(getline(line))) | endfor", '-c', ':wq! /dev/stdout', chdir: __dir__) stdin, stdout, stderr = Open3.popen3('vim', '-V', '--clean', '/dev/stdin', '-es', '-c', "echo expand('%:p:h') | source #{__dir__}/eregex.vim", '-c', "for line in range(0, line('$')) | call setline(line, ExtendedRegex2VimRegex(getline(line))) | endfor", '-c', ':wq! /dev/stdout', chdir: __dir__)
stdin.write(patterns.join("\n")) stdin.write(patterns.join("\n"))
@@ -168,28 +149,30 @@ def copy_file(package, src, dest)
FileUtils.mkdir_p(File.dirname(dest)) FileUtils.mkdir_p(File.dirname(dest))
name = package.fetch("name") name = package.fetch("name")
header = '" Polyglot metafile' if dest.end_with?(".vim")
if File.exist?(dest) header = '" Polyglot metafile'
meta_dest = dest if File.exist?(dest)
new_dest = dest meta_dest = dest
i = 0 new_dest = dest
while File.exist?(new_dest) i = 0
i += 1 while File.exist?(new_dest)
new_dest = "#{dest.gsub(/\.vim$/, '')}-#{i}.vim" i += 1
end new_dest = "#{dest.gsub(/\.vim$/, '')}-#{i}.vim"
end
if File.read(dest).include?(header)
dest = new_dest if File.read(dest).include?(header)
else dest = new_dest
FileUtils.mv(dest, new_dest) else
File.write(meta_dest, "#{header}\n") FileUtils.mv(dest, new_dest)
open(meta_dest, "a+") do |output| File.write(meta_dest, "#{header}\n")
output << "source <sfile>:h/#{File.basename(new_dest)}\n" open(meta_dest, "a+") do |output|
output << "source <sfile>:h/#{File.basename(new_dest)}\n"
end
dest = "#{dest.gsub(/\.vim$/, '')}-#{i+1}.vim"
end
open(meta_dest, "a+") do |output|
output << "source <sfile>:h/#{File.basename(dest)}\n"
end end
dest = "#{dest.gsub(/\.vim$/, '')}-#{i+1}.vim"
end
open(meta_dest, "a+") do |output|
output << "source <sfile>:h/#{File.basename(dest)}\n"
end end
end end

View File

@@ -231,3 +231,4 @@ call TestFiletype('trasys')
call TestFiletype('basic') call TestFiletype('basic')
call TestFiletype('vb') call TestFiletype('vb')
call TestFiletype('dosini') call TestFiletype('dosini')
call TestFiletype('odin')

170
syntax/odin.vim Normal file
View File

@@ -0,0 +1,170 @@
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'odin') == -1
if exists("b:current_syntax")
finish
endif
syntax keyword odinUsing using
syntax keyword odinTransmute transmute
syntax keyword odinDistinct distinct
syntax keyword odinOpaque opaque
syntax keyword odinStruct struct
syntax keyword odinEnum enum
syntax keyword odinUnion union
syntax keyword odinBitField bit_field
syntax keyword odinBitSet bit_set
syntax keyword odinIf if
syntax keyword odinElse else
syntax keyword odinDo do
syntax keyword odinFor for
syntax keyword odinSwitch switch
syntax keyword odinCase case
syntax keyword odinContinue continue
syntax keyword odinBreak break
syntax keyword odinSizeOf size_of
syntax keyword odinTypeInfoOf type_info_of
syntax keyword odinTypeIdOf typeid_of
syntax keyword odinTypeOf type_of
syntax keyword odinAlignOf align_of
syntax match odinTodo "TODO"
syntax match odinNote "NOTE"
syntax match odinXXX "XXX"
syntax match odinFixMe "FIXME"
syntax match odinNoCheckin "NOCHECKIN"
syntax match odinHack "HACK"
syntax keyword odinDataType string bool b8 b16 b32 b64 rune any rawptr f32 f64 f32le f32be f64le f64be u8 u16 u32 u64 u128 u16le u32le u64le u128le u16be u32be u64be u128be uint i8 i16 i32 i64 i128 i16le i32le i64le i128le i16be i32be i64be i128be int
syntax keyword odinBool true false
syntax keyword odinNull nil
syntax keyword odinDynamic dynamic
syntax keyword odinProc proc
syntax keyword odinIn in
syntax keyword odinNotIn notin
syntax keyword odinNotIn not_in
syntax keyword odinImport import
syntax keyword odinExport export
syntax keyword odinForeign foreign
syntax keyword odinConst const
syntax match odinNoinit "---"
syntax keyword odinPackage package
syntax keyword odinReturn return
syntax keyword odinDefer defer
syntax region odinChar start=/\v'/ skip=/\v\\./ end=/\v'/
syntax region odinString start=/\v"/ skip=/\v\\./ end=/\v"/
syntax match odinFunction "\v<\w*>(\s*::\s*)@="
syntax match odinDynamicFunction "\v<\w*(\s*:\=\s*\(.*\))@="
syntax match odinTagNote "@\<\w\+\>" display
syntax match odinClass "\v<[A-Z]\w+>" display
syntax match odinConstant "\v<[A-Z0-9,_]+>" display
syntax match odinRange "\.\." display
syntax match odinHalfRange "\.\.\<" display
syntax match odinTernaryQMark "?" display
syntax match odinDeclaration "\:\:\?" display
syntax match odinDeclAssign ":=" display
syntax match odinReturnOp "->" display
syntax match odinInteger "\-\?\<\d\+\>" display
syntax match odinFloat "\-\?\<[0-9][0-9_]*\%(\.[0-9][0-9_]*\)\%([eE][+-]\=[0-9_]\+\)\=" display
syntax match odinHex "\-\?\<0x[0-9A-Fa-f]\+\>" display
syntax match odinAddressOf "&" display
syntax match odinDeref "\^" display
syntax match odinMacro "#\<\w\+\>" display
syntax match odinTemplate "$\<\w\+\>"
syntax match odinCommentNote "@\<\w\+\>" contained display
syntax region odinLineComment start=/\/\// end=/$/ contains=odinLineComment, odinCommentNote, odinTodo, odinNote, odinXXX, odinFixMe, odinNoCheckin, odinHack
syntax region odinBlockComment start=/\v\/\*/ end=/\v\*\// contains=odinBlockComment, odinCommentNote, odinTodo, odinNote, odinXXX, odinFixMe, odinNoCheckin, odinHack
highlight link odinUsing Keyword
highlight link odinTransmute Keyword
highlight link odinDistinct Keyword
highlight link odinOpaque Keyword
highlight link odinReturn Keyword
highlight link odinSwitch Keyword
highlight link odinCase Keyword
highlight link odinProc Keyword
highlight link odinIn Keyword
highlight link odinNotIn Keyword
highlight link odinContinue Keyword
highlight link odinBreak Keyword
highlight link odinSizeOf Keyword
highlight link odinTypeOf Keyword
highlight link odinTypeInfoOf Keyword
highlight link odinTypeIdOf Keyword
highlight link odinAlignOf Keyword
highlight link odinPackage Keyword
highlight link odinImport Keyword
highlight link odinExport Keyword
highlight link odinForeign Keyword
highlight link odinNoinit Keyword
highlight link odinDo Keyword
highlight link odinDefer Operator
highlight link odinDynamic Operator
highlight link odinRange Operator
highlight link odinHalfRange Operator
highlight link odinAssign Operator
highlight link odinAddressOf Operator
highlight link odinDeref Operator
highlight link odinDeclaration Operator
highlight link odinDeclAssign Operator
highlight link odinAssign Operator
highlight link odinTernaryQMark Operator
highlight link odinReturnOp Operator
highlight link odinString String
highlight link odinChar String
highlight link odinStruct Structure
highlight link odinEnum Structure
highlight link odinUnion Structure
highlight link odinBitField Structure
highlight link odinBitSet Structure
highlight link odinFunction Function
highlight link odinDynamicFunction Function
highlight link odinMacro Macro
highlight link odinIf Conditional
highlight link odinElse Conditional
highlight link odinFor Repeat
highlight link odinLineComment Comment
highlight link odinBlockComment Comment
highlight link odinCommentNote Todo
highlight link odinTodo Todo
highlight link odinNote Todo
highlight link odinXXX Todo
highlight link odinFixMe Todo
highlight link odinNoCheckin Todo
highlight link odinHack Todo
highlight link odinClass Type
highlight link odinTemplate Constant
highlight link odinTagNote Identifier
highlight link odinDataType Type
highlight link odinBool Boolean
highlight link odinConstant Constant
highlight link odinNull Type
highlight link odinInteger Number
highlight link odinFloat Float
highlight link odinHex Number
let b:current_syntax = "odin"
endif