asm.vim 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. " Vim syntax file
  2. " Language: GNU Assembler
  3. " Maintainer: Erik Wognsen <erik.wognsen@gmail.com>
  4. " Previous maintainer:
  5. " Kevin Dahlhausen <kdahlhaus@yahoo.com>
  6. " Last Change: 2014 Feb 04
  7. " Thanks to Ori Avtalion for feedback on the comment markers!
  8. " quit when a syntax file was already loaded
  9. if exists("b:current_syntax")
  10. finish
  11. endif
  12. let s:cpo_save = &cpo
  13. set cpo&vim
  14. syn case ignore
  15. " storage types
  16. syn match asmType "\.long"
  17. syn match asmType "\.ascii"
  18. syn match asmType "\.asciz"
  19. syn match asmType "\.byte"
  20. syn match asmType "\.double"
  21. syn match asmType "\.float"
  22. syn match asmType "\.hword"
  23. syn match asmType "\.int"
  24. syn match asmType "\.octa"
  25. syn match asmType "\.quad"
  26. syn match asmType "\.short"
  27. syn match asmType "\.single"
  28. syn match asmType "\.space"
  29. syn match asmType "\.string"
  30. syn match asmType "\.word"
  31. syn match asmLabel "[a-z_][a-z0-9_]*:"he=e-1
  32. syn match asmIdentifier "[a-z_][a-z0-9_]*"
  33. " Various #'s as defined by GAS ref manual sec 3.6.2.1
  34. " Technically, the first decNumber def is actually octal,
  35. " since the value of 0-7 octal is the same as 0-7 decimal,
  36. " I (Kevin) prefer to map it as decimal:
  37. syn match decNumber "0\+[1-7]\=[\t\n$,; ]"
  38. syn match decNumber "[1-9]\d*"
  39. syn match octNumber "0[0-7][0-7]\+"
  40. syn match hexNumber "0[xX][0-9a-fA-F]\+"
  41. syn match binNumber "0[bB][0-1]*"
  42. syn keyword asmTodo contained TODO
  43. " GAS supports one type of multi line comments:
  44. syn region asmComment start="/\*" end="\*/" contains=asmTodo
  45. " GAS (undocumentedly?) supports C++ style comments. Unlike in C/C++ however,
  46. " a backslash ending a C++ style comment does not extend the comment to the
  47. " next line (hence the syntax region does not define 'skip="\\$"')
  48. syn region asmComment start="//" end="$" keepend contains=asmTodo
  49. " Line comment characters depend on the target architecture and command line
  50. " options and some comments may double as logical line number directives or
  51. " preprocessor commands. This situation is described at
  52. " http://sourceware.org/binutils/docs-2.22/as/Comments.html
  53. " Some line comment characters have other meanings for other targets. For
  54. " example, .type directives may use the `@' character which is also an ARM
  55. " comment marker.
  56. " As a compromise to accommodate what I arbitrarily assume to be the most
  57. " frequently used features of the most popular architectures (and also the
  58. " non-GNU assembly languages that use this syntax file because their asm files
  59. " are also named *.asm), the following are used as line comment characters:
  60. syn match asmComment "[#;!|].*" contains=asmTodo
  61. " Side effects of this include:
  62. " - When `;' is used to separate statements on the same line (many targets
  63. " support this), all statements except the first get highlighted as
  64. " comments. As a remedy, remove `;' from the above.
  65. " - ARM comments are not highlighted correctly. For ARM, uncomment the
  66. " following two lines and comment the one above.
  67. "syn match asmComment "@.*" contains=asmTodo
  68. "syn match asmComment "^#.*" contains=asmTodo
  69. " Advanced users of specific architectures will probably want to change the
  70. " comment highlighting or use a specific, more comprehensive syntax file.
  71. syn match asmInclude "\.include"
  72. syn match asmCond "\.if"
  73. syn match asmCond "\.else"
  74. syn match asmCond "\.endif"
  75. syn match asmMacro "\.macro"
  76. syn match asmMacro "\.endm"
  77. " Assembler directives start with a '.' and may contain upper case (e.g.,
  78. " .ABORT), numbers (e.g., .p2align), dash (e.g., .app-file) and underscore in
  79. " CFI directives (e.g., .cfi_startproc). This will also match labels starting
  80. " with '.', including the GCC auto-generated '.L' labels.
  81. syn match asmDirective "\.[A-Za-z][0-9A-Za-z-_]*"
  82. syn case match
  83. " Define the default highlighting.
  84. " Only when an item doesn't have highlighting yet
  85. " The default methods for highlighting. Can be overridden later
  86. hi def link asmSection Special
  87. hi def link asmLabel Label
  88. hi def link asmComment Comment
  89. hi def link asmTodo Todo
  90. hi def link asmDirective Statement
  91. hi def link asmInclude Include
  92. hi def link asmCond PreCondit
  93. hi def link asmMacro Macro
  94. hi def link hexNumber Number
  95. hi def link decNumber Number
  96. hi def link octNumber Number
  97. hi def link binNumber Number
  98. hi def link asmIdentifier Identifier
  99. hi def link asmType Type
  100. let b:current_syntax = "asm"
  101. let &cpo = s:cpo_save
  102. unlet s:cpo_save
  103. " vim: ts=8