asm.vim (6135B)
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 10 if exists("b:current_syntax") 11 finish 12 endif 13 14 let s:cpo_save = &cpo 15 set cpo&vim 16 17 syn case ignore 18 19 " storage types 20 syn match asmType "\.long" 21 syn match asmType "\.ascii" 22 syn match asmType "\.asciz" 23 syn match asmType "\.byte" 24 syn match asmType "\.double" 25 syn match asmType "\.float" 26 syn match asmType "\.hword" 27 syn match asmType "\.int" 28 syn match asmType "\.octa" 29 syn match asmType "\.quad" 30 syn match asmType "\.short" 31 syn match asmType "\.single" 32 syn match asmType "\.space" 33 syn match asmType "\.string" 34 syn match asmType "\.word" 35 syn match asmType "\.2byte" 36 syn match asmType "\.4byte" 37 syn match asmType "\.8byte" 38 39 syn match asmIdentifier "[a-z_][a-z0-9_]*" 40 syn 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: 46 syn match asmDecimal "\<0\+[1-7]\=\>" display 47 syn match asmDecimal "\<[1-9]\d*\>" display 48 syn match asmOctal "\<0[0-7][0-7]\+\>" display 49 syn match asmHexadecimal "\<0[xX][0-9a-fA-F]\+\>" display 50 syn match asmBinary "\<0[bB][0-1]\+\>" display 51 52 syn match asmFloat "\<\d\+\.\d*\%(e[+-]\=\d\+\)\=\>" display 53 syn match asmFloat "\.\d\+\%(e[+-]\=\d\+\)\=\>" display 54 syn match asmFloat "\<\d\%(e[+-]\=\d\+\)\>" display 55 syn match asmFloat "[+-]\=Inf\>\|\<NaN\>" display 56 57 syn match asmFloat "\%(0[edfghprs]\)[+-]\=\d*\%(\.\d\+\)\%(e[+-]\=\d\+\)\=" display 58 syn match asmFloat "\%(0[edfghprs]\)[+-]\=\d\+\%(\.\d\+\)\=\%(e[+-]\=\d\+\)\=" display 59 " Avoid fighting the hexadecimal match for unicorn-like '0x' prefixed floats 60 syn 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] 64 syn match asmCharacterEscape "\\." contained 65 syn match asmCharacter "'\\\=." contains=asmCharacterEscape 66 67 syn match asmStringEscape "\\\_." contained 68 syn match asmStringEscape "\\\%(\o\{3}\|00[89]\)" contained display 69 syn match asmStringEscape "\\x\x\+" contained display 70 71 syn region asmString start="\"" end="\"" skip="\\\\\|\\\"" contains=asmStringEscape 72 73 syn keyword asmTodo contained TODO FIXME XXX NOTE 74 75 " GAS supports one type of multi line comments: 76 syn 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="\\$"') 81 syn 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: 94 syn 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 108 syn match asmInclude "\.include" 109 syn match asmCond "\.if" 110 syn match asmCond "\.else" 111 syn match asmCond "\.endif" 112 syn match asmMacro "\.macro" 113 syn 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. 119 syn match asmDirective "\.[A-Za-z][0-9A-Za-z-_]*" 120 121 syn 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 127 hi def link asmSection Special 128 hi def link asmLabel Label 129 hi def link asmComment Comment 130 hi def link asmTodo Todo 131 hi def link asmDirective Statement 132 133 hi def link asmInclude Include 134 hi def link asmCond PreCondit 135 hi def link asmMacro Macro 136 137 if 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 146 else 147 hi def link asmHexadecimal Number 148 hi def link asmDecimal Number 149 hi def link asmOctal Number 150 hi def link asmBinary Number 151 endif 152 hi def link asmFloat Float 153 154 hi def link asmString String 155 hi def link asmStringEscape Special 156 hi def link asmCharacter Character 157 hi def link asmCharacterEscape Special 158 159 hi def link asmIdentifier Identifier 160 hi def link asmType Type 161 162 let b:current_syntax = "asm" 163 164 let &cpo = s:cpo_save 165 unlet s:cpo_save 166 167 " vim: nowrap sw=2 sts=2 ts=8 noet