Attachment 'vala.vim'

Download

   1 " Vim syntax file
   2 " Language:	Vala
   3 " Maintainers:	Emmanuele Bassi <ebassi@gnome.org>
   4 " 		Hans Vercammen <hveso3@gmail.com>
   5 " 		pancake <pancake@nopcode.org>
   6 " 		Sebastian Reichel <sre@ring0.de>
   7 " 		AdriĆ  Arrufat <adria.arrufat@protonmail.ch>
   8 " Last Change: 	2016-10-19
   9 " Filenames: 	*.vala *.vapi
  10 "
  11 " REFERENCES:
  12 " [1] http://live.gnome.org/Vala
  13 "
  14 " TODO: Possibly when reaching vala 1.0 release
  15 " 	- validate code attributes
  16 " 	- better error checking for known errors
  17 " 	- full support for valadoc
  18 "
  19 " 	add vala in /usr/share/vim/vim80/scripts.vim below ruby
  20 " 	to have shebang support
  21 
  22 if exists("b:current_syntax")
  23   finish
  24 endif
  25 
  26 let s:vala_cpo_save = &cpo
  27 set cpo&vim
  28 
  29 " Types
  30 syn keyword valaType			bool char double float size_t ssize_t string unichar void
  31 syn keyword valaType 			int int8 int16 int32 int64 long short
  32 syn keyword valaType 			uint uint8 uint16 uint32 uint64 ulong ushort
  33 " Container types
  34 syn match valaType			"\w\(\w\)*\(\s\+\)\?<"he=e-1,me=e-1 " Foo<Bar>
  35 " Storage keywords
  36 syn keyword valaStorage			class delegate enum errordomain interface namespace struct
  37 " repeat / condition / label
  38 syn keyword valaRepeat			break continue do for foreach return while
  39 syn keyword valaConditional		else if switch assert
  40 " User Labels
  41 syn keyword valaLabel			case default
  42 
  43 " Modifiers
  44 syn keyword valaModifier		abstract const dynamic ensures extern inline internal override 
  45 syn keyword valaModifier 		private protected public requires signal static virtual volatile weak
  46 syn keyword valaModifier 		async owned unowned
  47 " Constants
  48 syn keyword valaConstant		false null true
  49 " Exceptions
  50 syn keyword valaException		try catch finally throw
  51 " Unspecified Statements
  52 syn keyword valaUnspecifiedStatement	as base construct delete get in is lock new out params ref sizeof set this throws typeof using value var yield
  53 " Methods
  54 syn match   valaMethod			"\w\(\w\)*\(\s\+\)\?("he=e-1,me=e-1
  55 " Operators
  56 syn match   valaOperator		display "\%(+\|-\|/\|*\|=\|\^\|&\||\|!\|>\|<\|%\|?\)=\?"
  57 
  58 " Comments
  59 syn cluster valaCommentGroup 		contains=valaTodo
  60 syn keyword valaTodo 			contained TODO FIXME XXX NOTE
  61 
  62 " valadoc Comments (ported from javadoc comments in java.vim)
  63 " TODO: need to verify valadoc syntax
  64 if !exists("vala_ignore_valadoc")
  65   syn cluster valaDocCommentGroup	contains=valaDocTags,valaDocSeeTag
  66   syn region  valaDocTags 		contained start="{@\(link\|linkplain\|inherit[Dd]oc\|doc[rR]oot\|value\)" end="}"
  67   syn match   valaDocTags 		contained "@\(param\|exception\|throws\|since\)\s\+\S\+" contains=valaDocParam
  68   syn match   valaDocParam 		contained "\s\S\+"
  69   syn match   valaDocTags 		contained "@\(author\|brief\|version\|return\|deprecated\)\>"
  70   syn region  valaDocSeeTag		contained matchgroup=valaDocTags start="@see\s\+" matchgroup=NONE end="\_."re=e-1 contains=valaDocSeeTagParam
  71   syn match   valaDocSeeTagParam	contained @"\_[^"]\+"\|<a\s\+\_.\{-}</a>\|\(\k\|\.\)*\(#\k\+\((\_[^)]\+)\)\=\)\=@ extend
  72 endif
  73 
  74 " Comment Strings (ported from c.vim)
  75 if exists("vala_comment_strings")
  76   syn match  	valaCommentSkip		contained "^\s*\*\($\|\s\+\)"
  77   syn region 	valaCommentString	contained start=+L\=\\\@<!"+ skip=+\\\\\|\\"+ end=+"+ end=+\*/+me=s-1 contains=valaSpecialChar,valaCommentSkip
  78   syn region 	valaComment2String	contained start=+L\=\\\@<!"+ skip=+\\\\\|\\"+ end=+"+ end="$" contains=valaSpecialChar
  79   syn cluster 	valaCommentStringGroup 	contains=valaCommentString,valaCharacter,valaNumber
  80 
  81   syn region 	valaCommentL		start="//" end="$" keepend contains=@valaCommentGroup,valaComment2String,valaCharacter,valaNumber,valaSpaceError,@Spell
  82   syn region 	valaComment		matchgroup=valaCommentStart start="/\*" end="\*/" contains=@valaCommentGroup,@valaCommentStringGroup,valaCommentStartError,valaSpaceError,@Spell extend fold
  83   if !exists("vala_ignore_valadoc")
  84     syn region 	valaDocComment 		matchgroup=valaCommentStart start="/\*\*" end="\*/" keepend contains=@valaCommentGroup,@valaDocCommentGroup,@valaCommentStringGroup,valaCommentStartError,valaSpaceError,@Spell
  85   endif
  86 else
  87   syn region	valaCommentL		start="//" end="$" keepend contains=@valaCommentGroup,valaSpaceError,@Spell
  88   syn region	valaComment		matchgroup=valaCommentStart start="/\*" end="\*/" contains=@valaCommentGroup,valaCommentStartError,valaSpaceError,@Spell
  89   if !exists("vala_ignore_valadoc")
  90     syn region 	valaDocComment 		matchgroup=valaCommentStart start="/\*\*" end="\*/" keepend contains=@valaCommentGroup,@valaDocCommentGroup,valaCommentStartError,valaSpaceError,@Spell
  91   endif
  92 endif
  93 
  94 syn region	valaPreCondit		start="^\s*\(%:\|#\)\s*\(if\|ifdef\|ifndef\|elif\)\>" skip="\\$" end="$" end="//"me=s-1
  95 syn match	valaPreCondit		display "^\s*\(%:\|#\)\s*\(else\|endif\)\>"
  96 
  97 " Comment if 0 blocks (ported from c.vim)
  98 if !exists("vala_no_if0")
  99   syn region	valaCppOut		start="^\s*\(%:\|#\)\s*if\s\+0\+\>" end=".\@=\|$" contains=valaCppOut2 fold
 100   syn region	valaCppOut2		contained start="0" end="^\s*\(%:\|#\)\s*\(endif\>\|else\>\|elif\>\)" contains=valaSpaceError,valaCppSkip
 101   syn region	valaCppSkip		contained start="^\s*\(%:\|#\)\s*\(if\>\|ifdef\>\|ifndef\>\)" skip="\\$" end="^\s*\(%:\|#\)\s*endif\>" contains=valaSpaceError,valaCppSkip
 102 endif
 103 
 104 " match comment errors
 105 syntax match valaCommentError 		display "\*/"
 106 syntax match valaCommentStartError 	display "/\*"me=e-1 contained
 107 " match the special comment /**/
 108 syn match   valaComment		 	"/\*\*/"
 109 
 110 " Vala Code Attributes
 111 syn region  valaAttribute 		start="^\s*\[" end="\]$" contains=valaComment,valaString keepend
 112 syn region  valaAttribute 		start="\[CCode" end="\]" contains=valaComment,valaString
 113 
 114 " Avoid escaped keyword matching
 115 syn match   valaUserContent 		display "@\I*"
 116 
 117 " Strings and constants
 118 syn match   valaSpecialError		contained "\\."
 119 syn match   valaSpecialCharError	contained "[^']"
 120 syn match   valaSpecialChar		contained +\\["\\'0abfnrtvx]+
 121 syn match   valaFormatChar		contained +%\([-]\)\?\([+]\)\?\([0-9]\+\)\?\(\.\)\?\([0-9]\+\)\?[dfils%]+
 122 syn region  valaString			start=+"+  end=+"+ end=+$+ contains=valaSpecialChar,valaSpecialError,valaUnicodeNumber,@Spell,valaFormatChar
 123 syn region  valaVerbatimString		start=+"""+ end=+"""+ contains=@Spell
 124 syn match   valaUnicodeNumber		+\\\(u\x\{4}\|U\x\{8}\)+ contained contains=valaUnicodeSpecifier
 125 syn match   valaUnicodeSpecifier	+\\[uU]+ contained
 126 syn match   valaCharacter		"'[^']*'" contains=valaSpecialChar,valaSpecialCharError
 127 syn match   valaCharacter		"'\\''" contains=valaSpecialChar
 128 syn match   valaCharacter		"'[^\\]'"
 129 syn match   valaNumber			display "\<\(0[0-7]*\|0[xX]\x\+\|\d\+\)[lL]\=\>"
 130 syn match   valaNumber			display "\(\<\d\+\.\d*\|\.\d\+\)\([eE][-+]\=\d\+\)\=[fFdD]\="
 131 syn match   valaNumber			display "\<\d\+[eE][-+]\=\d\+[fFdD]\=\>"
 132 syn match   valaNumber			display "\<\d\+\([eE][-+]\=\d\+\)\=[fFdD]\>"
 133 
 134 " when wanted, highlight trailing white space
 135 if exists("vala_space_errors")
 136   if !exists("vala_no_trail_space_error")
 137     syn match valaSpaceError		display excludenl "\s\+$"
 138   endif
 139   if !exists("vala_no_tab_space_error")
 140     syn match valaSpaceError 		display " \+\t"me=e-1
 141   endif
 142 endif
 143 
 144 " when wanted, set minimum lines for comment syntax syncing
 145 if exists("vala_minlines")
 146   let b:vala_minlines = vala_minlines
 147 else
 148   let b:vala_minlines = 50
 149 endif
 150 exec "syn sync ccomment valaComment minlines=" . b:vala_minlines
 151 
 152 " code folding
 153 syn region valaBlock			start="{" end="}" transparent fold
 154 
 155 " The default highlighting.
 156 hi def link valaType			Type
 157 hi def link valaStorage			StorageClass
 158 hi def link valaRepeat			Repeat
 159 hi def link valaConditional		Conditional
 160 hi def link valaLabel			Label
 161 hi def link valaModifier		StorageClass
 162 hi def link valaConstant		Constant
 163 hi def link valaException		Exception
 164 hi def link valaUnspecifiedStatement	Statement
 165 hi def link valaUnspecifiedKeyword	Keyword
 166 hi def link valaContextualStatement	Statement
 167 hi def link valaMethod			Function
 168 hi def link valaOperator		Operator
 169 
 170 hi def link valaCommentError		Error
 171 hi def link valaCommentStartError	Error
 172 hi def link valaSpecialError		Error
 173 hi def link valaSpecialCharError	Error
 174 hi def link valaSpaceError 		Error
 175 
 176 hi def link valaTodo			Todo
 177 hi def link valaCommentL		valaComment
 178 hi def link valaCommentStart		valaComment
 179 hi def link valaCommentSkip		valaComment
 180 hi def link valaComment			Comment
 181 hi def link valaDocComment		Comment
 182 hi def link valaDocTags 		Special
 183 hi def link valaDocParam 		Function
 184 hi def link valaDocSeeTagParam 		Function
 185 hi def link valaAttribute 		PreCondit
 186 
 187 hi def link valaCommentString		valaString
 188 hi def link valaComment2String		valaString
 189 hi def link valaString			String
 190 hi def link valaVerbatimString		String
 191 hi def link valaCharacter		Character
 192 hi def link valaSpecialChar		SpecialChar
 193 hi def link valaFormatChar		SpecialChar
 194 hi def link valaNumber			Number
 195 hi def link valaUnicodeNumber		SpecialChar
 196 hi def link valaUnicodeSpecifier	SpecialChar
 197 
 198 hi def link valaPreCondit		PreCondit
 199 
 200 if !exists("vala_no_if0")
 201   hi def link valaCppSkip		valaCppOut
 202   hi def link valaCppOut2		valaCppOut
 203   hi def link valaCppOut		Comment
 204 endif
 205 
 206 let b:current_syntax = "vala"
 207 
 208 let &cpo = s:vala_cpo_save
 209 unlet s:vala_cpo_save
 210 
 211 " vim: ts=8

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2016-10-19 18:26:30, 8.9 KB) [[attachment:vala.vim]]

You are not allowed to attach a file to this page.