ada.vim 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. "----------------------------------------------------------------------------
  2. " Description: Vim Ada syntax file
  3. " Language: Ada (2005)
  4. " $Id: ada.vim 887 2008-07-08 14:29:01Z krischik $
  5. " Copyright: Copyright (C) 2006 Martin Krischik
  6. " Maintainer: Martin Krischik
  7. " David A. Wheeler <dwheeler@dwheeler.com>
  8. " Simon Bradley <simon.bradley@pitechnology.com>
  9. " Contributors: Preben Randhol.
  10. " $Author: krischik $
  11. " $Date: 2008-07-08 16:29:01 +0200 (Di, 08 Jul 2008) $
  12. " Version: 4.6
  13. " $Revision: 887 $
  14. " $HeadURL: https://gnuada.svn.sourceforge.net/svnroot/gnuada/trunk/tools/vim/syntax/ada.vim $
  15. " http://www.dwheeler.com/vim
  16. " History: 24.05.2006 MK Unified Headers
  17. " 26.05.2006 MK ' should not be in iskeyword.
  18. " 16.07.2006 MK Ada-Mode as vim-ball
  19. " 02.10.2006 MK Better folding.
  20. " 15.10.2006 MK Bram's suggestion for runtime integration
  21. " 05.11.2006 MK Spell check for comments and strings only
  22. " 05.11.2006 MK Bram suggested to save on spaces
  23. " Help Page: help ft-ada-syntax
  24. "------------------------------------------------------------------------------
  25. " The formal spec of Ada 2005 (ARM) is the "Ada 2005 Reference Manual".
  26. " For more Ada 2005 info, see http://www.gnuada.org and http://www.adapower.com.
  27. "
  28. " This vim syntax file works on vim 7.0 only and makes use of most of Voim 7.0
  29. " advanced features.
  30. "------------------------------------------------------------------------------
  31. if exists("b:current_syntax") || version < 700
  32. finish
  33. endif
  34. let s:keepcpo= &cpo
  35. set cpo&vim
  36. let b:current_syntax = "ada"
  37. " Section: Ada is entirely case-insensitive. {{{1
  38. "
  39. syntax case ignore
  40. " Section: Highlighting commands {{{1
  41. "
  42. " There are 72 reserved words in total in Ada2005. Some keywords are
  43. " used in more than one way. For example:
  44. " 1. "end" is a general keyword, but "end if" ends a Conditional.
  45. " 2. "then" is a conditional, but "and then" is an operator.
  46. "
  47. for b:Item in g:ada#Keywords
  48. " Standard Exceptions (including I/O).
  49. " We'll highlight the standard exceptions, similar to vim's Python mode.
  50. " It's possible to redefine the standard exceptions as something else,
  51. " but doing so is very bad practice, so simply highlighting them makes sense.
  52. if b:Item['kind'] == "x"
  53. execute "syntax keyword adaException " . b:Item['word']
  54. endif
  55. if b:Item['kind'] == "a"
  56. execute 'syntax match adaAttribute "\V' . b:Item['word'] . '"'
  57. endif
  58. " We don't normally highlight types in package Standard
  59. " (Integer, Character, Float, etc.). I don't think it looks good
  60. " with the other type keywords, and many Ada programs define
  61. " so many of their own types that it looks inconsistent.
  62. " However, if you want this highlighting, turn on "ada_standard_types".
  63. " For package Standard's definition, see ARM section A.1.
  64. if b:Item['kind'] == "t" && exists ("g:ada_standard_types")
  65. execute "syntax keyword adaBuiltinType " . b:Item['word']
  66. endif
  67. endfor
  68. " Section: others {{{1
  69. "
  70. syntax keyword adaLabel others
  71. " Section: Operatoren {{{1
  72. "
  73. syntax keyword adaOperator abs mod not rem xor
  74. syntax match adaOperator "\<and\>"
  75. syntax match adaOperator "\<and\s\+then\>"
  76. syntax match adaOperator "\<or\>"
  77. syntax match adaOperator "\<or\s\+else\>"
  78. syntax match adaOperator "[-+*/<>&]"
  79. syntax keyword adaOperator **
  80. syntax match adaOperator "[/<>]="
  81. syntax keyword adaOperator =>
  82. syntax match adaOperator "\.\."
  83. syntax match adaOperator "="
  84. " Section: <> {{{1
  85. "
  86. " Handle the box, <>, specially:
  87. "
  88. syntax keyword adaSpecial <>
  89. " Section: rainbow color {{{1
  90. "
  91. if exists("g:ada_rainbow_color")
  92. syntax match adaSpecial "[:;.,]"
  93. call rainbow_parenthsis#LoadRound ()
  94. call rainbow_parenthsis#Activate ()
  95. else
  96. syntax match adaSpecial "[:;().,]"
  97. endif
  98. " Section: := {{{1
  99. "
  100. " We won't map "adaAssignment" by default, but we need to map ":=" to
  101. " something or the "=" inside it will be mislabelled as an operator.
  102. " Note that in Ada, assignment (:=) is not considered an operator.
  103. "
  104. syntax match adaAssignment ":="
  105. " Section: Numbers, including floating point, exponents, and alternate bases. {{{1
  106. "
  107. syntax match adaNumber "\<\d[0-9_]*\(\.\d[0-9_]*\)\=\([Ee][+-]\=\d[0-9_]*\)\=\>"
  108. syntax match adaNumber "\<\d\d\=#\x[0-9A-Fa-f_]*\(\.\x[0-9A-Fa-f_]*\)\=#\([Ee][+-]\=\d[0-9_]*\)\="
  109. " Section: Identify leading numeric signs {{{1
  110. "
  111. " In "A-5" the "-" is an operator, " but in "A:=-5" the "-" is a sign. This
  112. " handles "A3+-5" (etc.) correctly. " This assumes that if you put a
  113. " don't put a space after +/- when it's used " as an operator, you won't
  114. " put a space before it either -- which is true " in code I've seen.
  115. "
  116. syntax match adaSign "[[:space:]<>=(,|:;&*/+-][+-]\d"lc=1,hs=s+1,he=e-1,me=e-1
  117. " Section: Labels for the goto statement. {{{1
  118. "
  119. syntax region adaLabel start="<<" end=">>"
  120. " Section: Boolean Constants {{{1
  121. " Boolean Constants.
  122. syntax keyword adaBoolean true false
  123. " Section: Warn C/C++ {{{1
  124. "
  125. " Warn people who try to use C/C++ notation erroneously:
  126. "
  127. syntax match adaError "//"
  128. syntax match adaError "/\*"
  129. syntax match adaError "=="
  130. " Section: Space Errors {{{1
  131. "
  132. if exists("g:ada_space_errors")
  133. if !exists("g:ada_no_trail_space_error")
  134. syntax match adaSpaceError excludenl "\s\+$"
  135. endif
  136. if !exists("g:ada_no_tab_space_error")
  137. syntax match adaSpaceError " \+\t"me=e-1
  138. endif
  139. if !exists("g:ada_all_tab_usage")
  140. syntax match adaSpecial "\t"
  141. endif
  142. endif
  143. " Section: end {{{1
  144. " Unless special ("end loop", "end if", etc.), "end" marks the end of a
  145. " begin, package, task etc. Assigning it to adaEnd.
  146. syntax match adaEnd /\<end\>/
  147. syntax keyword adaPreproc pragma
  148. syntax keyword adaRepeat exit for loop reverse while
  149. syntax match adaRepeat "\<end\s\+loop\>"
  150. syntax keyword adaStatement accept delay goto raise requeue return
  151. syntax keyword adaStatement terminate
  152. syntax match adaStatement "\<abort\>"
  153. " Section: Handle Ada's record keywords. {{{1
  154. "
  155. " 'record' usually starts a structure, but "with null record;" does not,
  156. " and 'end record;' ends a structure. The ordering here is critical -
  157. " 'record;' matches a "with null record", so make it a keyword (this can
  158. " match when the 'with' or 'null' is on a previous line).
  159. " We see the "end" in "end record" before the word record, so we match that
  160. " pattern as adaStructure (and it won't match the "record;" pattern).
  161. "
  162. syntax match adaStructure "\<record\>" contains=adaRecord
  163. syntax match adaStructure "\<end\s\+record\>" contains=adaRecord
  164. syntax match adaKeyword "\<record;"me=e-1
  165. " Section: type classes {{{1
  166. "
  167. syntax keyword adaStorageClass abstract access aliased array at constant delta
  168. syntax keyword adaStorageClass digits limited of private range tagged
  169. syntax keyword adaStorageClass interface synchronized
  170. syntax keyword adaTypedef subtype type
  171. " Section: Conditionals {{{1
  172. "
  173. " "abort" after "then" is a conditional of its own.
  174. "
  175. syntax match adaConditional "\<then\>"
  176. syntax match adaConditional "\<then\s\+abort\>"
  177. syntax match adaConditional "\<else\>"
  178. syntax match adaConditional "\<end\s\+if\>"
  179. syntax match adaConditional "\<end\s\+case\>"
  180. syntax match adaConditional "\<end\s\+select\>"
  181. syntax keyword adaConditional if case select
  182. syntax keyword adaConditional elsif when
  183. " Section: other keywords {{{1
  184. syntax match adaKeyword "\<is\>" contains=adaRecord
  185. syntax keyword adaKeyword all do exception in new null out
  186. syntax keyword adaKeyword separate until overriding
  187. " Section: begin keywords {{{1
  188. "
  189. " These keywords begin various constructs, and you _might_ want to
  190. " highlight them differently.
  191. "
  192. syntax keyword adaBegin begin body declare entry generic
  193. syntax keyword adaBegin protected renames task
  194. syntax match adaBegin "\<function\>" contains=adaFunction
  195. syntax match adaBegin "\<procedure\>" contains=adaProcedure
  196. syntax match adaBegin "\<package\>" contains=adaPackage
  197. if exists("ada_with_gnat_project_files")
  198. syntax keyword adaBegin project
  199. endif
  200. " Section: with, use {{{1
  201. "
  202. if exists("ada_withuse_ordinary")
  203. " Don't be fancy. Display "with" and "use" as ordinary keywords in all cases.
  204. syntax keyword adaKeyword with use
  205. else
  206. " Highlight "with" and "use" clauses like C's "#include" when they're used
  207. " to reference other compilation units; otherwise they're ordinary keywords.
  208. " If we have vim 6.0 or later, we'll use its advanced pattern-matching
  209. " capabilities so that we won't match leading spaces.
  210. syntax match adaKeyword "\<with\>"
  211. syntax match adaKeyword "\<use\>"
  212. syntax match adaBeginWith "^\s*\zs\(\(with\(\s\+type\)\=\)\|\(use\)\)\>" contains=adaInc
  213. syntax match adaSemiWith ";\s*\zs\(\(with\(\s\+type\)\=\)\|\(use\)\)\>" contains=adaInc
  214. syntax match adaInc "\<with\>" contained contains=NONE
  215. syntax match adaInc "\<with\s\+type\>" contained contains=NONE
  216. syntax match adaInc "\<use\>" contained contains=NONE
  217. " Recognize "with null record" as a keyword (even the "record").
  218. syntax match adaKeyword "\<with\s\+null\s\+record\>"
  219. " Consider generic formal parameters of subprograms and packages as keywords.
  220. syntax match adaKeyword ";\s*\zswith\s\+\(function\|procedure\|package\)\>"
  221. syntax match adaKeyword "^\s*\zswith\s\+\(function\|procedure\|package\)\>"
  222. endif
  223. " Section: String and character constants. {{{1
  224. "
  225. syntax region adaString contains=@Spell start=+"+ skip=+""+ end=+"+
  226. syntax match adaCharacter "'.'"
  227. " Section: Todo (only highlighted in comments) {{{1
  228. "
  229. syntax keyword adaTodo contained TODO FIXME XXX NOTE
  230. " Section: Comments. {{{1
  231. "
  232. syntax region adaComment
  233. \ oneline
  234. \ contains=adaTodo,adaLineError,@Spell
  235. \ start="--"
  236. \ end="$"
  237. " Section: line errors {{{1
  238. "
  239. " Note: Line errors have become quite slow with Vim 7.0
  240. "
  241. if exists("g:ada_line_errors")
  242. syntax match adaLineError "\(^.\{79}\)\@<=." contains=ALL containedin=ALL
  243. endif
  244. " Section: syntax folding {{{1
  245. "
  246. " Syntax folding is very tricky - for now I still suggest to use
  247. " indent folding
  248. "
  249. if exists("g:ada_folding") && g:ada_folding[0] == 's'
  250. if stridx (g:ada_folding, 'p') >= 0
  251. syntax region adaPackage
  252. \ start="\(\<package\s\+body\>\|\<package\>\)\s*\z(\k*\)"
  253. \ end="end\s\+\z1\s*;"
  254. \ keepend extend transparent fold contains=ALL
  255. endif
  256. if stridx (g:ada_folding, 'f') >= 0
  257. syntax region adaProcedure
  258. \ start="\<procedure\>\s*\z(\k*\)"
  259. \ end="\<end\>\s\+\z1\s*;"
  260. \ keepend extend transparent fold contains=ALL
  261. syntax region adaFunction
  262. \ start="\<procedure\>\s*\z(\k*\)"
  263. \ end="end\s\+\z1\s*;"
  264. \ keepend extend transparent fold contains=ALL
  265. endif
  266. if stridx (g:ada_folding, 'f') >= 0
  267. syntax region adaRecord
  268. \ start="\<is\s\+record\>"
  269. \ end="\<end\s\+record\>"
  270. \ keepend extend transparent fold contains=ALL
  271. endif
  272. endif
  273. " Section: The default methods for highlighting. Can be overridden later. {{{1
  274. "
  275. highlight def link adaCharacter Character
  276. highlight def link adaComment Comment
  277. highlight def link adaConditional Conditional
  278. highlight def link adaKeyword Keyword
  279. highlight def link adaLabel Label
  280. highlight def link adaNumber Number
  281. highlight def link adaSign Number
  282. highlight def link adaOperator Operator
  283. highlight def link adaPreproc PreProc
  284. highlight def link adaRepeat Repeat
  285. highlight def link adaSpecial Special
  286. highlight def link adaStatement Statement
  287. highlight def link adaString String
  288. highlight def link adaStructure Structure
  289. highlight def link adaTodo Todo
  290. highlight def link adaType Type
  291. highlight def link adaTypedef Typedef
  292. highlight def link adaStorageClass StorageClass
  293. highlight def link adaBoolean Boolean
  294. highlight def link adaException Exception
  295. highlight def link adaAttribute Tag
  296. highlight def link adaInc Include
  297. highlight def link adaError Error
  298. highlight def link adaSpaceError Error
  299. highlight def link adaLineError Error
  300. highlight def link adaBuiltinType Type
  301. highlight def link adaAssignment Special
  302. " Subsection: Begin, End {{{2
  303. "
  304. if exists ("ada_begin_preproc")
  305. " This is the old default display:
  306. highlight def link adaBegin PreProc
  307. highlight def link adaEnd PreProc
  308. else
  309. " This is the new default display:
  310. highlight def link adaBegin Keyword
  311. highlight def link adaEnd Keyword
  312. endif
  313. " Section: sync {{{1
  314. "
  315. " We don't need to look backwards to highlight correctly;
  316. " this speeds things up greatly.
  317. syntax sync minlines=1 maxlines=1
  318. let &cpo = s:keepcpo
  319. unlet s:keepcpo
  320. finish " 1}}}
  321. "------------------------------------------------------------------------------
  322. " Copyright (C) 2006 Martin Krischik
  323. "
  324. " Vim is Charityware - see ":help license" or uganda.txt for licence details.
  325. "------------------------------------------------------------------------------
  326. "vim: textwidth=78 nowrap tabstop=8 shiftwidth=3 softtabstop=3 noexpandtab
  327. "vim: foldmethod=marker