blob: 18f3de1c63bf6a7d2774f7fc5eb7bc1537096237 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim syntax file
Bram Moolenaar3132cdd2020-11-05 20:41:49 +01002" 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>
Nir Lichtmandb234362025-01-26 16:55:54 +01006" Contributors: Ori Avtalion, Lakshay Garg, Nir Lichtman
7" Last Change: 2025 Jan 26
Bram Moolenaar071d4272004-06-13 20:20:40 +00008
Bram Moolenaar89bcfda2016-08-30 23:26:57 +02009" quit when a syntax file was already loaded
10if exists("b:current_syntax")
Bram Moolenaar071d4272004-06-13 20:20:40 +000011 finish
12endif
13
Bram Moolenaar6ee8d892012-01-10 14:55:01 +010014let s:cpo_save = &cpo
15set cpo&vim
16
Bram Moolenaar071d4272004-06-13 20:20:40 +000017syn case ignore
18
Bram Moolenaar071d4272004-06-13 20:20:40 +000019" 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"
Nir Lichtmandb234362025-01-26 16:55:54 +010035syn match asmType "\.2byte"
36syn match asmType "\.4byte"
37syn match asmType "\.8byte"
Bram Moolenaar071d4272004-06-13 20:20:40 +000038
Bram Moolenaar071d4272004-06-13 20:20:40 +000039syn match asmIdentifier "[a-z_][a-z0-9_]*"
Bram Moolenaar3132cdd2020-11-05 20:41:49 +010040syn match asmLabel "[a-z_][a-z0-9_]*:"he=e-1
Bram Moolenaar071d4272004-06-13 20:20:40 +000041
42" Various #'s as defined by GAS ref manual sec 3.6.2.1
Bram Moolenaar3132cdd2020-11-05 20:41:49 +010043" Technically, the first asmDecimal def is actually octal,
Bram Moolenaar071d4272004-06-13 20:20:40 +000044" since the value of 0-7 octal is the same as 0-7 decimal,
Bram Moolenaar6ee8d892012-01-10 14:55:01 +010045" I (Kevin) prefer to map it as decimal:
Bram Moolenaar3132cdd2020-11-05 20:41:49 +010046syn 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
Bram Moolenaar071d4272004-06-13 20:20:40 +000051
Bram Moolenaar3132cdd2020-11-05 20:41:49 +010052syn 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
Bram Moolenaar00a927d2010-05-14 23:24:24 +020056
Bram Moolenaar3132cdd2020-11-05 20:41:49 +010057syn 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
Bram Moolenaar6ee8d892012-01-10 14:55:01 +010074
75" GAS supports one type of multi line comments:
Bram Moolenaar3132cdd2020-11-05 20:41:49 +010076syn region asmComment start="/\*" end="\*/" contains=asmTodo,@Spell
Bram Moolenaar6ee8d892012-01-10 14:55:01 +010077
Bram Moolenaar53bfca22012-04-13 23:04:47 +020078" 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="\\$"')
Bram Moolenaar3132cdd2020-11-05 20:41:49 +010081syn region asmComment start="//" end="$" keepend contains=asmTodo,@Spell
Bram Moolenaar53bfca22012-04-13 23:04:47 +020082
Bram Moolenaar6ee8d892012-01-10 14:55:01 +010083" 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:
Bram Moolenaar3132cdd2020-11-05 20:41:49 +010094syn match asmComment "[#;!|].*" contains=asmTodo,@Spell
Bram Moolenaar6ee8d892012-01-10 14:55:01 +010095
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.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000107
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
Bram Moolenaar92dff182014-02-11 19:15:50 +0100115" 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-_]*"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000120
Bram Moolenaar071d4272004-06-13 20:20:40 +0000121syn case match
122
123" Define the default highlighting.
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200124" Only when an item doesn't have highlighting yet
Bram Moolenaar071d4272004-06-13 20:20:40 +0000125
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200126" The default methods for highlighting. Can be overridden later
Bram Moolenaar3132cdd2020-11-05 20:41:49 +0100127hi def link asmSection Special
128hi def link asmLabel Label
129hi def link asmComment Comment
130hi def link asmTodo Todo
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200131hi def link asmDirective Statement
Bram Moolenaar071d4272004-06-13 20:20:40 +0000132
Bram Moolenaar3132cdd2020-11-05 20:41:49 +0100133hi def link asmInclude Include
134hi def link asmCond PreCondit
135hi def link asmMacro Macro
Bram Moolenaar071d4272004-06-13 20:20:40 +0000136
Bram Moolenaar3132cdd2020-11-05 20:41:49 +0100137if 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
Bram Moolenaar071d4272004-06-13 20:20:40 +0000158
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200159hi def link asmIdentifier Identifier
Bram Moolenaar3132cdd2020-11-05 20:41:49 +0100160hi def link asmType Type
Bram Moolenaar071d4272004-06-13 20:20:40 +0000161
162let b:current_syntax = "asm"
163
Bram Moolenaar6ee8d892012-01-10 14:55:01 +0100164let &cpo = s:cpo_save
165unlet s:cpo_save
166
Bram Moolenaar3132cdd2020-11-05 20:41:49 +0100167" vim: nowrap sw=2 sts=2 ts=8 noet