blob: f31770077506ea2897d2df8d1f7580aefd9fb944 [file] [log] [blame]
Bram Moolenaarc81e5e72007-05-05 18:24:42 +00001"----------------------------------------------------------------------------
2" Description: Vim Ada syntax file
3" Language: Ada (2005)
4" $Id$
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$
11" $Date$
12" Version: 4.2
13" $Revision$
14" $HeadURL: https://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"------------------------------------------------------------------------------
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
41setlocal nosmartcase
42setlocal ignorecase
Bram Moolenaar071d4272004-06-13 20:20:40 +000043
Bram Moolenaarc81e5e72007-05-05 18:24:42 +000044" Section: Highlighting commands {{{1
45"
46" There are 72 reserved words in total in Ada2005. Some keywords are
47" used in more than one way. For example:
Bram Moolenaar071d4272004-06-13 20:20:40 +000048" 1. "end" is a general keyword, but "end if" ends a Conditional.
49" 2. "then" is a conditional, but "and then" is an operator.
Bram Moolenaarc81e5e72007-05-05 18:24:42 +000050"
51for b:Item in g:ada#Keywords
52 " Standard Exceptions (including I/O).
53 " We'll highlight the standard exceptions, similar to vim's Python mode.
54 " It's possible to redefine the standard exceptions as something else,
55 " but doing so is very bad practice, so simply highlighting them makes sense.
56 if b:Item['kind'] == "x"
57 execute "syntax keyword adaException " . b:Item['word']
58 endif
59 if b:Item['kind'] == "a"
60 execute 'syntax match adaAttribute "\V' . b:Item['word'] . '"'
61 endif
62 " We don't normally highlight types in package Standard
63 " (Integer, Character, Float, etc.). I don't think it looks good
64 " with the other type keywords, and many Ada programs define
65 " so many of their own types that it looks inconsistent.
66 " However, if you want this highlighting, turn on "ada_standard_types".
67 " For package Standard's definition, see ARM section A.1.
68 if b:Item['kind'] == "t" && exists ("g:ada_standard_types")
69 execute "syntax keyword adaBuiltinType " . b:Item['word']
70 endif
71endfor
Bram Moolenaar071d4272004-06-13 20:20:40 +000072
Bram Moolenaarc81e5e72007-05-05 18:24:42 +000073" Section: others {{{1
74"
75syntax keyword adaLabel others
Bram Moolenaar071d4272004-06-13 20:20:40 +000076
Bram Moolenaarc81e5e72007-05-05 18:24:42 +000077" Section: Operatoren {{{1
78"
79syntax keyword adaOperator abs mod not rem xor
80syntax match adaOperator "\<and\>"
81syntax match adaOperator "\<and\s\+then\>"
82syntax match adaOperator "\<or\>"
83syntax match adaOperator "\<or\s\+else\>"
84syntax match adaOperator "[-+*/<>&]"
85syntax keyword adaOperator **
86syntax match adaOperator "[/<>]="
87syntax keyword adaOperator =>
88syntax match adaOperator "\.\."
89syntax match adaOperator "="
Bram Moolenaar071d4272004-06-13 20:20:40 +000090
Bram Moolenaarc81e5e72007-05-05 18:24:42 +000091" Section: <> {{{1
92"
93" Handle the box, <>, specially:
94"
95syntax keyword adaSpecial <>
Bram Moolenaar071d4272004-06-13 20:20:40 +000096
Bram Moolenaarc81e5e72007-05-05 18:24:42 +000097" Section: rainbow color {{{1
98"
99if exists("g:ada_rainbow_color")
100 syntax match adaSpecial "[:;.,]"
101 runtime plugin/Rainbow_Parenthsis.vim
102else
103 syntax match adaSpecial "[:;().,]"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000104endif
105
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000106" Section: := {{{1
107"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000108" We won't map "adaAssignment" by default, but we need to map ":=" to
109" something or the "=" inside it will be mislabelled as an operator.
110" Note that in Ada, assignment (:=) is not considered an operator.
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000111"
112syntax match adaAssignment ":="
Bram Moolenaar071d4272004-06-13 20:20:40 +0000113
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000114" Section: Numbers, including floating point, exponents, and alternate bases. {{{1
115"
116syntax match adaNumber "\<\d[0-9_]*\(\.\d[0-9_]*\)\=\([Ee][+-]\=\d[0-9_]*\)\=\>"
117syntax 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 +0000118
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000119" Section: Identify leading numeric signs {{{1
120"
121" In "A-5" the "-" is an operator, " but in "A:=-5" the "-" is a sign. This
122" handles "A3+-5" (etc.) correctly. " This assumes that if you put a
123" don't put a space after +/- when it's used " as an operator, you won't
124" put a space before it either -- which is true " in code I've seen.
125"
126syntax match adaSign "[[:space:]<>=(,|:;&*/+-][+-]\d"lc=1,hs=s+1,he=e-1,me=e-1
Bram Moolenaar071d4272004-06-13 20:20:40 +0000127
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000128" Section: Labels for the goto statement. {{{1
129"
130syntax region adaLabel start="<<" end=">>"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000131
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000132" Section: Boolean Constants {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +0000133" Boolean Constants.
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000134syntax keyword adaBoolean true false
Bram Moolenaar071d4272004-06-13 20:20:40 +0000135
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000136" Section: Warn C/C++ {{{1
137"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000138" Warn people who try to use C/C++ notation erroneously:
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000139"
140syntax match adaError "//"
141syntax match adaError "/\*"
142syntax match adaError "=="
Bram Moolenaar071d4272004-06-13 20:20:40 +0000143
144
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000145" Section: Space Errors {{{1
146"
147if exists("g:ada_space_errors")
148 if !exists("g:ada_no_trail_space_error")
149 syntax match adaSpaceError excludenl "\s\+$"
150 endif
151 if !exists("g:ada_no_tab_space_error")
152 syntax match adaSpaceError " \+\t"me=e-1
153 endif
154 if !exists("g:ada_all_tab_usage")
155 syntax match adaSpecial "\t"
156 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000157endif
158
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000159" Section: end {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +0000160" Unless special ("end loop", "end if", etc.), "end" marks the end of a
161" begin, package, task etc. Assiging it to adaEnd.
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000162syntax match adaEnd "\<end\>"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000163
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000164syntax keyword adaPreproc pragma
Bram Moolenaar071d4272004-06-13 20:20:40 +0000165
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000166syntax keyword adaRepeat exit for loop reverse while
167syntax match adaRepeat "\<end\s\+loop\>"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000168
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000169syntax keyword adaStatement accept delay goto raise requeue return
170syntax keyword adaStatement terminate
171syntax match adaStatement "\<abort\>"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000172
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000173" Section: Handle Ada's record keywords. {{{1
174"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000175" 'record' usually starts a structure, but "with null record;" does not,
176" and 'end record;' ends a structure. The ordering here is critical -
177" 'record;' matches a "with null record", so make it a keyword (this can
178" match when the 'with' or 'null' is on a previous line).
179" We see the "end" in "end record" before the word record, so we match that
180" pattern as adaStructure (and it won't match the "record;" pattern).
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000181"
182syntax match adaStructure "\<record\>" contains=adaRecord
183syntax match adaStructure "\<end\s\+record\>" contains=adaRecord
184syntax match adaKeyword "\<record;"me=e-1
Bram Moolenaar071d4272004-06-13 20:20:40 +0000185
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000186" Section: type classes {{{1
187"
188syntax keyword adaStorageClass abstract access aliased array at constant delta
189syntax keyword adaStorageClass digits limited of private range tagged
190syntax keyword adaStorageClass interface synchronized
191syntax keyword adaTypedef subtype type
Bram Moolenaar071d4272004-06-13 20:20:40 +0000192
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000193" Section: Conditionals {{{1
194"
195" "abort" after "then" is a conditional of its own.
196"
197syntax match adaConditional "\<then\>"
198syntax match adaConditional "\<then\s\+abort\>"
199syntax match adaConditional "\<else\>"
200syntax match adaConditional "\<end\s\+if\>"
201syntax match adaConditional "\<end\s\+case\>"
202syntax match adaConditional "\<end\s\+select\>"
203syntax keyword adaConditional if case select
204syntax keyword adaConditional elsif when
Bram Moolenaar071d4272004-06-13 20:20:40 +0000205
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000206" Section: other keywords {{{1
207syntax match adaKeyword "\<is\>" contains=adaRecord
208syntax keyword adaKeyword all do exception in new null out
209syntax keyword adaKeyword separate until overriding
Bram Moolenaar071d4272004-06-13 20:20:40 +0000210
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000211" Section: begin keywords {{{1
212"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000213" These keywords begin various constructs, and you _might_ want to
214" highlight them differently.
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000215"
216syntax keyword adaBegin begin body declare entry generic
217syntax keyword adaBegin protected renames task
Bram Moolenaar071d4272004-06-13 20:20:40 +0000218
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000219syntax match adaBegin "\<function\>" contains=adaFunction
220syntax match adaBegin "\<procedure\>" contains=adaProcedure
221syntax match adaBegin "\<package\>" contains=adaPackage
Bram Moolenaar071d4272004-06-13 20:20:40 +0000222
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000223if exists("ada_with_gnat_project_files")
224 syntax keyword adaBegin project
225endif
226
227" Section: with, use {{{1
228"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000229if exists("ada_withuse_ordinary")
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000230 " Don't be fancy. Display "with" and "use" as ordinary keywords in all cases.
231 syntax keyword adaKeyword with use
Bram Moolenaar071d4272004-06-13 20:20:40 +0000232else
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000233 " Highlight "with" and "use" clauses like C's "#include" when they're used
234 " to reference other compilation units; otherwise they're ordinary keywords.
235 " If we have vim 6.0 or later, we'll use its advanced pattern-matching
236 " capabilities so that we won't match leading spaces.
237 syntax match adaKeyword "\<with\>"
238 syntax match adaKeyword "\<use\>"
239 syntax match adaBeginWith "^\s*\zs\(\(with\(\s\+type\)\=\)\|\(use\)\)\>" contains=adaInc
240 syntax match adaSemiWith ";\s*\zs\(\(with\(\s\+type\)\=\)\|\(use\)\)\>" contains=adaInc
241 syntax match adaInc "\<with\>" contained contains=NONE
242 syntax match adaInc "\<with\s\+type\>" contained contains=NONE
243 syntax match adaInc "\<use\>" contained contains=NONE
244 " Recognize "with null record" as a keyword (even the "record").
245 syntax match adaKeyword "\<with\s\+null\s\+record\>"
246 " Consider generic formal parameters of subprograms and packages as keywords.
247 syntax match adaKeyword ";\s*\zswith\s\+\(function\|procedure\|package\)\>"
248 syntax match adaKeyword "^\s*\zswith\s\+\(function\|procedure\|package\)\>"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000249endif
250
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000251" Section: String and character constants. {{{1
252"
253syntax region adaString contains=@Spell start=+"+ skip=+""+ end=+"+
254syntax match adaCharacter "'.'"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000255
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000256" Section: Todo (only highlighted in comments) {{{1
257"
258syntax keyword adaTodo contained TODO FIXME XXX NOTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000259
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000260" Section: Comments. {{{1
261"
262syntax region adaComment
263 \ oneline
264 \ contains=adaTodo,adaLineError,@Spell
265 \ start="--"
266 \ end="$"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000267
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000268" Section: line errors {{{1
269"
270" Note: Line errors have become quite slow with Vim 7.0
271"
272if exists("g:ada_line_errors")
273 syntax match adaLineError "\(^.\{79}\)\@<=." contains=ALL containedin=ALL
274endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000275
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000276" Section: syntax folding {{{1
277"
278" Syntax folding is very tricky - for now I still suggest to use
279" indent folding
280"
281if exists("g:ada_folding") && g:ada_folding[0] == 's'
282 if stridx (g:ada_folding, 'p') >= 0
283 syntax region adaPackage
284 \ start="\(\<package\s\+body\>\|\<package\>\)\s*\z(\k*\)"
285 \ end="end\s\+\z1\s*;"
286 \ keepend extend transparent fold contains=ALL
287 endif
288 if stridx (g:ada_folding, 'f') >= 0
289 syntax region adaProcedure
290 \ start="\<procedure\>\s*\z(\k*\)"
291 \ end="\<end\>\s\+\z1\s*;"
292 \ keepend extend transparent fold contains=ALL
293 syntax region adaFunction
294 \ start="\<procedure\>\s*\z(\k*\)"
295 \ end="end\s\+\z1\s*;"
296 \ keepend extend transparent fold contains=ALL
297 endif
298 if stridx (g:ada_folding, 'f') >= 0
299 syntax region adaRecord
300 \ start="\<is\s\+record\>"
301 \ end="\<end\s\+record\>"
302 \ keepend extend transparent fold contains=ALL
303 endif
304endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000305
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000306" Section: The default methods for highlighting. Can be overridden later. {{{1
307"
308highlight def link adaCharacter Character
309highlight def link adaComment Comment
310highlight def link adaConditional Conditional
311highlight def link adaKeyword Keyword
312highlight def link adaLabel Label
313highlight def link adaNumber Number
314highlight def link adaSign Number
315highlight def link adaOperator Operator
316highlight def link adaPreproc PreProc
317highlight def link adaRepeat Repeat
318highlight def link adaSpecial Special
319highlight def link adaStatement Statement
320highlight def link adaString String
321highlight def link adaStructure Structure
322highlight def link adaTodo Todo
323highlight def link adaType Type
324highlight def link adaTypedef Typedef
325highlight def link adaStorageClass StorageClass
326highlight def link adaBoolean Boolean
327highlight def link adaException Exception
328highlight def link adaAttribute Tag
329highlight def link adaInc Include
330highlight def link adaError Error
331highlight def link adaSpaceError Error
332highlight def link adaLineError Error
333highlight def link adaBuiltinType Type
334highlight def link adaAssignment Special
Bram Moolenaar071d4272004-06-13 20:20:40 +0000335
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000336" Subsection: Begin, End {{{2
337"
338if exists ("ada_begin_preproc")
Bram Moolenaar071d4272004-06-13 20:20:40 +0000339 " This is the old default display:
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000340 highlight def link adaBegin PreProc
341 highlight def link adaEnd PreProc
342else
Bram Moolenaar071d4272004-06-13 20:20:40 +0000343 " This is the new default display:
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000344 highlight def link adaBegin Keyword
345 highlight def link adaEnd Keyword
Bram Moolenaar071d4272004-06-13 20:20:40 +0000346endif
347
Bram Moolenaar071d4272004-06-13 20:20:40 +0000348
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000349" Section: formatoptions {{{1
350"
351setlocal formatoptions+=ron
352
353" Section: sync {{{1
354"
355" We don't need to look backwards to highlight correctly;
356" this speeds things up greatly.
357syntax sync minlines=1 maxlines=1
358
359finish " 1}}}
360
361"------------------------------------------------------------------------------
362" Copyright (C) 2006 Martin Krischik
363"
364" Vim is Charityware - see ":help license" or uganda.txt for licence details.
365"------------------------------------------------------------------------------
366"vim: textwidth=78 nowrap tabstop=8 shiftwidth=3 softtabstop=3 noexpandtab
367"vim: foldmethod=marker