Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | " Vim syntax file |
Bram Moolenaar | 3132cdd | 2020-11-05 20:41:49 +0100 | [diff] [blame] | 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> |
Nir Lichtman | db23436 | 2025-01-26 16:55:54 +0100 | [diff] [blame] | 6 | " Contributors: Ori Avtalion, Lakshay Garg, Nir Lichtman |
| 7 | " Last Change: 2025 Jan 26 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8 | |
Bram Moolenaar | 89bcfda | 2016-08-30 23:26:57 +0200 | [diff] [blame] | 9 | " quit when a syntax file was already loaded |
| 10 | if exists("b:current_syntax") |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 11 | finish |
| 12 | endif |
| 13 | |
Bram Moolenaar | 6ee8d89 | 2012-01-10 14:55:01 +0100 | [diff] [blame] | 14 | let s:cpo_save = &cpo |
| 15 | set cpo&vim |
| 16 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 17 | syn case ignore |
| 18 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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" |
Nir Lichtman | db23436 | 2025-01-26 16:55:54 +0100 | [diff] [blame] | 35 | syn match asmType "\.2byte" |
| 36 | syn match asmType "\.4byte" |
| 37 | syn match asmType "\.8byte" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 38 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 39 | syn match asmIdentifier "[a-z_][a-z0-9_]*" |
Bram Moolenaar | 3132cdd | 2020-11-05 20:41:49 +0100 | [diff] [blame] | 40 | syn match asmLabel "[a-z_][a-z0-9_]*:"he=e-1 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 41 | |
| 42 | " Various #'s as defined by GAS ref manual sec 3.6.2.1 |
Bram Moolenaar | 3132cdd | 2020-11-05 20:41:49 +0100 | [diff] [blame] | 43 | " Technically, the first asmDecimal def is actually octal, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 44 | " since the value of 0-7 octal is the same as 0-7 decimal, |
Bram Moolenaar | 6ee8d89 | 2012-01-10 14:55:01 +0100 | [diff] [blame] | 45 | " I (Kevin) prefer to map it as decimal: |
Bram Moolenaar | 3132cdd | 2020-11-05 20:41:49 +0100 | [diff] [blame] | 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 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 51 | |
Bram Moolenaar | 3132cdd | 2020-11-05 20:41:49 +0100 | [diff] [blame] | 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 |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 56 | |
Bram Moolenaar | 3132cdd | 2020-11-05 20:41:49 +0100 | [diff] [blame] | 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 |
Bram Moolenaar | 6ee8d89 | 2012-01-10 14:55:01 +0100 | [diff] [blame] | 74 | |
| 75 | " GAS supports one type of multi line comments: |
Bram Moolenaar | 3132cdd | 2020-11-05 20:41:49 +0100 | [diff] [blame] | 76 | syn region asmComment start="/\*" end="\*/" contains=asmTodo,@Spell |
Bram Moolenaar | 6ee8d89 | 2012-01-10 14:55:01 +0100 | [diff] [blame] | 77 | |
Bram Moolenaar | 53bfca2 | 2012-04-13 23:04:47 +0200 | [diff] [blame] | 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="\\$"') |
Bram Moolenaar | 3132cdd | 2020-11-05 20:41:49 +0100 | [diff] [blame] | 81 | syn region asmComment start="//" end="$" keepend contains=asmTodo,@Spell |
Bram Moolenaar | 53bfca2 | 2012-04-13 23:04:47 +0200 | [diff] [blame] | 82 | |
Bram Moolenaar | 6ee8d89 | 2012-01-10 14:55:01 +0100 | [diff] [blame] | 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: |
Bram Moolenaar | 3132cdd | 2020-11-05 20:41:49 +0100 | [diff] [blame] | 94 | syn match asmComment "[#;!|].*" contains=asmTodo,@Spell |
Bram Moolenaar | 6ee8d89 | 2012-01-10 14:55:01 +0100 | [diff] [blame] | 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. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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 | |
Bram Moolenaar | 92dff18 | 2014-02-11 19:15:50 +0100 | [diff] [blame] | 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-_]*" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 120 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 121 | syn case match |
| 122 | |
| 123 | " Define the default highlighting. |
Bram Moolenaar | 89bcfda | 2016-08-30 23:26:57 +0200 | [diff] [blame] | 124 | " Only when an item doesn't have highlighting yet |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 125 | |
Bram Moolenaar | 89bcfda | 2016-08-30 23:26:57 +0200 | [diff] [blame] | 126 | " The default methods for highlighting. Can be overridden later |
Bram Moolenaar | 3132cdd | 2020-11-05 20:41:49 +0100 | [diff] [blame] | 127 | hi def link asmSection Special |
| 128 | hi def link asmLabel Label |
| 129 | hi def link asmComment Comment |
| 130 | hi def link asmTodo Todo |
Bram Moolenaar | f37506f | 2016-08-31 22:22:10 +0200 | [diff] [blame] | 131 | hi def link asmDirective Statement |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 132 | |
Bram Moolenaar | 3132cdd | 2020-11-05 20:41:49 +0100 | [diff] [blame] | 133 | hi def link asmInclude Include |
| 134 | hi def link asmCond PreCondit |
| 135 | hi def link asmMacro Macro |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 136 | |
Bram Moolenaar | 3132cdd | 2020-11-05 20:41:49 +0100 | [diff] [blame] | 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 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 158 | |
Bram Moolenaar | f37506f | 2016-08-31 22:22:10 +0200 | [diff] [blame] | 159 | hi def link asmIdentifier Identifier |
Bram Moolenaar | 3132cdd | 2020-11-05 20:41:49 +0100 | [diff] [blame] | 160 | hi def link asmType Type |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 161 | |
| 162 | let b:current_syntax = "asm" |
| 163 | |
Bram Moolenaar | 6ee8d89 | 2012-01-10 14:55:01 +0100 | [diff] [blame] | 164 | let &cpo = s:cpo_save |
| 165 | unlet s:cpo_save |
| 166 | |
Bram Moolenaar | 3132cdd | 2020-11-05 20:41:49 +0100 | [diff] [blame] | 167 | " vim: nowrap sw=2 sts=2 ts=8 noet |