mirror of
https://github.com/neovim/neovim.git
synced 2025-09-05 19:08:15 +00:00
vim-patch:9.1.0982: TI linker files are not recognized
Problem: TI linker files are not recognized
Solution: inspect '*.cmd' files and detect TI linker files
as 'lnk' filetype, include a lnk ftplugin and syntax
script (Wu, Zhenyu)
closes: vim/vim#16320
39a4eb0b2c
Co-authored-by: Wu, Zhenyu <wuzhenyu@ustc.edu>
This commit is contained in:

committed by
Christian Clason

parent
7ecd348b3d
commit
1877cd5fcd
14
runtime/ftplugin/lnk.vim
Normal file
14
runtime/ftplugin/lnk.vim
Normal file
@@ -0,0 +1,14 @@
|
||||
" Vim filetype plugin file
|
||||
" Language: TI linker command file
|
||||
" Document: https://software-dl.ti.com/ccs/esd/documents/sdto_cgt_Linker-Command-File-Primer.html
|
||||
" Maintainer: Wu, Zhenyu <wuzhenyu@ustc.edu>
|
||||
" Last Change: 2024 Dec 31
|
||||
|
||||
if exists("b:did_ftplugin") | finish | endif
|
||||
let b:did_ftplugin = 1
|
||||
|
||||
setlocal comments=sO:*\ -,mO:*\ \ ,exO:*/,s1:/*,mb:*,ex:*/,:///,://
|
||||
setlocal commentstring=/*\ %s\ */
|
||||
setlocal iskeyword+=.
|
||||
|
||||
let b:undo_ftplugin = "setl commentstring< comments< iskeyword<"
|
@@ -1393,7 +1393,7 @@ local extension = {
|
||||
txt = detect.txt,
|
||||
xml = detect.xml,
|
||||
y = detect.y,
|
||||
cmd = detect_line1('^/%*', 'rexx', 'dosbatch'),
|
||||
cmd = detect.cmd,
|
||||
rul = detect.rul,
|
||||
cpy = detect_line1('^##', 'python', 'cobol'),
|
||||
dsl = detect_line1('^%s*<!', 'dsl', 'structurizr'),
|
||||
|
@@ -219,6 +219,24 @@ function M.cls(_, bufnr)
|
||||
return 'st'
|
||||
end
|
||||
|
||||
--- *.cmd is close to a Batch file, but on OS/2 Rexx files and TI linker command files also use *.cmd.
|
||||
--- lnk: `/* comment */`, `// comment`, and `--linker-option=value`
|
||||
--- rexx: `/* comment */`, `-- comment`
|
||||
--- @type vim.filetype.mapfn
|
||||
function M.cmd(_, bufnr)
|
||||
local lines = table.concat(getlines(bufnr, 1, 20))
|
||||
if matchregex(lines, [[MEMORY\|SECTIONS\|\%(^\|\n\)--\S\|\%(^\|\n\)//]]) then
|
||||
return 'lnk'
|
||||
else
|
||||
local line1 = getline(bufnr, 1)
|
||||
if line1:find('^/%*') then
|
||||
return 'rexx'
|
||||
else
|
||||
return 'dosbatch'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--- @type vim.filetype.mapfn
|
||||
function M.conf(path, bufnr)
|
||||
if fn.did_filetype() ~= 0 or path:find(vim.g.ft_ignore_pat) then
|
||||
|
77
runtime/syntax/cmacro.vim
Normal file
77
runtime/syntax/cmacro.vim
Normal file
@@ -0,0 +1,77 @@
|
||||
" Vim syntax file
|
||||
" Language: C macro for C preprocessor
|
||||
" Maintainer: Wu, Zhenyu <wuzhenyu@ustc.edu>
|
||||
" Last Change: 2024 Dec 31
|
||||
" modified from syntax/c.vim
|
||||
|
||||
" C compiler has a preprocessor: `cpp -P test.txt`
|
||||
" test.txt doesn't need to be a C file
|
||||
if exists("b:current_syntax")
|
||||
finish
|
||||
endif
|
||||
|
||||
let s:cpo_save = &cpo
|
||||
set cpo&vim
|
||||
|
||||
" Accept %: for # (C99)
|
||||
syn region cmacroPreCondit start="^\s*\zs\%(%:\|#\)\s*\%(if\|ifdef\|ifndef\|elif\)\>" skip="\\$" end="$" keepend contains=cmacroCppParen,cmacroNumbers
|
||||
syn match cmacroPreConditMatch display "^\s*\zs\%(%:\|#\)\s*\%(else\|endif\)\>"
|
||||
if !exists("c_no_if0")
|
||||
syn cluster cmacroCppOutInGroup contains=cmacroCppInIf,cmacroCppInElse,cmacroCppInElse2,cmacroCppOutIf,cmacroCppOutIf2,cmacroCppOutElse,cmacroCppInSkip,cmacroCppOutSkip
|
||||
syn region cmacroCppOutWrapper start="^\s*\zs\%(%:\|#\)\s*if\s\+0\+\s*\%($\|//\|/\*\|&\)" end=".\@=\|$" contains=cmacroCppOutIf,cmacroCppOutElse,@NoSpell fold
|
||||
syn region cmacroCppOutIf contained start="0\+" matchgroup=cmacroCppOutWrapper end="^\s*\%(%:\|#\)\s*endif\>" contains=cmacroCppOutIf2,cmacroCppOutElse
|
||||
if !exists("c_no_if0_fold")
|
||||
syn region cmacroCppOutIf2 contained matchgroup=cmacroCppOutWrapper start="0\+" end="^\s*\%(%:\|#\)\s*\%(else\>\|elif\s\+\%(0\+\s*\%($\|//\|/\*\|&\)\)\@!\|endif\>\)"me=s-1 contains=cmacroCppOutSkip,@Spell fold
|
||||
else
|
||||
syn region cmacroCppOutIf2 contained matchgroup=cmacroCppOutWrapper start="0\+" end="^\s*\%(%:\|#\)\s*\%(else\>\|elif\s\+\%(0\+\s*\%($\|//\|/\*\|&\)\)\@!\|endif\>\)"me=s-1 contains=cmacroCppOutSkip,@Spell
|
||||
endif
|
||||
syn region cmacroCppOutElse contained matchgroup=cmacroCppOutWrapper start="^\s*\%(%:\|#\)\s*\%(else\|elif\)" end="^\s*\%(%:\|#\)\s*endif\>"me=s-1 contains=TOP,cmacroPreCondit
|
||||
syn region cmacroCppInWrapper start="^\s*\zs\%(%:\|#\)\s*if\s\+0*[1-9]\d*\s*\%($\|//\|/\*\||\)" end=".\@=\|$" contains=cmacroCppInIf,cmacroCppInElse fold
|
||||
syn region cmacroCppInIf contained matchgroup=cmacroCppInWrapper start="\d\+" end="^\s*\%(%:\|#\)\s*endif\>" contains=TOP,cmacroPreCondit
|
||||
if !exists("c_no_if0_fold")
|
||||
syn region cmacroCppInElse contained start="^\s*\%(%:\|#\)\s*\%(else\>\|elif\s\+\%(0*[1-9]\d*\s*\%($\|//\|/\*\||\)\)\@!\)" end=".\@=\|$" containedin=cmacroCppInIf contains=cmacroCppInElse2 fold
|
||||
else
|
||||
syn region cmacroCppInElse contained start="^\s*\%(%:\|#\)\s*\%(else\>\|elif\s\+\%(0*[1-9]\d*\s*\%($\|//\|/\*\||\)\)\@!\)" end=".\@=\|$" containedin=cmacroCppInIf contains=cmacroCppInElse2
|
||||
endif
|
||||
syn region cmacroCppInElse2 contained matchgroup=cmacroCppInWrapper start="^\s*\%(%:\|#\)\s*\%(else\|elif\)\%([^/]\|/[^/*]\)*" end="^\s*\%(%:\|#\)\s*endif\>"me=s-1 contains=cmacroCppOutSkip,@Spell
|
||||
syn region cmacroCppOutSkip contained start="^\s*\%(%:\|#\)\s*\%(if\>\|ifdef\>\|ifndef\>\)" skip="\\$" end="^\s*\%(%:\|#\)\s*endif\>" contains=cmacroCppOutSkip
|
||||
syn region cmacroCppInSkip contained matchgroup=cmacroCppInWrapper start="^\s*\%(%:\|#\)\s*\%(if\s\+\%(\d\+\s*\%($\|//\|/\*\||\|&\)\)\@!\|ifdef\>\|ifndef\>\)" skip="\\$" end="^\s*\%(%:\|#\)\s*endif\>" containedin=cmacroCppOutElse,cmacroCppInIf,cmacroCppInSkip contains=TOP,cmacroPreProc
|
||||
endif
|
||||
syn region cmacroIncluded display contained start=+"+ skip=+\\\\\|\\"+ end=+"+
|
||||
syn match cmacroIncluded display contained "<[^>]*>"
|
||||
syn match cmacroInclude display "^\s*\zs\%(%:\|#\)\s*include\>\s*["<]" contains=cmacroIncluded
|
||||
"syn match cmacroLineSkip "\\$"
|
||||
syn cluster cmacroPreProcmacroGroup contains=cmacroPreCondit,cmacroIncluded,cmacroInclude,cmacroDefine,cmacroCppOutWrapper,cmacroCppInWrapper,@cmacroCppOutInGroup,cmacroNumbersCom,@cmacroCommentGroup,cmacroParen,cmacroBracket,cmacroMulti,cmacroBadBlock
|
||||
syn region cmacroDefine start="^\s*\zs\%(%:\|#\)\s*\%(define\|undef\)\>" skip="\\$" end="$" keepend contains=ALLBUT,@cmacroPreProcmacroGroup,@Spell
|
||||
syn region cmacroPreProc start="^\s*\zs\%(%:\|#\)\s*\%(pragma\>\|line\>\|warning\>\|warn\>\|error\>\)" skip="\\$" end="$" keepend contains=ALLBUT,@cmacroPreProcmacroGroup,@Spell
|
||||
|
||||
" be able to fold #pragma regions
|
||||
syn region cmacroPragma start="^\s*#pragma\s\+region\>" end="^\s*#pragma\s\+endregion\>" transparent keepend extend fold
|
||||
|
||||
syn keyword cmacroTodo contained TODO FIXME XXX NOTE
|
||||
syn region cmacroComment start='/\*' end='\*/' contains=cmacroTodo,@Spell
|
||||
syn match cmacroCommentError "\*/"
|
||||
syn region cmacroComment start='//' end='$' contains=cmacroTodo,@Spell
|
||||
|
||||
" Define the default highlighting.
|
||||
" Only used when an item doesn't have highlighting yet
|
||||
hi def link cmacroInclude Include
|
||||
hi def link cmacroPreProc PreProc
|
||||
hi def link cmacroDefine Macro
|
||||
hi def link cmacroIncluded cmacroString
|
||||
hi def link cmacroCppInWrapper cmacroCppOutWrapper
|
||||
hi def link cmacroCppOutWrapper cmacroPreCondit
|
||||
hi def link cmacroPreConditMatch cmacroPreCondit
|
||||
hi def link cmacroPreCondit PreCondit
|
||||
hi def link cmacroCppOutSkip cmacroCppOutIf2
|
||||
hi def link cmacroCppInElse2 cmacroCppOutIf2
|
||||
hi def link cmacroCppOutIf2 cmacroCppOut
|
||||
hi def link cmacroCppOut Comment
|
||||
hi def link cmacroTodo Todo
|
||||
hi def link cmacroComment Comment
|
||||
hi def link cmacroCommentError Error
|
||||
|
||||
let b:current_syntax = "cmacro"
|
||||
|
||||
let &cpo = s:cpo_save
|
||||
unlet s:cpo_save
|
40
runtime/syntax/lnk.vim
Normal file
40
runtime/syntax/lnk.vim
Normal file
@@ -0,0 +1,40 @@
|
||||
" Vim syntax file
|
||||
" Language: TI linker command file
|
||||
" Document: https://downloads.ti.com/docs/esd/SPRUI03A/Content/SPRUI03A_HTML/linker_description.html
|
||||
" Document: https://software-dl.ti.com/ccs/esd/documents/sdto_cgt_Linker-Command-File-Primer.html
|
||||
" Maintainer: Wu, Zhenyu <wuzhenyu@ustc.edu>
|
||||
" Last Change: 2024 Dec 31
|
||||
|
||||
if exists("b:current_syntax")
|
||||
finish
|
||||
endif
|
||||
|
||||
runtime! syntax/cmacro.vim
|
||||
|
||||
syn case ignore
|
||||
syn match lnkNumber "0x[0-9a-f]\+"
|
||||
" Linker command files are ASCII files that contain one or more of the following:
|
||||
" Input filenames, which specify object files, archive libraries, or other command files.
|
||||
" Linker options, which can be used in the command file in the same manner that they are used on the command line
|
||||
syn match lnkOption "^[-+][-_a-zA-Z#@]\+"
|
||||
syn match lnkOption "^--[^ \t$=`'"|);]\+"
|
||||
syn match lnkFile '[^ =]\+\%(\.\S\+\)\+\>'
|
||||
syn match lnkLibFile '[^ =]\+\.lib\>'
|
||||
" The MEMORY and SECTIONS linker directives. The MEMORY directive defines the target memory configuration (see Section 8.5.4). The SECTIONS directive controls how sections are built and allocated (see Section 8.5.5.)
|
||||
syn keyword lnkKeyword ADDRESS_MASK f LOAD ORIGIN START ALGORITHM FILL LOAD_END PAGE TABLE ALIGN GROUP LOAD_SIZE PALIGN TYPE ATTR HAMMING_MASK LOAD_START PARITY_MASK UNION BLOCK HIGH MEMORY RUN UNORDERED COMPRESSION INPUT_PAGE MIRRORING RUN_END VFILL COPY INPUT_RANGE NOINIT RUN_SIZE DSECT l NOLOAD RUN_START ECC LEN o SECTIONS END LENGTH ORG SIZE
|
||||
syn region lnkLibrary start=+<+ end=+>+
|
||||
syn match lnkAttrib '\<[RWXI]\+\>'
|
||||
syn match lnkSections '\<\.\k\+'
|
||||
" Assignment statements, which define and assign values to global symbols
|
||||
syn case match
|
||||
|
||||
hi def link lnkNumber Number
|
||||
hi def link lnkOption Special
|
||||
hi def link lnkKeyword Keyword
|
||||
hi def link lnkLibrary String
|
||||
hi def link lnkFile String
|
||||
hi def link lnkLibFile Special
|
||||
hi def link lnkAttrib Type
|
||||
hi def link lnkSections Macro
|
||||
|
||||
let b:current_syntax = "lnk"
|
@@ -2300,6 +2300,27 @@ func Test_cls_file()
|
||||
filetype off
|
||||
endfunc
|
||||
|
||||
func Test_cmd_file()
|
||||
filetype on
|
||||
|
||||
call writefile(['--rom_model'], 'Xfile.cmd')
|
||||
split Xfile.cmd
|
||||
call assert_equal('lnk', &filetype)
|
||||
bwipe!
|
||||
|
||||
call writefile(['/* comment */'], 'Xfile.cmd')
|
||||
split Xfile.cmd
|
||||
call assert_equal('rexx', &filetype)
|
||||
bwipe!
|
||||
|
||||
call writefile(['REM comment'], 'Xfile.cmd')
|
||||
split Xfile.cmd
|
||||
call assert_equal('dosbatch', &filetype)
|
||||
bwipe!
|
||||
|
||||
filetype off
|
||||
endfunc
|
||||
|
||||
func Test_sig_file()
|
||||
filetype on
|
||||
|
||||
|
Reference in New Issue
Block a user