Skip to content

Commit 4f73c07

Browse files
Freed-Wuchrisbra
authored andcommitted
patch 9.1.0998: filetype: TI assembly files are not recognized
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: #15827 Signed-off-by: Wu, Zhenyu <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent a21240b commit 4f73c07

File tree

7 files changed

+156
-5
lines changed

7 files changed

+156
-5
lines changed

.github/MAINTAINERS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ runtime/ftplugin/tcsh.vim @dkearns
292292
runtime/ftplugin/terraform.vim @JannoTjarks
293293
runtime/ftplugin/tf.vim @ribru17
294294
runtime/ftplugin/thrift.vim @jiangyinzuo
295+
runtime/ftplugin/tiasm.vim @Freed-Wu
295296
runtime/ftplugin/tidy.vim @dkearns
296297
runtime/ftplugin/tmux.vim @ericpruitt
297298
runtime/ftplugin/toml.vim @averms
@@ -610,6 +611,7 @@ runtime/syntax/tcsh.vim @dkearns
610611
runtime/syntax/teraterm.vim @k-takata
611612
runtime/syntax/terraform.vim @gpanders
612613
runtime/syntax/thrift.vim @jiangyinzuo
614+
runtime/syntax/tiasm.vim @Freed-Wu
613615
runtime/syntax/tidy.vim @dkearns
614616
runtime/syntax/tmux.vim @ericpruitt
615617
runtime/syntax/toml.vim @averms

runtime/autoload/dist/ft.vim

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ vim9script
33
# Vim functions for file type detection
44
#
55
# Maintainer: The Vim Project <https://github.com/vim/vim>
6-
# Last Change: 2024 May 23
6+
# Last Change: 2025 Jan 08
77
# Former Maintainer: Bram Moolenaar <[email protected]>
88

99
# These functions are moved here from runtime/filetype.vim to make startup
@@ -32,6 +32,10 @@ enddef
3232
# This function checks for the kind of assembly that is wanted by the user, or
3333
# can be detected from the first five lines of the file.
3434
export def FTasm()
35+
# tiasm uses `* commment`
36+
if join(getline(1, 10), "\n") =~ '\%(\%(^\|\n\)\*\|Texas Instruments Incorporated\)'
37+
setf tiasm
38+
endif
3539
# make sure b:asmsyntax exists
3640
if !exists("b:asmsyntax")
3741
b:asmsyntax = ""
@@ -1003,6 +1007,14 @@ export def SQL()
10031007
endif
10041008
enddef
10051009

1010+
export def FTsa()
1011+
if join(getline(1, 4), "\n") =~# '\%(^\|\n\);'
1012+
setf tiasm
1013+
return
1014+
endif
1015+
setf sather
1016+
enddef
1017+
10061018
# This function checks the first 25 lines of file extension "sc" to resolve
10071019
# detection between scala and SuperCollider.
10081020
# NOTE: We don't check for 'Class : Method', as this can easily be confused

runtime/filetype.vim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
" Vim support file to detect file types
22
"
33
" Maintainer: The Vim Project <https://github.com/vim/vim>
4-
" Last Change: 2024 Dec 31
4+
" Last Change: 2025 Jan 08
55
" Former Maintainer: Bram Moolenaar <[email protected]>
66

77
" Listen very carefully, I will say this only once
@@ -2200,8 +2200,8 @@ au BufNewFile,BufRead *.sas setf sas
22002200
" Sass
22012201
au BufNewFile,BufRead *.sass setf sass
22022202

2203-
" Sather
2204-
au BufNewFile,BufRead *.sa setf sather
2203+
" Sather, TI linear assembly
2204+
au BufNewFile,BufRead *.sa call dist#ft#FTsa()
22052205

22062206
" Scala
22072207
au BufNewFile,BufRead *.scala setf scala

runtime/ftplugin/tiasm.vim

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
" Vim filetype plugin file
2+
" Language: TI linear assembly language
3+
" Maintainer: Wu, Zhenyu <[email protected]>
4+
" Last Change: 2025 Jan 08
5+
6+
if exists("b:did_ftplugin") | finish | endif
7+
let b:did_ftplugin = 1
8+
9+
setlocal comments=:;
10+
setlocal commentstring=;\ %s
11+
12+
let b:undo_ftplugin = "setl commentstring< comments<"
13+
14+
if exists("loaded_matchit")
15+
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'
16+
let b:match_ignorecase = 1
17+
let b:undo_ftplugin ..= " | unlet! b:match_ignorecase b:match_words"
18+
endif

runtime/syntax/tiasm.vim

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
" Vim syntax file
2+
" Language: TI linear assembly language
3+
" Document: https://downloads.ti.com/docs/esd/SPRUI03B/#SPRUI03B_HTML/assembler-description.html
4+
" Maintainer: Wu, Zhenyu <[email protected]>
5+
" Last Change: 2025 Jan 08
6+
7+
if exists("b:current_syntax")
8+
finish
9+
endif
10+
11+
syn case ignore
12+
13+
" storage types
14+
syn match tiasmType "\.bits"
15+
syn match tiasmType "\.byte"
16+
syn match tiasmType "\.char"
17+
syn match tiasmType "\.cstring"
18+
syn match tiasmType "\.double"
19+
syn match tiasmType "\.field"
20+
syn match tiasmType "\.float"
21+
syn match tiasmType "\.half"
22+
syn match tiasmType "\.int"
23+
syn match tiasmType "\.long"
24+
syn match tiasmType "\.short"
25+
syn match tiasmType "\.string"
26+
syn match tiasmType "\.ubyte"
27+
syn match tiasmType "\.uchar"
28+
syn match tiasmType "\.uhalf"
29+
syn match tiasmType "\.uint"
30+
syn match tiasmType "\.ulong"
31+
syn match tiasmType "\.ushort"
32+
syn match tiasmType "\.uword"
33+
syn match tiasmType "\.word"
34+
35+
syn match tiasmIdentifier "[a-z_][a-z0-9_]*"
36+
37+
syn match tiasmDecimal "\<[1-9]\d*\>" display
38+
syn match tiasmOctal "\<0[0-7][0-7]\+\>\|\<[0-7]\+[oO]\>" display
39+
syn match tiasmHexadecimal "\<0[xX][0-9a-fA-F]\+\>\|\<[0-9][0-9a-fA-F]*[hH]\>" display
40+
syn match tiasmBinary "\<0[bB][0-1]\+\>\|\<[01]\+[bB]\>" display
41+
42+
syn match tiasmFloat "\<\d\+\.\d*\%(e[+-]\=\d\+\)\=\>" display
43+
syn match tiasmFloat "\<\d\%(e[+-]\=\d\+\)\>" display
44+
45+
syn match tiasmCharacter "'.'\|''\|'[^']'"
46+
47+
syn region tiasmString start="\"" end="\"" skip="\"\""
48+
49+
syn match tiasmFunction "\$[a-zA-Z_][a-zA-Z_0-9]*\ze("
50+
51+
syn keyword tiasmTodo contained TODO FIXME XXX NOTE
52+
syn region tiasmComment start=";" end="$" keepend contains=tiasmTodo,@Spell
53+
syn match tiasmComment "^[*!].*" contains=tiasmTodo,@Spell
54+
syn match tiasmLabel "^[^ *!;][^ :]*"
55+
56+
syn match tiasmInclude "\.include"
57+
syn match tiasmCond "\.if"
58+
syn match tiasmCond "\.else"
59+
syn match tiasmCond "\.endif"
60+
syn match tiasmMacro "\.macro"
61+
syn match tiasmMacro "\.endm"
62+
63+
syn match tiasmDirective "\.[A-Za-z][0-9A-Za-z-_]*"
64+
65+
syn case match
66+
67+
hi def link tiasmLabel Label
68+
hi def link tiasmComment Comment
69+
hi def link tiasmTodo Todo
70+
hi def link tiasmDirective Statement
71+
72+
hi def link tiasmInclude Include
73+
hi def link tiasmCond PreCondit
74+
hi def link tiasmMacro Macro
75+
76+
if exists('g:tiasm_legacy_syntax_groups')
77+
hi def link hexNumber Number
78+
hi def link decNumber Number
79+
hi def link octNumber Number
80+
hi def link binNumber Number
81+
hi def link tiasmHexadecimal hexNumber
82+
hi def link tiasmDecimal decNumber
83+
hi def link tiasmOctal octNumber
84+
hi def link tiasmBinary binNumber
85+
else
86+
hi def link tiasmHexadecimal Number
87+
hi def link tiasmDecimal Number
88+
hi def link tiasmOctal Number
89+
hi def link tiasmBinary Number
90+
endif
91+
hi def link tiasmFloat Float
92+
93+
hi def link tiasmString String
94+
hi def link tiasmStringEscape Special
95+
hi def link tiasmCharacter Character
96+
hi def link tiasmCharacterEscape Special
97+
98+
hi def link tiasmIdentifier Identifier
99+
hi def link tiasmType Type
100+
hi def link tiasmFunction Function
101+
102+
let b:current_syntax = "lineartiasm"

src/testdir/test_filetype.vim

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,6 @@ def s:GetFilenameChecks(): dict<list<string>>
676676
samba: ['smb.conf'],
677677
sas: ['file.sas'],
678678
sass: ['file.sass'],
679-
sather: ['file.sa'],
680679
sbt: ['file.sbt'],
681680
scala: ['file.scala'],
682681
scheme: ['file.scm', 'file.ss', 'file.sld', 'file.stsg', 'any/local/share/supertux2/config', '.lips_repl_history'],
@@ -2331,6 +2330,22 @@ func Test_cmd_file()
23312330
filetype off
23322331
endfunc
23332332

2333+
func Test_sa_file()
2334+
filetype on
2335+
2336+
call writefile([';* XXX-a.sa: XXX for TI C6000 DSP *;', '.no_mdep'], 'Xfile.sa')
2337+
split Xfile.sa
2338+
call assert_equal('tiasm', &filetype)
2339+
bwipe!
2340+
2341+
call writefile(['-- comment'], 'Xfile.sa')
2342+
split Xfile.sa
2343+
call assert_equal('sather', &filetype)
2344+
bwipe!
2345+
2346+
filetype off
2347+
endfunc
2348+
23342349
func Test_sig_file()
23352350
filetype on
23362351

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,8 @@ static char *(features[]) =
704704

705705
static int included_patches[] =
706706
{ /* Add new patch number below this line */
707+
/**/
708+
998,
707709
/**/
708710
997,
709711
/**/

0 commit comments

Comments
 (0)