aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2025-01-09 17:30:26 +0800
committerGitHub <noreply@github.com>2025-01-09 17:30:26 +0800
commit3f0adf90debb35b5a937480151a659d654106ff6 (patch)
tree831044a1cda13ab6a66456b284c150348ed8b487
parentd740a4274d9e1031e05dd86909103dba54fbbaf8 (diff)
downloadrneovim-3f0adf90debb35b5a937480151a659d654106ff6.tar.gz
rneovim-3f0adf90debb35b5a937480151a659d654106ff6.tar.bz2
rneovim-3f0adf90debb35b5a937480151a659d654106ff6.zip
vim-patch:9.1.0998: filetype: TI assembly files are not recognized (#31929)
Problem: filetype: TI assembly files are not recognized Solution: inspect '*.sa' and assembly files and detect TI assembly files, include filetype plugin and syntax script for TI assembly files (Wu, Zhenyu) closes: vim/vim#15827 https://github.com/vim/vim/commit/4f73c07abff420bad9fa5befc2c284c00b984993 Co-authored-by: Wu, Zhenyu <wuzhenyu@ustc.edu>
-rw-r--r--runtime/ftplugin/tiasm.vim18
-rw-r--r--runtime/lua/vim/filetype.lua2
-rw-r--r--runtime/lua/vim/filetype/detect.lua15
-rw-r--r--runtime/syntax/tiasm.vim102
-rw-r--r--test/old/testdir/test_filetype.vim17
5 files changed, 152 insertions, 2 deletions
diff --git a/runtime/ftplugin/tiasm.vim b/runtime/ftplugin/tiasm.vim
new file mode 100644
index 0000000000..13a3dc64f7
--- /dev/null
+++ b/runtime/ftplugin/tiasm.vim
@@ -0,0 +1,18 @@
+" Vim filetype plugin file
+" Language: TI linear assembly language
+" Maintainer: Wu, Zhenyu <wuzhenyu@ustc.edu>
+" Last Change: 2025 Jan 08
+
+if exists("b:did_ftplugin") | finish | endif
+let b:did_ftplugin = 1
+
+setlocal comments=:;
+setlocal commentstring=;\ %s
+
+let b:undo_ftplugin = "setl commentstring< comments<"
+
+if exists("loaded_matchit")
+ let b:match_words = '^\s\+\.if\>:^\s\+\.elseif:^\s\+\.else\>:^\s\+\.endif\>,^\s\+\.group:^\s\+\.gmember:^\s\+\.endgroup,^\s\+\.loop:^\s\+\.break:^\s\+\.endloop,^\s\+\.macro:^\s\+\.mexit:^\s\+\.endm,^\s\+\.asmfunc:^\s\+\.endasmfunc,^\s\+\.c\?struct:^\s\+\.endstruct,^\s\+\.c\?union:^\s\+\.endunion,^\s\+\.c\?proc:^\s\+\.return:^\s\+\.endproc'
+ let b:match_ignorecase = 1
+ let b:undo_ftplugin ..= " | unlet! b:match_ignorecase b:match_words"
+endif
diff --git a/runtime/lua/vim/filetype.lua b/runtime/lua/vim/filetype.lua
index 033a04cdc7..dee1bd88ca 100644
--- a/runtime/lua/vim/filetype.lua
+++ b/runtime/lua/vim/filetype.lua
@@ -1064,11 +1064,11 @@ local extension = {
builder = 'ruby',
rake = 'ruby',
rs = 'rust',
+ sa = detect.sa,
sage = 'sage',
sls = 'salt',
sas = 'sas',
sass = 'sass',
- sa = 'sather',
sbt = 'sbt',
scala = 'scala',
ss = 'scheme',
diff --git a/runtime/lua/vim/filetype/detect.lua b/runtime/lua/vim/filetype/detect.lua
index a1c17bc1af..2d989fdbac 100644
--- a/runtime/lua/vim/filetype/detect.lua
+++ b/runtime/lua/vim/filetype/detect.lua
@@ -34,6 +34,12 @@ local matchregex = vim.filetype._matchregex
-- can be detected from the first five lines of the file.
--- @type vim.filetype.mapfn
function M.asm(path, bufnr)
+ -- tiasm uses `* commment`
+ local lines = table.concat(getlines(bufnr, 1, 10), '\n')
+ if findany(lines, { '^%*', '\n%*', 'Texas Instruments Incorporated' }) then
+ return 'tiasm'
+ end
+
local syntax = vim.b[bufnr].asmsyntax
if not syntax or syntax == '' then
syntax = M.asm_syntax(path, bufnr)
@@ -1424,6 +1430,15 @@ function M.sig(_, bufnr)
end
end
+--- @type vim.filetype.mapfn
+function M.sa(_, bufnr)
+ local lines = table.concat(getlines(bufnr, 1, 4), '\n')
+ if findany(lines, { '^;', '\n;' }) then
+ return 'tiasm'
+ end
+ return 'sather'
+end
+
-- This function checks the first 25 lines of file extension "sc" to resolve
-- detection between scala and SuperCollider
--- @type vim.filetype.mapfn
diff --git a/runtime/syntax/tiasm.vim b/runtime/syntax/tiasm.vim
new file mode 100644
index 0000000000..bdadc4a0a7
--- /dev/null
+++ b/runtime/syntax/tiasm.vim
@@ -0,0 +1,102 @@
+" Vim syntax file
+" Language: TI linear assembly language
+" Document: https://downloads.ti.com/docs/esd/SPRUI03B/#SPRUI03B_HTML/assembler-description.html
+" Maintainer: Wu, Zhenyu <wuzhenyu@ustc.edu>
+" Last Change: 2025 Jan 08
+
+if exists("b:current_syntax")
+ finish
+endif
+
+syn case ignore
+
+" storage types
+syn match tiasmType "\.bits"
+syn match tiasmType "\.byte"
+syn match tiasmType "\.char"
+syn match tiasmType "\.cstring"
+syn match tiasmType "\.double"
+syn match tiasmType "\.field"
+syn match tiasmType "\.float"
+syn match tiasmType "\.half"
+syn match tiasmType "\.int"
+syn match tiasmType "\.long"
+syn match tiasmType "\.short"
+syn match tiasmType "\.string"
+syn match tiasmType "\.ubyte"
+syn match tiasmType "\.uchar"
+syn match tiasmType "\.uhalf"
+syn match tiasmType "\.uint"
+syn match tiasmType "\.ulong"
+syn match tiasmType "\.ushort"
+syn match tiasmType "\.uword"
+syn match tiasmType "\.word"
+
+syn match tiasmIdentifier "[a-z_][a-z0-9_]*"
+
+syn match tiasmDecimal "\<[1-9]\d*\>" display
+syn match tiasmOctal "\<0[0-7][0-7]\+\>\|\<[0-7]\+[oO]\>" display
+syn match tiasmHexadecimal "\<0[xX][0-9a-fA-F]\+\>\|\<[0-9][0-9a-fA-F]*[hH]\>" display
+syn match tiasmBinary "\<0[bB][0-1]\+\>\|\<[01]\+[bB]\>" display
+
+syn match tiasmFloat "\<\d\+\.\d*\%(e[+-]\=\d\+\)\=\>" display
+syn match tiasmFloat "\<\d\%(e[+-]\=\d\+\)\>" display
+
+syn match tiasmCharacter "'.'\|''\|'[^']'"
+
+syn region tiasmString start="\"" end="\"" skip="\"\""
+
+syn match tiasmFunction "\$[a-zA-Z_][a-zA-Z_0-9]*\ze("
+
+syn keyword tiasmTodo contained TODO FIXME XXX NOTE
+syn region tiasmComment start=";" end="$" keepend contains=tiasmTodo,@Spell
+syn match tiasmComment "^[*!].*" contains=tiasmTodo,@Spell
+syn match tiasmLabel "^[^ *!;][^ :]*"
+
+syn match tiasmInclude "\.include"
+syn match tiasmCond "\.if"
+syn match tiasmCond "\.else"
+syn match tiasmCond "\.endif"
+syn match tiasmMacro "\.macro"
+syn match tiasmMacro "\.endm"
+
+syn match tiasmDirective "\.[A-Za-z][0-9A-Za-z-_]*"
+
+syn case match
+
+hi def link tiasmLabel Label
+hi def link tiasmComment Comment
+hi def link tiasmTodo Todo
+hi def link tiasmDirective Statement
+
+hi def link tiasmInclude Include
+hi def link tiasmCond PreCondit
+hi def link tiasmMacro Macro
+
+if exists('g:tiasm_legacy_syntax_groups')
+ hi def link hexNumber Number
+ hi def link decNumber Number
+ hi def link octNumber Number
+ hi def link binNumber Number
+ hi def link tiasmHexadecimal hexNumber
+ hi def link tiasmDecimal decNumber
+ hi def link tiasmOctal octNumber
+ hi def link tiasmBinary binNumber
+else
+ hi def link tiasmHexadecimal Number
+ hi def link tiasmDecimal Number
+ hi def link tiasmOctal Number
+ hi def link tiasmBinary Number
+endif
+hi def link tiasmFloat Float
+
+hi def link tiasmString String
+hi def link tiasmStringEscape Special
+hi def link tiasmCharacter Character
+hi def link tiasmCharacterEscape Special
+
+hi def link tiasmIdentifier Identifier
+hi def link tiasmType Type
+hi def link tiasmFunction Function
+
+let b:current_syntax = "lineartiasm"
diff --git a/test/old/testdir/test_filetype.vim b/test/old/testdir/test_filetype.vim
index 6c8ab3a270..d890884eb5 100644
--- a/test/old/testdir/test_filetype.vim
+++ b/test/old/testdir/test_filetype.vim
@@ -672,7 +672,6 @@ func s:GetFilenameChecks() abort
\ 'samba': ['smb.conf'],
\ 'sas': ['file.sas'],
\ 'sass': ['file.sass'],
- \ 'sather': ['file.sa'],
\ 'sbt': ['file.sbt'],
\ 'scala': ['file.scala'],
\ 'scheme': ['file.scm', 'file.ss', 'file.sld', 'file.stsg', 'any/local/share/supertux2/config', '.lips_repl_history'],
@@ -2322,6 +2321,22 @@ func Test_cmd_file()
filetype off
endfunc
+func Test_sa_file()
+ filetype on
+
+ call writefile([';* XXX-a.sa: XXX for TI C6000 DSP *;', '.no_mdep'], 'Xfile.sa')
+ split Xfile.sa
+ call assert_equal('tiasm', &filetype)
+ bwipe!
+
+ call writefile(['-- comment'], 'Xfile.sa')
+ split Xfile.sa
+ call assert_equal('sather', &filetype)
+ bwipe!
+
+ filetype off
+endfunc
+
func Test_sig_file()
filetype on