1 "----------------------------------------------------------------------------
2 " Description: Vim Ada syntax file
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.
11 " $Date: 2008-07-08 16:29:01 +0200 (Di, 08 Jul 2008) $
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.
28 " This vim syntax file works on vim 7.0 only and makes use of most of Voim 7.0
30 "------------------------------------------------------------------------------
32 if exists("b:current_syntax") || version < 700
36 let b:current_syntax = "ada"
38 " Section: Ada is entirely case-insensitive. {{{1
42 " Section: Highlighting commands {{{1
44 " There are 72 reserved words in total in Ada2005. Some keywords are
45 " used in more than one way. For example:
46 " 1. "end" is a general keyword, but "end if" ends a Conditional.
47 " 2. "then" is a conditional, but "and then" is an operator.
49 for b:Item in g:ada#Keywords
50 " Standard Exceptions (including I/O).
51 " We'll highlight the standard exceptions, similar to vim's Python mode.
52 " It's possible to redefine the standard exceptions as something else,
53 " but doing so is very bad practice, so simply highlighting them makes sense.
54 if b:Item['kind'] == "x"
55 execute "syntax keyword adaException " . b:Item['word']
57 if b:Item['kind'] == "a"
58 execute 'syntax match adaAttribute "\V' . b:Item['word'] . '"'
60 " We don't normally highlight types in package Standard
61 " (Integer, Character, Float, etc.). I don't think it looks good
62 " with the other type keywords, and many Ada programs define
63 " so many of their own types that it looks inconsistent.
64 " However, if you want this highlighting, turn on "ada_standard_types".
65 " For package Standard's definition, see ARM section A.1.
66 if b:Item['kind'] == "t" && exists ("g:ada_standard_types")
67 execute "syntax keyword adaBuiltinType " . b:Item['word']
71 " Section: others {{{1
73 syntax keyword adaLabel others
75 " Section: Operatoren {{{1
77 syntax keyword adaOperator abs mod not rem xor
78 syntax match adaOperator "\<and\>"
79 syntax match adaOperator "\<and\s\+then\>"
80 syntax match adaOperator "\<or\>"
81 syntax match adaOperator "\<or\s\+else\>"
82 syntax match adaOperator "[-+*/<>&]"
83 syntax keyword adaOperator **
84 syntax match adaOperator "[/<>]="
85 syntax keyword adaOperator =>
86 syntax match adaOperator "\.\."
87 syntax match adaOperator "="
91 " Handle the box, <>, specially:
93 syntax keyword adaSpecial <>
95 " Section: rainbow color {{{1
97 if exists("g:ada_rainbow_color")
98 syntax match adaSpecial "[:;.,]"
99 call rainbow_parenthsis#LoadRound ()
100 call rainbow_parenthsis#Activate ()
102 syntax match adaSpecial "[:;().,]"
107 " We won't map "adaAssignment" by default, but we need to map ":=" to
108 " something or the "=" inside it will be mislabelled as an operator.
109 " Note that in Ada, assignment (:=) is not considered an operator.
111 syntax match adaAssignment ":="
113 " Section: Numbers, including floating point, exponents, and alternate bases. {{{1
115 syntax match adaNumber "\<\d[0-9_]*\(\.\d[0-9_]*\)\=\([Ee][+-]\=\d[0-9_]*\)\=\>"
116 syntax match adaNumber "\<\d\d\=#\x[0-9A-Fa-f_]*\(\.\x[0-9A-Fa-f_]*\)\=#\([Ee][+-]\=\d[0-9_]*\)\="
118 " Section: Identify leading numeric signs {{{1
120 " In "A-5" the "-" is an operator, " but in "A:=-5" the "-" is a sign. This
121 " handles "A3+-5" (etc.) correctly. " This assumes that if you put a
122 " don't put a space after +/- when it's used " as an operator, you won't
123 " put a space before it either -- which is true " in code I've seen.
125 syntax match adaSign "[[:space:]<>=(,|:;&*/+-][+-]\d"lc=1,hs=s+1,he=e-1,me=e-1
127 " Section: Labels for the goto statement. {{{1
129 syntax region adaLabel start="<<" end=">>"
131 " Section: Boolean Constants {{{1
133 syntax keyword adaBoolean true false
135 " Section: Warn C/C++ {{{1
137 " Warn people who try to use C/C++ notation erroneously:
139 syntax match adaError "//"
140 syntax match adaError "/\*"
141 syntax match adaError "=="
144 " Section: Space Errors {{{1
146 if exists("g:ada_space_errors")
147 if !exists("g:ada_no_trail_space_error")
148 syntax match adaSpaceError excludenl "\s\+$"
150 if !exists("g:ada_no_tab_space_error")
151 syntax match adaSpaceError " \+\t"me=e-1
153 if !exists("g:ada_all_tab_usage")
154 syntax match adaSpecial "\t"
159 " Unless special ("end loop", "end if", etc.), "end" marks the end of a
160 " begin, package, task etc. Assiging it to adaEnd.
161 syntax match adaEnd /\<end\>/
163 syntax keyword adaPreproc pragma
165 syntax keyword adaRepeat exit for loop reverse while
166 syntax match adaRepeat "\<end\s\+loop\>"
168 syntax keyword adaStatement accept delay goto raise requeue return
169 syntax keyword adaStatement terminate
170 syntax match adaStatement "\<abort\>"
172 " Section: Handle Ada's record keywords. {{{1
174 " 'record' usually starts a structure, but "with null record;" does not,
175 " and 'end record;' ends a structure. The ordering here is critical -
176 " 'record;' matches a "with null record", so make it a keyword (this can
177 " match when the 'with' or 'null' is on a previous line).
178 " We see the "end" in "end record" before the word record, so we match that
179 " pattern as adaStructure (and it won't match the "record;" pattern).
181 syntax match adaStructure "\<record\>" contains=adaRecord
182 syntax match adaStructure "\<end\s\+record\>" contains=adaRecord
183 syntax match adaKeyword "\<record;"me=e-1
185 " Section: type classes {{{1
187 syntax keyword adaStorageClass abstract access aliased array at constant delta
188 syntax keyword adaStorageClass digits limited of private range tagged
189 syntax keyword adaStorageClass interface synchronized
190 syntax keyword adaTypedef subtype type
192 " Section: Conditionals {{{1
194 " "abort" after "then" is a conditional of its own.
196 syntax match adaConditional "\<then\>"
197 syntax match adaConditional "\<then\s\+abort\>"
198 syntax match adaConditional "\<else\>"
199 syntax match adaConditional "\<end\s\+if\>"
200 syntax match adaConditional "\<end\s\+case\>"
201 syntax match adaConditional "\<end\s\+select\>"
202 syntax keyword adaConditional if case select
203 syntax keyword adaConditional elsif when
205 " Section: other keywords {{{1
206 syntax match adaKeyword "\<is\>" contains=adaRecord
207 syntax keyword adaKeyword all do exception in new null out
208 syntax keyword adaKeyword separate until overriding
210 " Section: begin keywords {{{1
212 " These keywords begin various constructs, and you _might_ want to
213 " highlight them differently.
215 syntax keyword adaBegin begin body declare entry generic
216 syntax keyword adaBegin protected renames task
218 syntax match adaBegin "\<function\>" contains=adaFunction
219 syntax match adaBegin "\<procedure\>" contains=adaProcedure
220 syntax match adaBegin "\<package\>" contains=adaPackage
222 if exists("ada_with_gnat_project_files")
223 syntax keyword adaBegin project
226 " Section: with, use {{{1
228 if exists("ada_withuse_ordinary")
229 " Don't be fancy. Display "with" and "use" as ordinary keywords in all cases.
230 syntax keyword adaKeyword with use
232 " Highlight "with" and "use" clauses like C's "#include" when they're used
233 " to reference other compilation units; otherwise they're ordinary keywords.
234 " If we have vim 6.0 or later, we'll use its advanced pattern-matching
235 " capabilities so that we won't match leading spaces.
236 syntax match adaKeyword "\<with\>"
237 syntax match adaKeyword "\<use\>"
238 syntax match adaBeginWith "^\s*\zs\(\(with\(\s\+type\)\=\)\|\(use\)\)\>" contains=adaInc
239 syntax match adaSemiWith ";\s*\zs\(\(with\(\s\+type\)\=\)\|\(use\)\)\>" contains=adaInc
240 syntax match adaInc "\<with\>" contained contains=NONE
241 syntax match adaInc "\<with\s\+type\>" contained contains=NONE
242 syntax match adaInc "\<use\>" contained contains=NONE
243 " Recognize "with null record" as a keyword (even the "record").
244 syntax match adaKeyword "\<with\s\+null\s\+record\>"
245 " Consider generic formal parameters of subprograms and packages as keywords.
246 syntax match adaKeyword ";\s*\zswith\s\+\(function\|procedure\|package\)\>"
247 syntax match adaKeyword "^\s*\zswith\s\+\(function\|procedure\|package\)\>"
250 " Section: String and character constants. {{{1
252 syntax region adaString contains=@Spell start=+"+ skip=+""+ end=+"+
253 syntax match adaCharacter "'.'"
255 " Section: Todo (only highlighted in comments) {{{1
257 syntax keyword adaTodo contained TODO FIXME XXX NOTE
259 " Section: Comments. {{{1
261 syntax region adaComment
263 \ contains=adaTodo,adaLineError,@Spell
267 " Section: line errors {{{1
269 " Note: Line errors have become quite slow with Vim 7.0
271 if exists("g:ada_line_errors")
272 syntax match adaLineError "\(^.\{79}\)\@<=." contains=ALL containedin=ALL
275 " Section: syntax folding {{{1
277 " Syntax folding is very tricky - for now I still suggest to use
280 if exists("g:ada_folding") && g:ada_folding[0] == 's'
281 if stridx (g:ada_folding, 'p') >= 0
282 syntax region adaPackage
283 \ start="\(\<package\s\+body\>\|\<package\>\)\s*\z(\k*\)"
284 \ end="end\s\+\z1\s*;"
285 \ keepend extend transparent fold contains=ALL
287 if stridx (g:ada_folding, 'f') >= 0
288 syntax region adaProcedure
289 \ start="\<procedure\>\s*\z(\k*\)"
290 \ end="\<end\>\s\+\z1\s*;"
291 \ keepend extend transparent fold contains=ALL
292 syntax region adaFunction
293 \ start="\<procedure\>\s*\z(\k*\)"
294 \ end="end\s\+\z1\s*;"
295 \ keepend extend transparent fold contains=ALL
297 if stridx (g:ada_folding, 'f') >= 0
298 syntax region adaRecord
299 \ start="\<is\s\+record\>"
300 \ end="\<end\s\+record\>"
301 \ keepend extend transparent fold contains=ALL
305 " Section: The default methods for highlighting. Can be overridden later. {{{1
307 highlight def link adaCharacter Character
308 highlight def link adaComment Comment
309 highlight def link adaConditional Conditional
310 highlight def link adaKeyword Keyword
311 highlight def link adaLabel Label
312 highlight def link adaNumber Number
313 highlight def link adaSign Number
314 highlight def link adaOperator Operator
315 highlight def link adaPreproc PreProc
316 highlight def link adaRepeat Repeat
317 highlight def link adaSpecial Special
318 highlight def link adaStatement Statement
319 highlight def link adaString String
320 highlight def link adaStructure Structure
321 highlight def link adaTodo Todo
322 highlight def link adaType Type
323 highlight def link adaTypedef Typedef
324 highlight def link adaStorageClass StorageClass
325 highlight def link adaBoolean Boolean
326 highlight def link adaException Exception
327 highlight def link adaAttribute Tag
328 highlight def link adaInc Include
329 highlight def link adaError Error
330 highlight def link adaSpaceError Error
331 highlight def link adaLineError Error
332 highlight def link adaBuiltinType Type
333 highlight def link adaAssignment Special
335 " Subsection: Begin, End {{{2
337 if exists ("ada_begin_preproc")
338 " This is the old default display:
339 highlight def link adaBegin PreProc
340 highlight def link adaEnd PreProc
342 " This is the new default display:
343 highlight def link adaBegin Keyword
344 highlight def link adaEnd Keyword
351 " We don't need to look backwards to highlight correctly;
352 " this speeds things up greatly.
353 syntax sync minlines=1 maxlines=1
357 "------------------------------------------------------------------------------
358 " Copyright (C) 2006 Martin Krischik
360 " Vim is Charityware - see ":help license" or uganda.txt for licence details.
361 "------------------------------------------------------------------------------
362 "vim: textwidth=78 nowrap tabstop=8 shiftwidth=3 softtabstop=3 noexpandtab
363 "vim: foldmethod=marker