Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | " Vim syntax file |
| 2 | " Language: GNU Assembler |
Bram Moolenaar | 555cdc2 | 2010-01-12 21:31:21 +0100 | [diff] [blame] | 3 | " Maintainer: Erik Wognsen <erik.wognsen@gmail.com> |
| 4 | " Previous maintainer: |
| 5 | " Kevin Dahlhausen <kdahlhaus@yahoo.com> |
Bram Moolenaar | 92dff18 | 2014-02-11 19:15:50 +0100 | [diff] [blame] | 6 | " Last Change: 2014 Feb 04 |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 7 | |
| 8 | " Thanks to Ori Avtalion for feedback on the comment markers! |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9 | |
| 10 | " For version 5.x: Clear all syntax items |
Bram Moolenaar | 555cdc2 | 2010-01-12 21:31:21 +0100 | [diff] [blame] | 11 | " For version 6.0 and later: Quit when a syntax file was already loaded |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 12 | if version < 600 |
| 13 | syntax clear |
| 14 | elseif exists("b:current_syntax") |
| 15 | finish |
| 16 | endif |
| 17 | |
Bram Moolenaar | 6ee8d89 | 2012-01-10 14:55:01 +0100 | [diff] [blame] | 18 | let s:cpo_save = &cpo |
| 19 | set cpo&vim |
| 20 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 21 | syn case ignore |
| 22 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 23 | " storage types |
| 24 | syn match asmType "\.long" |
| 25 | syn match asmType "\.ascii" |
| 26 | syn match asmType "\.asciz" |
| 27 | syn match asmType "\.byte" |
| 28 | syn match asmType "\.double" |
| 29 | syn match asmType "\.float" |
| 30 | syn match asmType "\.hword" |
| 31 | syn match asmType "\.int" |
| 32 | syn match asmType "\.octa" |
| 33 | syn match asmType "\.quad" |
| 34 | syn match asmType "\.short" |
| 35 | syn match asmType "\.single" |
| 36 | syn match asmType "\.space" |
| 37 | syn match asmType "\.string" |
| 38 | syn match asmType "\.word" |
| 39 | |
| 40 | syn match asmLabel "[a-z_][a-z0-9_]*:"he=e-1 |
| 41 | syn 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 Moolenaar | 6ee8d89 | 2012-01-10 14:55:01 +0100 | [diff] [blame] | 46 | " I (Kevin) prefer to map it as decimal: |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 47 | syn match decNumber "0\+[1-7]\=[\t\n$,; ]" |
| 48 | syn match decNumber "[1-9]\d*" |
| 49 | syn match octNumber "0[0-7][0-7]\+" |
| 50 | syn match hexNumber "0[xX][0-9a-fA-F]\+" |
| 51 | syn match binNumber "0[bB][0-1]*" |
| 52 | |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 53 | syn keyword asmTodo contained TODO |
| 54 | |
Bram Moolenaar | 6ee8d89 | 2012-01-10 14:55:01 +0100 | [diff] [blame] | 55 | |
| 56 | " GAS supports one type of multi line comments: |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 57 | syn region asmComment start="/\*" end="\*/" contains=asmTodo |
Bram Moolenaar | 6ee8d89 | 2012-01-10 14:55:01 +0100 | [diff] [blame] | 58 | |
Bram Moolenaar | 53bfca2 | 2012-04-13 23:04:47 +0200 | [diff] [blame] | 59 | " GAS (undocumentedly?) supports C++ style comments. Unlike in C/C++ however, |
| 60 | " a backslash ending a C++ style comment does not extend the comment to the |
| 61 | " next line (hence the syntax region does not define 'skip="\\$"') |
| 62 | syn region asmComment start="//" end="$" keepend contains=asmTodo |
| 63 | |
Bram Moolenaar | 6ee8d89 | 2012-01-10 14:55:01 +0100 | [diff] [blame] | 64 | " Line comment characters depend on the target architecture and command line |
| 65 | " options and some comments may double as logical line number directives or |
| 66 | " preprocessor commands. This situation is described at |
| 67 | " http://sourceware.org/binutils/docs-2.22/as/Comments.html |
| 68 | " Some line comment characters have other meanings for other targets. For |
| 69 | " example, .type directives may use the `@' character which is also an ARM |
| 70 | " comment marker. |
| 71 | " As a compromise to accommodate what I arbitrarily assume to be the most |
| 72 | " frequently used features of the most popular architectures (and also the |
| 73 | " non-GNU assembly languages that use this syntax file because their asm files |
| 74 | " are also named *.asm), the following are used as line comment characters: |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 75 | syn match asmComment "[#;!|].*" contains=asmTodo |
Bram Moolenaar | 6ee8d89 | 2012-01-10 14:55:01 +0100 | [diff] [blame] | 76 | |
| 77 | " Side effects of this include: |
| 78 | " - When `;' is used to separate statements on the same line (many targets |
| 79 | " support this), all statements except the first get highlighted as |
| 80 | " comments. As a remedy, remove `;' from the above. |
| 81 | " - ARM comments are not highlighted correctly. For ARM, uncomment the |
| 82 | " following two lines and comment the one above. |
| 83 | "syn match asmComment "@.*" contains=asmTodo |
| 84 | "syn match asmComment "^#.*" contains=asmTodo |
| 85 | |
| 86 | " Advanced users of specific architectures will probably want to change the |
| 87 | " comment highlighting or use a specific, more comprehensive syntax file. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 88 | |
| 89 | syn match asmInclude "\.include" |
| 90 | syn match asmCond "\.if" |
| 91 | syn match asmCond "\.else" |
| 92 | syn match asmCond "\.endif" |
| 93 | syn match asmMacro "\.macro" |
| 94 | syn match asmMacro "\.endm" |
| 95 | |
Bram Moolenaar | 92dff18 | 2014-02-11 19:15:50 +0100 | [diff] [blame] | 96 | " Assembler directives start with a '.' and may contain upper case (e.g., |
| 97 | " .ABORT), numbers (e.g., .p2align), dash (e.g., .app-file) and underscore in |
| 98 | " CFI directives (e.g., .cfi_startproc). This will also match labels starting |
| 99 | " with '.', including the GCC auto-generated '.L' labels. |
| 100 | syn match asmDirective "\.[A-Za-z][0-9A-Za-z-_]*" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 101 | |
| 102 | |
| 103 | syn case match |
| 104 | |
| 105 | " Define the default highlighting. |
| 106 | " For version 5.7 and earlier: only when not done already |
| 107 | " For version 5.8 and later: only when an item doesn't have highlighting yet |
| 108 | if version >= 508 || !exists("did_asm_syntax_inits") |
| 109 | if version < 508 |
| 110 | let did_asm_syntax_inits = 1 |
| 111 | command -nargs=+ HiLink hi link <args> |
| 112 | else |
| 113 | command -nargs=+ HiLink hi def link <args> |
| 114 | endif |
| 115 | |
| 116 | " The default methods for highlighting. Can be overridden later |
| 117 | HiLink asmSection Special |
| 118 | HiLink asmLabel Label |
| 119 | HiLink asmComment Comment |
Bram Moolenaar | 00a927d | 2010-05-14 23:24:24 +0200 | [diff] [blame] | 120 | HiLink asmTodo Todo |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 121 | HiLink asmDirective Statement |
| 122 | |
| 123 | HiLink asmInclude Include |
| 124 | HiLink asmCond PreCondit |
| 125 | HiLink asmMacro Macro |
| 126 | |
| 127 | HiLink hexNumber Number |
| 128 | HiLink decNumber Number |
| 129 | HiLink octNumber Number |
| 130 | HiLink binNumber Number |
| 131 | |
Bram Moolenaar | 6ee8d89 | 2012-01-10 14:55:01 +0100 | [diff] [blame] | 132 | HiLink asmIdentifier Identifier |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 133 | HiLink asmType Type |
| 134 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 135 | delcommand HiLink |
| 136 | endif |
| 137 | |
| 138 | let b:current_syntax = "asm" |
| 139 | |
Bram Moolenaar | 6ee8d89 | 2012-01-10 14:55:01 +0100 | [diff] [blame] | 140 | let &cpo = s:cpo_save |
| 141 | unlet s:cpo_save |
| 142 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 143 | " vim: ts=8 |