blob: 0ce8d23994ae661aa712d7d59c31a1ede7476d75 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim syntax file
2" Language: GNU Assembler
Bram Moolenaar555cdc22010-01-12 21:31:21 +01003" Maintainer: Erik Wognsen <erik.wognsen@gmail.com>
4" Previous maintainer:
5" Kevin Dahlhausen <kdahlhaus@yahoo.com>
Bram Moolenaar6ee8d892012-01-10 14:55:01 +01006" Last Change: 2012 Jan 5
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007
8" Thanks to Ori Avtalion for feedback on the comment markers!
Bram Moolenaar071d4272004-06-13 20:20:40 +00009
10" For version 5.x: Clear all syntax items
Bram Moolenaar555cdc22010-01-12 21:31:21 +010011" For version 6.0 and later: Quit when a syntax file was already loaded
Bram Moolenaar071d4272004-06-13 20:20:40 +000012if version < 600
13 syntax clear
14elseif exists("b:current_syntax")
15 finish
16endif
17
Bram Moolenaar6ee8d892012-01-10 14:55:01 +010018let s:cpo_save = &cpo
19set cpo&vim
20
Bram Moolenaar071d4272004-06-13 20:20:40 +000021syn case ignore
22
Bram Moolenaar071d4272004-06-13 20:20:40 +000023" storage types
24syn match asmType "\.long"
25syn match asmType "\.ascii"
26syn match asmType "\.asciz"
27syn match asmType "\.byte"
28syn match asmType "\.double"
29syn match asmType "\.float"
30syn match asmType "\.hword"
31syn match asmType "\.int"
32syn match asmType "\.octa"
33syn match asmType "\.quad"
34syn match asmType "\.short"
35syn match asmType "\.single"
36syn match asmType "\.space"
37syn match asmType "\.string"
38syn match asmType "\.word"
39
40syn match asmLabel "[a-z_][a-z0-9_]*:"he=e-1
41syn match asmIdentifier "[a-z_][a-z0-9_]*"
42
43" Various #'s as defined by GAS ref manual sec 3.6.2.1
44" Technically, the first decNumber def is actually octal,
45" since the value of 0-7 octal is the same as 0-7 decimal,
Bram Moolenaar6ee8d892012-01-10 14:55:01 +010046" I (Kevin) prefer to map it as decimal:
Bram Moolenaar071d4272004-06-13 20:20:40 +000047syn match decNumber "0\+[1-7]\=[\t\n$,; ]"
48syn match decNumber "[1-9]\d*"
49syn match octNumber "0[0-7][0-7]\+"
50syn match hexNumber "0[xX][0-9a-fA-F]\+"
51syn match binNumber "0[bB][0-1]*"
52
Bram Moolenaar00a927d2010-05-14 23:24:24 +020053syn keyword asmTodo contained TODO
54
Bram Moolenaar6ee8d892012-01-10 14:55:01 +010055
56" GAS supports one type of multi line comments:
Bram Moolenaar00a927d2010-05-14 23:24:24 +020057syn region asmComment start="/\*" end="\*/" contains=asmTodo
Bram Moolenaar6ee8d892012-01-10 14:55:01 +010058
59" Line comment characters depend on the target architecture and command line
60" options and some comments may double as logical line number directives or
61" preprocessor commands. This situation is described at
62" http://sourceware.org/binutils/docs-2.22/as/Comments.html
63" Some line comment characters have other meanings for other targets. For
64" example, .type directives may use the `@' character which is also an ARM
65" comment marker.
66" As a compromise to accommodate what I arbitrarily assume to be the most
67" frequently used features of the most popular architectures (and also the
68" non-GNU assembly languages that use this syntax file because their asm files
69" are also named *.asm), the following are used as line comment characters:
Bram Moolenaar00a927d2010-05-14 23:24:24 +020070syn match asmComment "[#;!|].*" contains=asmTodo
Bram Moolenaar6ee8d892012-01-10 14:55:01 +010071
72" Side effects of this include:
73" - When `;' is used to separate statements on the same line (many targets
74" support this), all statements except the first get highlighted as
75" comments. As a remedy, remove `;' from the above.
76" - ARM comments are not highlighted correctly. For ARM, uncomment the
77" following two lines and comment the one above.
78"syn match asmComment "@.*" contains=asmTodo
79"syn match asmComment "^#.*" contains=asmTodo
80
81" Advanced users of specific architectures will probably want to change the
82" comment highlighting or use a specific, more comprehensive syntax file.
Bram Moolenaar071d4272004-06-13 20:20:40 +000083
84syn match asmInclude "\.include"
85syn match asmCond "\.if"
86syn match asmCond "\.else"
87syn match asmCond "\.endif"
88syn match asmMacro "\.macro"
89syn match asmMacro "\.endm"
90
91syn match asmDirective "\.[a-z][a-z]\+"
92
93
94syn case match
95
96" Define the default highlighting.
97" For version 5.7 and earlier: only when not done already
98" For version 5.8 and later: only when an item doesn't have highlighting yet
99if version >= 508 || !exists("did_asm_syntax_inits")
100 if version < 508
101 let did_asm_syntax_inits = 1
102 command -nargs=+ HiLink hi link <args>
103 else
104 command -nargs=+ HiLink hi def link <args>
105 endif
106
107 " The default methods for highlighting. Can be overridden later
108 HiLink asmSection Special
109 HiLink asmLabel Label
110 HiLink asmComment Comment
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200111 HiLink asmTodo Todo
Bram Moolenaar071d4272004-06-13 20:20:40 +0000112 HiLink asmDirective Statement
113
114 HiLink asmInclude Include
115 HiLink asmCond PreCondit
116 HiLink asmMacro Macro
117
118 HiLink hexNumber Number
119 HiLink decNumber Number
120 HiLink octNumber Number
121 HiLink binNumber Number
122
Bram Moolenaar6ee8d892012-01-10 14:55:01 +0100123 HiLink asmIdentifier Identifier
Bram Moolenaar071d4272004-06-13 20:20:40 +0000124 HiLink asmType Type
125
Bram Moolenaar071d4272004-06-13 20:20:40 +0000126 delcommand HiLink
127endif
128
129let b:current_syntax = "asm"
130
Bram Moolenaar6ee8d892012-01-10 14:55:01 +0100131let &cpo = s:cpo_save
132unlet s:cpo_save
133
Bram Moolenaar071d4272004-06-13 20:20:40 +0000134" vim: ts=8