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 32if exists("b:current_syntax") || version < 700 33 finish 34endif 35 36let b:current_syntax = "ada" 37 38" Section: Ada is entirely case-insensitive. {{{1 39" 40syntax case ignore 41 42" 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: 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. 48" 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 70 71" Section: others {{{1 72" 73syntax keyword adaLabel others 74 75" 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 "=" 88 89" Section: <> {{{1 90" 91" Handle the box, <>, specially: 92" 93syntax keyword adaSpecial <> 94 95" Section: rainbow color {{{1 96" 97if exists("g:ada_rainbow_color") 98 syntax match adaSpecial "[:;.,]" 99 call rainbow_parenthsis#LoadRound () 100 call rainbow_parenthsis#Activate () 101else 102 syntax match adaSpecial "[:;().,]" 103endif 104 105" Section: := {{{1 106" 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. 110" 111syntax match adaAssignment ":=" 112 113" 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_]*\)\=" 117 118" 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 126 127" Section: Labels for the goto statement. {{{1 128" 129syntax region adaLabel start="<<" end=">>" 130 131" Section: Boolean Constants {{{1 132" Boolean Constants. 133syntax keyword adaBoolean true false 134 135" Section: Warn C/C++ {{{1 136" 137" Warn people who try to use C/C++ notation erroneously: 138" 139syntax match adaError "//" 140syntax match adaError "/\*" 141syntax match adaError "==" 142 143 144" 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 156endif 157 158" Section: end {{{1 159" Unless special ("end loop", "end if", etc.), "end" marks the end of a 160" begin, package, task etc. Assiging it to adaEnd. 161syntax match adaEnd /\<end\>/ 162 163syntax keyword adaPreproc pragma 164 165syntax keyword adaRepeat exit for loop reverse while 166syntax match adaRepeat "\<end\s\+loop\>" 167 168syntax keyword adaStatement accept delay goto raise requeue return 169syntax keyword adaStatement terminate 170syntax match adaStatement "\<abort\>" 171 172" Section: Handle Ada's record keywords. {{{1 173" 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). 180" 181syntax match adaStructure "\<record\>" contains=adaRecord 182syntax match adaStructure "\<end\s\+record\>" contains=adaRecord 183syntax match adaKeyword "\<record;"me=e-1 184 185" 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 191 192" 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 204 205" 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 209 210" Section: begin keywords {{{1 211" 212" These keywords begin various constructs, and you _might_ want to 213" highlight them differently. 214" 215syntax keyword adaBegin begin body declare entry generic 216syntax keyword adaBegin protected renames task 217 218syntax match adaBegin "\<function\>" contains=adaFunction 219syntax match adaBegin "\<procedure\>" contains=adaProcedure 220syntax match adaBegin "\<package\>" contains=adaPackage 221 222if exists("ada_with_gnat_project_files") 223 syntax keyword adaBegin project 224endif 225 226" Section: with, use {{{1 227" 228if 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 231else 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\)\>" 248endif 249 250" Section: String and character constants. {{{1 251" 252syntax region adaString contains=@Spell start=+"+ skip=+""+ end=+"+ 253syntax match adaCharacter "'.'" 254 255" Section: Todo (only highlighted in comments) {{{1 256" 257syntax keyword adaTodo contained TODO FIXME XXX NOTE 258 259" Section: Comments. {{{1 260" 261syntax region adaComment 262 \ oneline 263 \ contains=adaTodo,adaLineError,@Spell 264 \ start="--" 265 \ end="$" 266 267" 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 274 275" 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 304 305" 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 334 335" Subsection: Begin, End {{{2 336" 337if exists ("ada_begin_preproc") 338 " This is the old default display: 339 highlight def link adaBegin PreProc 340 highlight def link adaEnd PreProc 341else 342 " This is the new default display: 343 highlight def link adaBegin Keyword 344 highlight def link adaEnd Keyword 345endif 346 347 348 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 364