robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Christian Clasonvim-patch:db23436: runtime(asm): add byte directives to syntax script21aed725d2

master
6.0 KiB167 linesraw
1" Vim syntax file
2" Language:		GNU Assembler
3" Maintainer:		Doug Kearns dougkearns@gmail.com
4" Previous Maintainers: Erik Wognsen <erik.wognsen@gmail.com>
5"			Kevin Dahlhausen <kdahlhaus@yahoo.com>
6" Contributors:		Ori Avtalion, Lakshay Garg, Nir Lichtman
7" Last Change:		2025 Jan 26
8
9" quit when a syntax file was already loaded
10if exists("b:current_syntax")
11  finish
12endif
13
14let s:cpo_save = &cpo
15set cpo&vim
16
17syn case ignore
18
19" storage types
20syn match asmType "\.long"
21syn match asmType "\.ascii"
22syn match asmType "\.asciz"
23syn match asmType "\.byte"
24syn match asmType "\.double"
25syn match asmType "\.float"
26syn match asmType "\.hword"
27syn match asmType "\.int"
28syn match asmType "\.octa"
29syn match asmType "\.quad"
30syn match asmType "\.short"
31syn match asmType "\.single"
32syn match asmType "\.space"
33syn match asmType "\.string"
34syn match asmType "\.word"
35syn match asmType "\.2byte"
36syn match asmType "\.4byte"
37syn match asmType "\.8byte"
38
39syn match asmIdentifier		"[a-z_][a-z0-9_]*"
40syn match asmLabel		"[a-z_][a-z0-9_]*:"he=e-1
41
42" Various #'s as defined by GAS ref manual sec 3.6.2.1
43" Technically, the first asmDecimal def is actually octal,
44" since the value of 0-7 octal is the same as 0-7 decimal,
45" I (Kevin) prefer to map it as decimal:
46syn match asmDecimal		"\<0\+[1-7]\=\>"	 display
47syn match asmDecimal		"\<[1-9]\d*\>"		 display
48syn match asmOctal		"\<0[0-7][0-7]\+\>"	 display
49syn match asmHexadecimal	"\<0[xX][0-9a-fA-F]\+\>" display
50syn match asmBinary		"\<0[bB][0-1]\+\>"	 display
51
52syn match asmFloat		"\<\d\+\.\d*\%(e[+-]\=\d\+\)\=\>" display
53syn match asmFloat		"\.\d\+\%(e[+-]\=\d\+\)\=\>"	  display
54syn match asmFloat		"\<\d\%(e[+-]\=\d\+\)\>"	  display
55syn match asmFloat		"[+-]\=Inf\>\|\<NaN\>"		  display
56
57syn match asmFloat		"\%(0[edfghprs]\)[+-]\=\d*\%(\.\d\+\)\%(e[+-]\=\d\+\)\="    display
58syn match asmFloat		"\%(0[edfghprs]\)[+-]\=\d\+\%(\.\d\+\)\=\%(e[+-]\=\d\+\)\=" display
59" Avoid fighting the hexadecimal match for unicorn-like '0x' prefixed floats
60syn match asmFloat		"\%(0x\)[+-]\=\d*\%(\.\d\+\)\%(e[+-]\=\d\+\)\="		    display
61
62" Allow all characters to be escaped (and in strings) as these vary across
63" architectures [See sec 3.6.1.1 Strings]
64syn match asmCharacterEscape	"\\."    contained
65syn match asmCharacter		"'\\\=." contains=asmCharacterEscape
66
67syn match asmStringEscape	"\\\_."			contained
68syn match asmStringEscape	"\\\%(\o\{3}\|00[89]\)"	contained display
69syn match asmStringEscape	"\\x\x\+"		contained display
70
71syn region asmString		start="\"" end="\"" skip="\\\\\|\\\"" contains=asmStringEscape
72
73syn keyword asmTodo		contained TODO FIXME XXX NOTE
74
75" GAS supports one type of multi line comments:
76syn region asmComment		start="/\*" end="\*/" contains=asmTodo,@Spell
77
78" GAS (undocumentedly?) supports C++ style comments. Unlike in C/C++ however,
79" a backslash ending a C++ style comment does not extend the comment to the
80" next line (hence the syntax region does not define 'skip="\\$"')
81syn region asmComment		start="//" end="$" keepend contains=asmTodo,@Spell
82
83" Line comment characters depend on the target architecture and command line
84" options and some comments may double as logical line number directives or
85" preprocessor commands. This situation is described at
86" http://sourceware.org/binutils/docs-2.22/as/Comments.html
87" Some line comment characters have other meanings for other targets. For
88" example, .type directives may use the `@' character which is also an ARM
89" comment marker.
90" As a compromise to accommodate what I arbitrarily assume to be the most
91" frequently used features of the most popular architectures (and also the
92" non-GNU assembly languages that use this syntax file because their asm files
93" are also named *.asm), the following are used as line comment characters:
94syn match asmComment		"[#;!|].*" contains=asmTodo,@Spell
95
96" Side effects of this include:
97" - When `;' is used to separate statements on the same line (many targets
98"   support this), all statements except the first get highlighted as
99"   comments. As a remedy, remove `;' from the above.
100" - ARM comments are not highlighted correctly. For ARM, uncomment the
101"   following two lines and comment the one above.
102"syn match asmComment		"@.*" contains=asmTodo
103"syn match asmComment		"^#.*" contains=asmTodo
104
105" Advanced users of specific architectures will probably want to change the
106" comment highlighting or use a specific, more comprehensive syntax file.
107
108syn match asmInclude		"\.include"
109syn match asmCond		"\.if"
110syn match asmCond		"\.else"
111syn match asmCond		"\.endif"
112syn match asmMacro		"\.macro"
113syn match asmMacro		"\.endm"
114
115" Assembler directives start with a '.' and may contain upper case (e.g.,
116" .ABORT), numbers (e.g., .p2align), dash (e.g., .app-file) and underscore in
117" CFI directives (e.g., .cfi_startproc). This will also match labels starting
118" with '.', including the GCC auto-generated '.L' labels.
119syn match asmDirective		"\.[A-Za-z][0-9A-Za-z-_]*"
120
121syn case match
122
123" Define the default highlighting.
124" Only when an item doesn't have highlighting yet
125
126" The default methods for highlighting.  Can be overridden later
127hi def link asmSection		Special
128hi def link asmLabel		Label
129hi def link asmComment		Comment
130hi def link asmTodo		Todo
131hi def link asmDirective	Statement
132
133hi def link asmInclude		Include
134hi def link asmCond		PreCondit
135hi def link asmMacro		Macro
136
137if exists('g:asm_legacy_syntax_groups')
138  hi def link hexNumber		Number
139  hi def link decNumber		Number
140  hi def link octNumber		Number
141  hi def link binNumber		Number
142  hi def link asmHexadecimal	hexNumber
143  hi def link asmDecimal	decNumber
144  hi def link asmOctal		octNumber
145  hi def link asmBinary		binNumber
146else
147  hi def link asmHexadecimal	Number
148  hi def link asmDecimal	Number
149  hi def link asmOctal		Number
150  hi def link asmBinary		Number
151endif
152hi def link asmFloat		Float
153
154hi def link asmString		String
155hi def link asmStringEscape	Special
156hi def link asmCharacter	Character
157hi def link asmCharacterEscape	Special
158
159hi def link asmIdentifier	Identifier
160hi def link asmType		Type
161
162let b:current_syntax = "asm"
163
164let &cpo = s:cpo_save
165unlet s:cpo_save
166
167" vim: nowrap sw=2 sts=2 ts=8 noet