blob: 7a7b2a0774f3e9175fc02ea7bb5982e75e4d2c3d [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim syntax file
2" Language: Ada (95)
3" Maintainer: David A. Wheeler <dwheeler@dwheeler.com>
4" URL: http://www.dwheeler.com/vim
5" Last Change: 2001-11-02
6
7" Former Maintainer: Simon Bradley <simon.bradley@pitechnology.com>
8" (was <sib93@aber.ac.uk>)
9" Other contributors: Preben Randhol.
10" The formal spec of Ada95 (ARM) is the "Ada95 Reference Manual".
11" For more Ada95 info, see http://www.gnuada.org and http://www.adapower.com.
12
13" This vim syntax file works on vim 5.6, 5.7, 5.8 and 6.x.
14" It implements Bram Moolenaar's April 25, 2001 recommendations to make
15" the syntax file maximally portable across different versions of vim.
16" If vim 6.0+ is available,
17" this syntax file takes advantage of the vim 6.0 advanced pattern-matching
18" functions to avoid highlighting uninteresting leading spaces in
19" some expressions containing "with" and "use".
20
21" For version 5.x: Clear all syntax items
22" For version 6.x: Quit when a syntax file was already loaded
23if version < 600
24 syntax clear
25elseif exists("b:current_syntax")
26 finish
27endif
28
29" Ada is entirely case-insensitive.
30syn case ignore
31
32" We don't need to look backwards to highlight correctly;
33" this speeds things up greatly.
34syn sync minlines=1 maxlines=1
35
36" Highlighting commands. There are 69 reserved words in total in Ada95.
37" Some keywords are used in more than one way. For example:
38" 1. "end" is a general keyword, but "end if" ends a Conditional.
39" 2. "then" is a conditional, but "and then" is an operator.
40
41
42" Standard Exceptions (including I/O).
43" We'll highlight the standard exceptions, similar to vim's Python mode.
44" It's possible to redefine the standard exceptions as something else,
45" but doing so is very bad practice, so simply highlighting them makes sense.
46syn keyword adaException Constraint_Error Program_Error Storage_Error
47syn keyword adaException Tasking_Error
48syn keyword adaException Status_Error Mode_Error Name_Error Use_Error
49syn keyword adaException Device_Error End_Error Data_Error Layout_Error
50syn keyword adaException Length_Error Pattern_Error Index_Error
51syn keyword adaException Translation_Error
52syn keyword adaException Time_Error Argument_Error
53syn keyword adaException Tag_Error
54syn keyword adaException Picture_Error
55" Interfaces
56syn keyword adaException Terminator_Error Conversion_Error
57syn keyword adaException Pointer_Error Dereference_Error Update_Error
58" This isn't in the Ada spec, but a GNAT extension.
59syn keyword adaException Assert_Failure
60" We don't list ALL exceptions defined in particular compilers (e.g., GNAT),
61" because it's quite reasonable to define those phrases as non-exceptions.
62
63
64" We don't normally highlight types in package Standard
65" (Integer, Character, Float, etc.). I don't think it looks good
66" with the other type keywords, and many Ada programs define
67" so many of their own types that it looks inconsistent.
68" However, if you want this highlighting, turn on "ada_standard_types".
69" For package Standard's definition, see ARM section A.1.
70
71if exists("ada_standard_types")
72 syn keyword adaBuiltinType Boolean Integer Natural Positive Float
73 syn keyword adaBuiltinType Character Wide_Character
74 syn keyword adaBuiltinType String Wide_String
75 syn keyword adaBuiltinType Duration
76 " These aren't listed in ARM section A.1's code, but they're noted as
77 " options in ARM sections 3.5.4 and 3.5.7:
78 syn keyword adaBuiltinType Short_Integer Short_Short_Integer
79 syn keyword adaBuiltinType Long_Integer Long_Long_Integer
80 syn keyword adaBuiltinType Short_Float Short_Short_Float
81 syn keyword adaBuiltinType Long_Float Long_Long_Float
82endif
83
84" There are MANY other predefined types; they've not been added, because
85" determining when they're a type requires context in general.
86" One potential addition would be Unbounded_String.
87
88
89syn keyword adaLabel others
90
91syn keyword adaOperator abs mod not rem xor
92syn match adaOperator "\<and\>"
93syn match adaOperator "\<and\s\+then\>"
94syn match adaOperator "\<or\>"
95syn match adaOperator "\<or\s\+else\>"
96syn match adaOperator "[-+*/<>&]"
97syn keyword adaOperator **
98syn match adaOperator "[/<>]="
99syn keyword adaOperator =>
100syn match adaOperator "\.\."
101syn match adaOperator "="
102
103" We won't map "adaAssignment" by default, but we need to map ":=" to
104" something or the "=" inside it will be mislabelled as an operator.
105" Note that in Ada, assignment (:=) is not considered an operator.
106syn match adaAssignment ":="
107
108" Handle the box, <>, specially:
109syn keyword adaSpecial <>
110
111" Numbers, including floating point, exponents, and alternate bases.
112syn match adaNumber "\<\d[0-9_]*\(\.\d[0-9_]*\)\=\([Ee][+-]\=\d[0-9_]*\)\=\>"
113syn match adaNumber "\<\d\d\=#\x[0-9A-Fa-f_]*\(\.\x[0-9A-Fa-f_]*\)\=#\([Ee][+-]\=\d[0-9_]*\)\="
114
115" Identify leading numeric signs. In "A-5" the "-" is an operator,
116" but in "A:=-5" the "-" is a sign. This handles "A3+-5" (etc.) correctly.
117" This assumes that if you put a don't put a space after +/- when it's used
118" as an operator, you won't put a space before it either -- which is true
119" in code I've seen.
120syn match adaSign "[[:space:]<>=(,|:;&*/+-][+-]\d"lc=1,hs=s+1,he=e-1,me=e-1
121
122" Labels for the goto statement.
123syn region adaLabel start="<<" end=">>"
124
125" Boolean Constants.
126syn keyword adaBoolean true false
127
128" Warn people who try to use C/C++ notation erroneously:
129syn match adaError "//"
130syn match adaError "/\*"
131syn match adaError "=="
132
133
134if exists("ada_space_errors")
135 if !exists("ada_no_trail_space_error")
136 syn match adaSpaceError excludenl "\s\+$"
137 endif
138 if !exists("ada_no_tab_space_error")
139 syn match adaSpaceError " \+\t"me=e-1
140 endif
141endif
142
143" Unless special ("end loop", "end if", etc.), "end" marks the end of a
144" begin, package, task etc. Assiging it to adaEnd.
145syn match adaEnd "\<end\>"
146
147syn keyword adaPreproc pragma
148
149syn keyword adaRepeat exit for loop reverse while
150syn match adaRepeat "\<end\s\+loop\>"
151
152syn keyword adaStatement accept delay goto raise requeue return
153syn keyword adaStatement terminate
154syn match adaStatement "\<abort\>"
155
156" Handle Ada's record keywords.
157" 'record' usually starts a structure, but "with null record;" does not,
158" and 'end record;' ends a structure. The ordering here is critical -
159" 'record;' matches a "with null record", so make it a keyword (this can
160" match when the 'with' or 'null' is on a previous line).
161" We see the "end" in "end record" before the word record, so we match that
162" pattern as adaStructure (and it won't match the "record;" pattern).
163syn match adaStructure "\<record\>"
164syn match adaStructure "\<end\s\+record\>"
165syn match adaKeyword "\<record;"me=e-1
166
167syn keyword adaStorageClass abstract access aliased array at constant delta
168syn keyword adaStorageClass digits limited of private range tagged
169syn keyword adaTypedef subtype type
170
171" Conditionals. "abort" after "then" is a conditional of its own.
172syn match adaConditional "\<then\>"
173syn match adaConditional "\<then\s\+abort\>"
174syn match adaConditional "\<else\>"
175syn match adaConditional "\<end\s\+if\>"
176syn match adaConditional "\<end\s\+case\>"
177syn match adaConditional "\<end\s\+select\>"
178syn keyword adaConditional if case select
179syn keyword adaConditional elsif when
180
181syn keyword adaKeyword all do exception in is new null out
182syn keyword adaKeyword separate until
183
184" These keywords begin various constructs, and you _might_ want to
185" highlight them differently.
186syn keyword adaBegin begin body declare entry function generic
187syn keyword adaBegin package procedure protected renames task
188
189
190if exists("ada_withuse_ordinary")
191" Don't be fancy. Display "with" and "use" as ordinary keywords in all cases.
192 syn keyword adaKeyword with use
193else
194 " Highlight "with" and "use" clauses like C's "#include" when they're used
195 " to reference other compilation units; otherwise they're ordinary keywords.
196 " If we have vim 6.0 or later, we'll use its advanced pattern-matching
197 " capabilities so that we won't match leading spaces.
198 syn match adaKeyword "\<with\>"
199 syn match adaKeyword "\<use\>"
200 if version < 600
201 syn match adaBeginWith "^\s*\(\(with\(\s\+type\)\=\)\|\(use\)\)\>" contains=adaInc
202 syn match adaSemiWith ";\s*\(\(with\(\s\+type\)\=\)\|\(use\)\)\>"lc=1 contains=adaInc
203 else
204 syn match adaBeginWith "^\s*\zs\(\(with\(\s\+type\)\=\)\|\(use\)\)\>" contains=adaInc
205 syn match adaSemiWith ";\s*\zs\(\(with\(\s\+type\)\=\)\|\(use\)\)\>" contains=adaInc
206 endif
207 syn match adaInc "\<with\>" contained contains=NONE
208 syn match adaInc "\<with\s\+type\>" contained contains=NONE
209 syn match adaInc "\<use\>" contained contains=NONE
210 " Recognize "with null record" as a keyword (even the "record").
211 syn match adaKeyword "\<with\s\+null\s\+record\>"
212 " Consider generic formal parameters of subprograms and packages as keywords.
213 if version < 600
214 syn match adaKeyword ";\s*with\s\+\(function\|procedure\|package\)\>"
215 syn match adaKeyword "^\s*with\s\+\(function\|procedure\|package\)\>"
216 else
217 syn match adaKeyword ";\s*\zswith\s\+\(function\|procedure\|package\)\>"
218 syn match adaKeyword "^\s*\zswith\s\+\(function\|procedure\|package\)\>"
219 endif
220endif
221
222
223" String and character constants.
224syn region adaString start=+"+ skip=+""+ end=+"+
225syn match adaCharacter "'.'"
226
227" Todo (only highlighted in comments)
228syn keyword adaTodo contained TODO FIXME XXX
229
230" Comments.
231syn region adaComment oneline contains=adaTodo start="--" end="$"
232
233
234
235" Define the default highlighting.
236" For version 5.7 and earlier: only when not done already
237" For version 5.8 and later: only when an item doesn't have highlighting yet
238if version >= 508 || !exists("did_ada_syn_inits")
239 if version < 508
240 let did_ada_syn_inits = 1
241 command -nargs=+ HiLink hi link <args>
242 else
243 command -nargs=+ HiLink hi def link <args>
244 endif
245
246 " The default methods for highlighting. Can be overridden later.
247 HiLink adaCharacter Character
248 HiLink adaComment Comment
249 HiLink adaConditional Conditional
250 HiLink adaKeyword Keyword
251 HiLink adaLabel Label
252 HiLink adaNumber Number
253 HiLink adaSign Number
254 HiLink adaOperator Operator
255 HiLink adaPreproc PreProc
256 HiLink adaRepeat Repeat
257 HiLink adaSpecial Special
258 HiLink adaStatement Statement
259 HiLink adaString String
260 HiLink adaStructure Structure
261 HiLink adaTodo Todo
262 HiLink adaType Type
263 HiLink adaTypedef Typedef
264 HiLink adaStorageClass StorageClass
265 HiLink adaBoolean Boolean
266 HiLink adaException Exception
267 HiLink adaInc Include
268 HiLink adaError Error
269 HiLink adaSpaceError Error
270 HiLink adaBuiltinType Type
271
272 if exists("ada_begin_preproc")
273 " This is the old default display:
274 HiLink adaBegin PreProc
275 HiLink adaEnd PreProc
276 else
277 " This is the new default display:
278 HiLink adaBegin Keyword
279 HiLink adaEnd Keyword
280 endif
281
282 delcommand HiLink
283endif
284
285let b:current_syntax = "ada"
286
287" vim: ts=8