xref: /vim-8.2.3635/runtime/syntax/asm.vim (revision 3132cddd)
1071d4279SBram Moolenaar" Vim syntax file
2071d4279SBram Moolenaar" Language:		GNU Assembler
3*3132cdddSBram Moolenaar" Maintainer:		Doug Kearns [email protected]
4*3132cdddSBram Moolenaar" Previous Maintainers: Erik Wognsen <[email protected]>
5555cdc2fSBram Moolenaar"			Kevin Dahlhausen <[email protected]>
6*3132cdddSBram Moolenaar" Contributors:		Ori Avtalion, Lakshay Garg
7*3132cdddSBram Moolenaar" Last Change:		2020 Oct 31
8071d4279SBram Moolenaar
989bcfda6SBram Moolenaar" quit when a syntax file was already loaded
1089bcfda6SBram Moolenaarif exists("b:current_syntax")
11071d4279SBram Moolenaar  finish
12071d4279SBram Moolenaarendif
13071d4279SBram Moolenaar
146ee8d89cSBram Moolenaarlet s:cpo_save = &cpo
156ee8d89cSBram Moolenaarset cpo&vim
166ee8d89cSBram Moolenaar
17071d4279SBram Moolenaarsyn case ignore
18071d4279SBram Moolenaar
19071d4279SBram Moolenaar" storage types
20071d4279SBram Moolenaarsyn match asmType "\.long"
21071d4279SBram Moolenaarsyn match asmType "\.ascii"
22071d4279SBram Moolenaarsyn match asmType "\.asciz"
23071d4279SBram Moolenaarsyn match asmType "\.byte"
24071d4279SBram Moolenaarsyn match asmType "\.double"
25071d4279SBram Moolenaarsyn match asmType "\.float"
26071d4279SBram Moolenaarsyn match asmType "\.hword"
27071d4279SBram Moolenaarsyn match asmType "\.int"
28071d4279SBram Moolenaarsyn match asmType "\.octa"
29071d4279SBram Moolenaarsyn match asmType "\.quad"
30071d4279SBram Moolenaarsyn match asmType "\.short"
31071d4279SBram Moolenaarsyn match asmType "\.single"
32071d4279SBram Moolenaarsyn match asmType "\.space"
33071d4279SBram Moolenaarsyn match asmType "\.string"
34071d4279SBram Moolenaarsyn match asmType "\.word"
35071d4279SBram Moolenaar
36071d4279SBram Moolenaarsyn match asmIdentifier		"[a-z_][a-z0-9_]*"
37*3132cdddSBram Moolenaarsyn match asmLabel		"[a-z_][a-z0-9_]*:"he=e-1
38071d4279SBram Moolenaar
39071d4279SBram Moolenaar" Various #'s as defined by GAS ref manual sec 3.6.2.1
40*3132cdddSBram Moolenaar" Technically, the first asmDecimal def is actually octal,
41071d4279SBram Moolenaar" since the value of 0-7 octal is the same as 0-7 decimal,
426ee8d89cSBram Moolenaar" I (Kevin) prefer to map it as decimal:
43*3132cdddSBram Moolenaarsyn match asmDecimal		"\<0\+[1-7]\=\>"	 display
44*3132cdddSBram Moolenaarsyn match asmDecimal		"\<[1-9]\d*\>"		 display
45*3132cdddSBram Moolenaarsyn match asmOctal		"\<0[0-7][0-7]\+\>"	 display
46*3132cdddSBram Moolenaarsyn match asmHexadecimal	"\<0[xX][0-9a-fA-F]\+\>" display
47*3132cdddSBram Moolenaarsyn match asmBinary		"\<0[bB][0-1]\+\>"	 display
48071d4279SBram Moolenaar
49*3132cdddSBram Moolenaarsyn match asmFloat		"\<\d\+\.\d*\%(e[+-]\=\d\+\)\=\>" display
50*3132cdddSBram Moolenaarsyn match asmFloat		"\.\d\+\%(e[+-]\=\d\+\)\=\>"	  display
51*3132cdddSBram Moolenaarsyn match asmFloat		"\<\d\%(e[+-]\=\d\+\)\>"	  display
52*3132cdddSBram Moolenaarsyn match asmFloat		"[+-]\=Inf\>\|\<NaN\>"		  display
5300a927d6SBram Moolenaar
54*3132cdddSBram Moolenaarsyn match asmFloat		"\%(0[edfghprs]\)[+-]\=\d*\%(\.\d\+\)\%(e[+-]\=\d\+\)\="    display
55*3132cdddSBram Moolenaarsyn match asmFloat		"\%(0[edfghprs]\)[+-]\=\d\+\%(\.\d\+\)\=\%(e[+-]\=\d\+\)\=" display
56*3132cdddSBram Moolenaar" Avoid fighting the hexadecimal match for unicorn-like '0x' prefixed floats
57*3132cdddSBram Moolenaarsyn match asmFloat		"\%(0x\)[+-]\=\d*\%(\.\d\+\)\%(e[+-]\=\d\+\)\="		    display
58*3132cdddSBram Moolenaar
59*3132cdddSBram Moolenaar" Allow all characters to be escaped (and in strings) as these vary across
60*3132cdddSBram Moolenaar" architectures [See sec 3.6.1.1 Strings]
61*3132cdddSBram Moolenaarsyn match asmCharacterEscape	"\\."    contained
62*3132cdddSBram Moolenaarsyn match asmCharacter		"'\\\=." contains=asmCharacterEscape
63*3132cdddSBram Moolenaar
64*3132cdddSBram Moolenaarsyn match asmStringEscape	"\\\_."			contained
65*3132cdddSBram Moolenaarsyn match asmStringEscape	"\\\%(\o\{3}\|00[89]\)"	contained display
66*3132cdddSBram Moolenaarsyn match asmStringEscape	"\\x\x\+"		contained display
67*3132cdddSBram Moolenaar
68*3132cdddSBram Moolenaarsyn region asmString		start="\"" end="\"" skip="\\\\\|\\\"" contains=asmStringEscape
69*3132cdddSBram Moolenaar
70*3132cdddSBram Moolenaarsyn keyword asmTodo		contained TODO FIXME XXX NOTE
716ee8d89cSBram Moolenaar
726ee8d89cSBram Moolenaar" GAS supports one type of multi line comments:
73*3132cdddSBram Moolenaarsyn region asmComment		start="/\*" end="\*/" contains=asmTodo,@Spell
746ee8d89cSBram Moolenaar
7553bfca22SBram Moolenaar" GAS (undocumentedly?) supports C++ style comments. Unlike in C/C++ however,
7653bfca22SBram Moolenaar" a backslash ending a C++ style comment does not extend the comment to the
7753bfca22SBram Moolenaar" next line (hence the syntax region does not define 'skip="\\$"')
78*3132cdddSBram Moolenaarsyn region asmComment		start="//" end="$" keepend contains=asmTodo,@Spell
7953bfca22SBram Moolenaar
806ee8d89cSBram Moolenaar" Line comment characters depend on the target architecture and command line
816ee8d89cSBram Moolenaar" options and some comments may double as logical line number directives or
826ee8d89cSBram Moolenaar" preprocessor commands. This situation is described at
836ee8d89cSBram Moolenaar" http://sourceware.org/binutils/docs-2.22/as/Comments.html
846ee8d89cSBram Moolenaar" Some line comment characters have other meanings for other targets. For
856ee8d89cSBram Moolenaar" example, .type directives may use the `@' character which is also an ARM
866ee8d89cSBram Moolenaar" comment marker.
876ee8d89cSBram Moolenaar" As a compromise to accommodate what I arbitrarily assume to be the most
886ee8d89cSBram Moolenaar" frequently used features of the most popular architectures (and also the
896ee8d89cSBram Moolenaar" non-GNU assembly languages that use this syntax file because their asm files
906ee8d89cSBram Moolenaar" are also named *.asm), the following are used as line comment characters:
91*3132cdddSBram Moolenaarsyn match asmComment		"[#;!|].*" contains=asmTodo,@Spell
926ee8d89cSBram Moolenaar
936ee8d89cSBram Moolenaar" Side effects of this include:
946ee8d89cSBram Moolenaar" - When `;' is used to separate statements on the same line (many targets
956ee8d89cSBram Moolenaar"   support this), all statements except the first get highlighted as
966ee8d89cSBram Moolenaar"   comments. As a remedy, remove `;' from the above.
976ee8d89cSBram Moolenaar" - ARM comments are not highlighted correctly. For ARM, uncomment the
986ee8d89cSBram Moolenaar"   following two lines and comment the one above.
9900a927d6SBram Moolenaar"syn match asmComment		"@.*" contains=asmTodo
1006ee8d89cSBram Moolenaar"syn match asmComment		"^#.*" contains=asmTodo
1016ee8d89cSBram Moolenaar
1026ee8d89cSBram Moolenaar" Advanced users of specific architectures will probably want to change the
1036ee8d89cSBram Moolenaar" comment highlighting or use a specific, more comprehensive syntax file.
104071d4279SBram Moolenaar
105071d4279SBram Moolenaarsyn match asmInclude		"\.include"
106071d4279SBram Moolenaarsyn match asmCond		"\.if"
107071d4279SBram Moolenaarsyn match asmCond		"\.else"
108071d4279SBram Moolenaarsyn match asmCond		"\.endif"
109071d4279SBram Moolenaarsyn match asmMacro		"\.macro"
110071d4279SBram Moolenaarsyn match asmMacro		"\.endm"
111071d4279SBram Moolenaar
11292dff182SBram Moolenaar" Assembler directives start with a '.' and may contain upper case (e.g.,
11392dff182SBram Moolenaar" .ABORT), numbers (e.g., .p2align), dash (e.g., .app-file) and underscore in
11492dff182SBram Moolenaar" CFI directives (e.g., .cfi_startproc). This will also match labels starting
11592dff182SBram Moolenaar" with '.', including the GCC auto-generated '.L' labels.
11692dff182SBram Moolenaarsyn match asmDirective		"\.[A-Za-z][0-9A-Za-z-_]*"
117071d4279SBram Moolenaar
118071d4279SBram Moolenaarsyn case match
119071d4279SBram Moolenaar
120071d4279SBram Moolenaar" Define the default highlighting.
12189bcfda6SBram Moolenaar" Only when an item doesn't have highlighting yet
122071d4279SBram Moolenaar
123071d4279SBram Moolenaar" The default methods for highlighting.  Can be overridden later
124f37506f6SBram Moolenaarhi def link asmSection		Special
125f37506f6SBram Moolenaarhi def link asmLabel		Label
126f37506f6SBram Moolenaarhi def link asmComment		Comment
127f37506f6SBram Moolenaarhi def link asmTodo		Todo
128f37506f6SBram Moolenaarhi def link asmDirective	Statement
129071d4279SBram Moolenaar
130f37506f6SBram Moolenaarhi def link asmInclude		Include
131f37506f6SBram Moolenaarhi def link asmCond		PreCondit
132f37506f6SBram Moolenaarhi def link asmMacro		Macro
133071d4279SBram Moolenaar
134*3132cdddSBram Moolenaarif exists('g:asm_legacy_syntax_groups')
135f37506f6SBram Moolenaar  hi def link hexNumber		Number
136f37506f6SBram Moolenaar  hi def link decNumber		Number
137f37506f6SBram Moolenaar  hi def link octNumber		Number
138f37506f6SBram Moolenaar  hi def link binNumber		Number
139*3132cdddSBram Moolenaar  hi def link asmHexadecimal	hexNumber
140*3132cdddSBram Moolenaar  hi def link asmDecimal	decNumber
141*3132cdddSBram Moolenaar  hi def link asmOctal		octNumber
142*3132cdddSBram Moolenaar  hi def link asmBinary		binNumber
143*3132cdddSBram Moolenaarelse
144*3132cdddSBram Moolenaar  hi def link asmHexadecimal	Number
145*3132cdddSBram Moolenaar  hi def link asmDecimal	Number
146*3132cdddSBram Moolenaar  hi def link asmOctal		Number
147*3132cdddSBram Moolenaar  hi def link asmBinary		Number
148*3132cdddSBram Moolenaarendif
149*3132cdddSBram Moolenaarhi def link asmFloat		Float
150*3132cdddSBram Moolenaar
151*3132cdddSBram Moolenaarhi def link asmString		String
152*3132cdddSBram Moolenaarhi def link asmStringEscape	Special
153*3132cdddSBram Moolenaarhi def link asmCharacter	Character
154*3132cdddSBram Moolenaarhi def link asmCharacterEscape	Special
155071d4279SBram Moolenaar
156f37506f6SBram Moolenaarhi def link asmIdentifier	Identifier
157f37506f6SBram Moolenaarhi def link asmType		Type
158071d4279SBram Moolenaar
159071d4279SBram Moolenaarlet b:current_syntax = "asm"
160071d4279SBram Moolenaar
1616ee8d89cSBram Moolenaarlet &cpo = s:cpo_save
1626ee8d89cSBram Moolenaarunlet s:cpo_save
1636ee8d89cSBram Moolenaar
164*3132cdddSBram Moolenaar" vim: nowrap sw=2 sts=2 ts=8 noet
165