blob: 73f283a4a76c2c1e0ff22156c150bc818ab42dd8 [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>
6" Contributors: Ori Avtalion, Lakshay Garg
7" Last Change: 2020 Oct 31
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"
35
Bram Moolenaar071d4272004-06-13 20:20:40 +000036syn match asmIdentifier "[a-z_][a-z0-9_]*"
Bram Moolenaar3132cdd2020-11-05 20:41:49 +010037syn match asmLabel "[a-z_][a-z0-9_]*:"he=e-1
Bram Moolenaar071d4272004-06-13 20:20:40 +000038
39" Various #'s as defined by GAS ref manual sec 3.6.2.1
Bram Moolenaar3132cdd2020-11-05 20:41:49 +010040" Technically, the first asmDecimal def is actually octal,
Bram Moolenaar071d4272004-06-13 20:20:40 +000041" since the value of 0-7 octal is the same as 0-7 decimal,
Bram Moolenaar6ee8d892012-01-10 14:55:01 +010042" I (Kevin) prefer to map it as decimal:
Bram Moolenaar3132cdd2020-11-05 20:41:49 +010043syn match asmDecimal "\<0\+[1-7]\=\>" display
44syn match asmDecimal "\<[1-9]\d*\>" display
45syn match asmOctal "\<0[0-7][0-7]\+\>" display
46syn match asmHexadecimal "\<0[xX][0-9a-fA-F]\+\>" display
47syn match asmBinary "\<0[bB][0-1]\+\>" display
Bram Moolenaar071d4272004-06-13 20:20:40 +000048
Bram Moolenaar3132cdd2020-11-05 20:41:49 +010049syn match asmFloat "\<\d\+\.\d*\%(e[+-]\=\d\+\)\=\>" display
50syn match asmFloat "\.\d\+\%(e[+-]\=\d\+\)\=\>" display
51syn match asmFloat "\<\d\%(e[+-]\=\d\+\)\>" display
52syn match asmFloat "[+-]\=Inf\>\|\<NaN\>" display
Bram Moolenaar00a927d2010-05-14 23:24:24 +020053
Bram Moolenaar3132cdd2020-11-05 20:41:49 +010054syn match asmFloat "\%(0[edfghprs]\)[+-]\=\d*\%(\.\d\+\)\%(e[+-]\=\d\+\)\=" display
55syn match asmFloat "\%(0[edfghprs]\)[+-]\=\d\+\%(\.\d\+\)\=\%(e[+-]\=\d\+\)\=" display
56" Avoid fighting the hexadecimal match for unicorn-like '0x' prefixed floats
57syn match asmFloat "\%(0x\)[+-]\=\d*\%(\.\d\+\)\%(e[+-]\=\d\+\)\=" display
58
59" Allow all characters to be escaped (and in strings) as these vary across
60" architectures [See sec 3.6.1.1 Strings]
61syn match asmCharacterEscape "\\." contained
62syn match asmCharacter "'\\\=." contains=asmCharacterEscape
63
64syn match asmStringEscape "\\\_." contained
65syn match asmStringEscape "\\\%(\o\{3}\|00[89]\)" contained display
66syn match asmStringEscape "\\x\x\+" contained display
67
68syn region asmString start="\"" end="\"" skip="\\\\\|\\\"" contains=asmStringEscape
69
70syn keyword asmTodo contained TODO FIXME XXX NOTE
Bram Moolenaar6ee8d892012-01-10 14:55:01 +010071
72" GAS supports one type of multi line comments:
Bram Moolenaar3132cdd2020-11-05 20:41:49 +010073syn region asmComment start="/\*" end="\*/" contains=asmTodo,@Spell
Bram Moolenaar6ee8d892012-01-10 14:55:01 +010074
Bram Moolenaar53bfca22012-04-13 23:04:47 +020075" GAS (undocumentedly?) supports C++ style comments. Unlike in C/C++ however,
76" a backslash ending a C++ style comment does not extend the comment to the
77" next line (hence the syntax region does not define 'skip="\\$"')
Bram Moolenaar3132cdd2020-11-05 20:41:49 +010078syn region asmComment start="//" end="$" keepend contains=asmTodo,@Spell
Bram Moolenaar53bfca22012-04-13 23:04:47 +020079
Bram Moolenaar6ee8d892012-01-10 14:55:01 +010080" Line comment characters depend on the target architecture and command line
81" options and some comments may double as logical line number directives or
82" preprocessor commands. This situation is described at
83" http://sourceware.org/binutils/docs-2.22/as/Comments.html
84" Some line comment characters have other meanings for other targets. For
85" example, .type directives may use the `@' character which is also an ARM
86" comment marker.
87" As a compromise to accommodate what I arbitrarily assume to be the most
88" frequently used features of the most popular architectures (and also the
89" non-GNU assembly languages that use this syntax file because their asm files
90" are also named *.asm), the following are used as line comment characters:
Bram Moolenaar3132cdd2020-11-05 20:41:49 +010091syn match asmComment "[#;!|].*" contains=asmTodo,@Spell
Bram Moolenaar6ee8d892012-01-10 14:55:01 +010092
93" Side effects of this include:
94" - When `;' is used to separate statements on the same line (many targets
95" support this), all statements except the first get highlighted as
96" comments. As a remedy, remove `;' from the above.
97" - ARM comments are not highlighted correctly. For ARM, uncomment the
98" following two lines and comment the one above.
99"syn match asmComment "@.*" contains=asmTodo
100"syn match asmComment "^#.*" contains=asmTodo
101
102" Advanced users of specific architectures will probably want to change the
103" comment highlighting or use a specific, more comprehensive syntax file.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000104
105syn match asmInclude "\.include"
106syn match asmCond "\.if"
107syn match asmCond "\.else"
108syn match asmCond "\.endif"
109syn match asmMacro "\.macro"
110syn match asmMacro "\.endm"
111
Bram Moolenaar92dff182014-02-11 19:15:50 +0100112" Assembler directives start with a '.' and may contain upper case (e.g.,
113" .ABORT), numbers (e.g., .p2align), dash (e.g., .app-file) and underscore in
114" CFI directives (e.g., .cfi_startproc). This will also match labels starting
115" with '.', including the GCC auto-generated '.L' labels.
116syn match asmDirective "\.[A-Za-z][0-9A-Za-z-_]*"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000117
Bram Moolenaar071d4272004-06-13 20:20:40 +0000118syn case match
119
120" Define the default highlighting.
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200121" Only when an item doesn't have highlighting yet
Bram Moolenaar071d4272004-06-13 20:20:40 +0000122
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200123" The default methods for highlighting. Can be overridden later
Bram Moolenaar3132cdd2020-11-05 20:41:49 +0100124hi def link asmSection Special
125hi def link asmLabel Label
126hi def link asmComment Comment
127hi def link asmTodo Todo
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200128hi def link asmDirective Statement
Bram Moolenaar071d4272004-06-13 20:20:40 +0000129
Bram Moolenaar3132cdd2020-11-05 20:41:49 +0100130hi def link asmInclude Include
131hi def link asmCond PreCondit
132hi def link asmMacro Macro
Bram Moolenaar071d4272004-06-13 20:20:40 +0000133
Bram Moolenaar3132cdd2020-11-05 20:41:49 +0100134if exists('g:asm_legacy_syntax_groups')
135 hi def link hexNumber Number
136 hi def link decNumber Number
137 hi def link octNumber Number
138 hi def link binNumber Number
139 hi def link asmHexadecimal hexNumber
140 hi def link asmDecimal decNumber
141 hi def link asmOctal octNumber
142 hi def link asmBinary binNumber
143else
144 hi def link asmHexadecimal Number
145 hi def link asmDecimal Number
146 hi def link asmOctal Number
147 hi def link asmBinary Number
148endif
149hi def link asmFloat Float
150
151hi def link asmString String
152hi def link asmStringEscape Special
153hi def link asmCharacter Character
154hi def link asmCharacterEscape Special
Bram Moolenaar071d4272004-06-13 20:20:40 +0000155
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200156hi def link asmIdentifier Identifier
Bram Moolenaar3132cdd2020-11-05 20:41:49 +0100157hi def link asmType Type
Bram Moolenaar071d4272004-06-13 20:20:40 +0000158
159let b:current_syntax = "asm"
160
Bram Moolenaar6ee8d892012-01-10 14:55:01 +0100161let &cpo = s:cpo_save
162unlet s:cpo_save
163
Bram Moolenaar3132cdd2020-11-05 20:41:49 +0100164" vim: nowrap sw=2 sts=2 ts=8 noet