blob: 4f04bd0218e47f7d2a4c73b0c56444f318496868 [file] [log] [blame]
Bram Moolenaarc81e5e72007-05-05 18:24:42 +00001"----------------------------------------------------------------------------
2" Description: Vim Ada syntax file
3" Language: Ada (2005)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004" $Id: ada.vim 887 2008-07-08 14:29:01Z krischik $
Bram Moolenaarc81e5e72007-05-05 18:24:42 +00005" 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.
Bram Moolenaar5c736222010-01-06 20:54:52 +010010" $Author: krischik $
11" $Date: 2008-07-08 16:29:01 +0200 (Di, 08 Jul 2008) $
Bram Moolenaarc236c162008-07-13 17:41:49 +000012" Version: 4.6
Bram Moolenaar5c736222010-01-06 20:54:52 +010013" $Revision: 887 $
Bram Moolenaarc236c162008-07-13 17:41:49 +000014" $HeadURL: https://gnuada.svn.sourceforge.net/svnroot/gnuada/trunk/tools/vim/syntax/ada.vim $
Bram Moolenaarc81e5e72007-05-05 18:24:42 +000015" 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"------------------------------------------------------------------------------
Bram Moolenaar071d4272004-06-13 20:20:40 +000031
Bram Moolenaarc81e5e72007-05-05 18:24:42 +000032if exists("b:current_syntax") || version < 700
33 finish
Bram Moolenaar071d4272004-06-13 20:20:40 +000034endif
35
Bram Moolenaarc81e5e72007-05-05 18:24:42 +000036let b:current_syntax = "ada"
Bram Moolenaar071d4272004-06-13 20:20:40 +000037
Bram Moolenaarc81e5e72007-05-05 18:24:42 +000038" Section: Ada is entirely case-insensitive. {{{1
39"
40syntax case ignore
Bram Moolenaar071d4272004-06-13 20:20:40 +000041
Bram Moolenaarc81e5e72007-05-05 18:24:42 +000042" Section: Highlighting commands {{{1
43"
44" There are 72 reserved words in total in Ada2005. Some keywords are
45" used in more than one way. For example:
Bram Moolenaar071d4272004-06-13 20:20:40 +000046" 1. "end" is a general keyword, but "end if" ends a Conditional.
47" 2. "then" is a conditional, but "and then" is an operator.
Bram Moolenaarc81e5e72007-05-05 18:24:42 +000048"
49for 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']
56 endif
57 if b:Item['kind'] == "a"
58 execute 'syntax match adaAttribute "\V' . b:Item['word'] . '"'
59 endif
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']
68 endif
69endfor
Bram Moolenaar071d4272004-06-13 20:20:40 +000070
Bram Moolenaarc81e5e72007-05-05 18:24:42 +000071" Section: others {{{1
72"
73syntax keyword adaLabel others
Bram Moolenaar071d4272004-06-13 20:20:40 +000074
Bram Moolenaarc81e5e72007-05-05 18:24:42 +000075" Section: Operatoren {{{1
76"
77syntax keyword adaOperator abs mod not rem xor
78syntax match adaOperator "\<and\>"
79syntax match adaOperator "\<and\s\+then\>"
80syntax match adaOperator "\<or\>"
81syntax match adaOperator "\<or\s\+else\>"
82syntax match adaOperator "[-+*/<>&]"
83syntax keyword adaOperator **
84syntax match adaOperator "[/<>]="
85syntax keyword adaOperator =>
86syntax match adaOperator "\.\."
87syntax match adaOperator "="
Bram Moolenaar071d4272004-06-13 20:20:40 +000088
Bram Moolenaarc81e5e72007-05-05 18:24:42 +000089" Section: <> {{{1
90"
91" Handle the box, <>, specially:
92"
93syntax keyword adaSpecial <>
Bram Moolenaar071d4272004-06-13 20:20:40 +000094
Bram Moolenaarc81e5e72007-05-05 18:24:42 +000095" Section: rainbow color {{{1
96"
97if exists("g:ada_rainbow_color")
98 syntax match adaSpecial "[:;.,]"
Bram Moolenaarc236c162008-07-13 17:41:49 +000099 call rainbow_parenthsis#LoadRound ()
100 call rainbow_parenthsis#Activate ()
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000101else
102 syntax match adaSpecial "[:;().,]"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000103endif
104
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000105" Section: := {{{1
106"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000107" 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.
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000110"
111syntax match adaAssignment ":="
Bram Moolenaar071d4272004-06-13 20:20:40 +0000112
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000113" Section: Numbers, including floating point, exponents, and alternate bases. {{{1
114"
115syntax match adaNumber "\<\d[0-9_]*\(\.\d[0-9_]*\)\=\([Ee][+-]\=\d[0-9_]*\)\=\>"
116syntax match adaNumber "\<\d\d\=#\x[0-9A-Fa-f_]*\(\.\x[0-9A-Fa-f_]*\)\=#\([Ee][+-]\=\d[0-9_]*\)\="
Bram Moolenaar071d4272004-06-13 20:20:40 +0000117
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000118" Section: Identify leading numeric signs {{{1
119"
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.
124"
125syntax match adaSign "[[:space:]<>=(,|:;&*/+-][+-]\d"lc=1,hs=s+1,he=e-1,me=e-1
Bram Moolenaar071d4272004-06-13 20:20:40 +0000126
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000127" Section: Labels for the goto statement. {{{1
128"
129syntax region adaLabel start="<<" end=">>"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000130
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000131" Section: Boolean Constants {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +0000132" Boolean Constants.
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000133syntax keyword adaBoolean true false
Bram Moolenaar071d4272004-06-13 20:20:40 +0000134
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000135" Section: Warn C/C++ {{{1
136"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000137" Warn people who try to use C/C++ notation erroneously:
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000138"
139syntax match adaError "//"
140syntax match adaError "/\*"
141syntax match adaError "=="
Bram Moolenaar071d4272004-06-13 20:20:40 +0000142
143
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000144" Section: Space Errors {{{1
145"
146if exists("g:ada_space_errors")
147 if !exists("g:ada_no_trail_space_error")
148 syntax match adaSpaceError excludenl "\s\+$"
149 endif
150 if !exists("g:ada_no_tab_space_error")
151 syntax match adaSpaceError " \+\t"me=e-1
152 endif
153 if !exists("g:ada_all_tab_usage")
154 syntax match adaSpecial "\t"
155 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000156endif
157
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000158" Section: end {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +0000159" Unless special ("end loop", "end if", etc.), "end" marks the end of a
160" begin, package, task etc. Assiging it to adaEnd.
Bram Moolenaarc236c162008-07-13 17:41:49 +0000161syntax match adaEnd /\<end\>/
Bram Moolenaar071d4272004-06-13 20:20:40 +0000162
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000163syntax keyword adaPreproc pragma
Bram Moolenaar071d4272004-06-13 20:20:40 +0000164
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000165syntax keyword adaRepeat exit for loop reverse while
166syntax match adaRepeat "\<end\s\+loop\>"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000167
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000168syntax keyword adaStatement accept delay goto raise requeue return
169syntax keyword adaStatement terminate
170syntax match adaStatement "\<abort\>"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000171
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000172" Section: Handle Ada's record keywords. {{{1
173"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000174" '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).
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000180"
181syntax match adaStructure "\<record\>" contains=adaRecord
182syntax match adaStructure "\<end\s\+record\>" contains=adaRecord
183syntax match adaKeyword "\<record;"me=e-1
Bram Moolenaar071d4272004-06-13 20:20:40 +0000184
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000185" Section: type classes {{{1
186"
187syntax keyword adaStorageClass abstract access aliased array at constant delta
188syntax keyword adaStorageClass digits limited of private range tagged
189syntax keyword adaStorageClass interface synchronized
190syntax keyword adaTypedef subtype type
Bram Moolenaar071d4272004-06-13 20:20:40 +0000191
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000192" Section: Conditionals {{{1
193"
194" "abort" after "then" is a conditional of its own.
195"
196syntax match adaConditional "\<then\>"
197syntax match adaConditional "\<then\s\+abort\>"
198syntax match adaConditional "\<else\>"
199syntax match adaConditional "\<end\s\+if\>"
200syntax match adaConditional "\<end\s\+case\>"
201syntax match adaConditional "\<end\s\+select\>"
202syntax keyword adaConditional if case select
203syntax keyword adaConditional elsif when
Bram Moolenaar071d4272004-06-13 20:20:40 +0000204
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000205" Section: other keywords {{{1
206syntax match adaKeyword "\<is\>" contains=adaRecord
207syntax keyword adaKeyword all do exception in new null out
208syntax keyword adaKeyword separate until overriding
Bram Moolenaar071d4272004-06-13 20:20:40 +0000209
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000210" Section: begin keywords {{{1
211"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000212" These keywords begin various constructs, and you _might_ want to
213" highlight them differently.
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000214"
215syntax keyword adaBegin begin body declare entry generic
216syntax keyword adaBegin protected renames task
Bram Moolenaar071d4272004-06-13 20:20:40 +0000217
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000218syntax match adaBegin "\<function\>" contains=adaFunction
219syntax match adaBegin "\<procedure\>" contains=adaProcedure
220syntax match adaBegin "\<package\>" contains=adaPackage
Bram Moolenaar071d4272004-06-13 20:20:40 +0000221
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000222if exists("ada_with_gnat_project_files")
223 syntax keyword adaBegin project
224endif
225
226" Section: with, use {{{1
227"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000228if exists("ada_withuse_ordinary")
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000229 " Don't be fancy. Display "with" and "use" as ordinary keywords in all cases.
230 syntax keyword adaKeyword with use
Bram Moolenaar071d4272004-06-13 20:20:40 +0000231else
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000232 " 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\)\>"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000248endif
249
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000250" Section: String and character constants. {{{1
251"
252syntax region adaString contains=@Spell start=+"+ skip=+""+ end=+"+
253syntax match adaCharacter "'.'"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000254
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000255" Section: Todo (only highlighted in comments) {{{1
256"
257syntax keyword adaTodo contained TODO FIXME XXX NOTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000258
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000259" Section: Comments. {{{1
260"
261syntax region adaComment
262 \ oneline
263 \ contains=adaTodo,adaLineError,@Spell
264 \ start="--"
265 \ end="$"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000266
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000267" Section: line errors {{{1
268"
269" Note: Line errors have become quite slow with Vim 7.0
270"
271if exists("g:ada_line_errors")
272 syntax match adaLineError "\(^.\{79}\)\@<=." contains=ALL containedin=ALL
273endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000274
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000275" Section: syntax folding {{{1
276"
277" Syntax folding is very tricky - for now I still suggest to use
278" indent folding
279"
280if 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
286 endif
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
296 endif
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
302 endif
303endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000304
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000305" Section: The default methods for highlighting. Can be overridden later. {{{1
306"
307highlight def link adaCharacter Character
308highlight def link adaComment Comment
309highlight def link adaConditional Conditional
310highlight def link adaKeyword Keyword
311highlight def link adaLabel Label
312highlight def link adaNumber Number
313highlight def link adaSign Number
314highlight def link adaOperator Operator
315highlight def link adaPreproc PreProc
316highlight def link adaRepeat Repeat
317highlight def link adaSpecial Special
318highlight def link adaStatement Statement
319highlight def link adaString String
320highlight def link adaStructure Structure
321highlight def link adaTodo Todo
322highlight def link adaType Type
323highlight def link adaTypedef Typedef
324highlight def link adaStorageClass StorageClass
325highlight def link adaBoolean Boolean
326highlight def link adaException Exception
327highlight def link adaAttribute Tag
328highlight def link adaInc Include
329highlight def link adaError Error
330highlight def link adaSpaceError Error
331highlight def link adaLineError Error
332highlight def link adaBuiltinType Type
333highlight def link adaAssignment Special
Bram Moolenaar071d4272004-06-13 20:20:40 +0000334
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000335" Subsection: Begin, End {{{2
336"
337if exists ("ada_begin_preproc")
Bram Moolenaar071d4272004-06-13 20:20:40 +0000338 " This is the old default display:
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000339 highlight def link adaBegin PreProc
340 highlight def link adaEnd PreProc
341else
Bram Moolenaar071d4272004-06-13 20:20:40 +0000342 " This is the new default display:
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000343 highlight def link adaBegin Keyword
344 highlight def link adaEnd Keyword
Bram Moolenaar071d4272004-06-13 20:20:40 +0000345endif
346
Bram Moolenaar071d4272004-06-13 20:20:40 +0000347
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000348
349" Section: sync {{{1
350"
351" We don't need to look backwards to highlight correctly;
352" this speeds things up greatly.
353syntax sync minlines=1 maxlines=1
354
355finish " 1}}}
356
357"------------------------------------------------------------------------------
358" Copyright (C) 2006 Martin Krischik
359"
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