haxe.vim 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. " Vim syntax file
  2. " Language: haxe
  3. " Please check :help haxe.vim for comments on some of the options available.
  4. "set errorformat=%f\:%l\:\ characters\ %c-%*[^\ ]\ %m,%f\:%l\:\ %m
  5. set errorformat=%f\:%l\:\ characters\ %c-%*[^\ ]\ %m,%f\:%l\:\ %m
  6. " Quit when a syntax file was already loaded
  7. if !exists("main_syntax")
  8. if version < 600
  9. syntax clear
  10. elseif exists("b:current_syntax")
  11. finish
  12. endif
  13. " we define it here so that included files can test for it
  14. let main_syntax='haxe'
  15. endif
  16. " don't use standard HiLink, it will not work with included syntax files
  17. if version < 508
  18. command! -nargs=+ HaxeHiLink hi link <args>
  19. else
  20. command! -nargs=+ HaxeHiLink hi def link <args>
  21. endif
  22. " some characters that cannot be in a haxe program (outside a string)
  23. syn match haxeError "[\\@`]"
  24. syn match haxeError "<<<\|=>\|<>\|||=\|&&=\|\*\/"
  25. " use separate name so that it can be deleted in haxecc.vim
  26. syn match haxeError2 "#\|=<"
  27. HaxeHiLink haxeError2 haxeError
  28. " keyword definitions
  29. syn keyword haxeExternal import extern package
  30. syn keyword haxeConditional if else switch
  31. syn keyword haxeRepeat while for do in
  32. syn keyword haxeBoolean true false
  33. syn keyword haxeConstant null
  34. syn keyword haxeTypedef this super
  35. syn keyword haxeOperator new cast
  36. syn keyword haxeType Void Bool Int Float Dynamic
  37. syn keyword haxeStatement return
  38. syn keyword haxeStorageClass function var final typedef enum
  39. " syn keyword haxeStatic
  40. syn keyword haxeExceptions throw try catch finally untyped
  41. syn keyword haxeAssert assert
  42. syn keyword haxeMethodDecl synchronized throws
  43. syn keyword haxeClassDecl extends implements interface
  44. syn match haxeOperator "\.\.\."
  45. " to differentiate the keyword class from MyClass.class we use a match here
  46. syn match haxeTypedef "\.\s*\<class\>"ms=s+1
  47. syn match haxeClassDecl "^class\>"
  48. syn match haxeClassDecl "[^.]\s*\<class\>"ms=s+1
  49. syn keyword haxeBranch break continue nextgroup=haxeUserLabelRef skipwhite
  50. syn match haxeUserLabelRef "\k\+" contained
  51. syn keyword haxeScopeDecl static public protected private abstract override
  52. " haxe.lang.*
  53. syn match haxeLangClass "\<System\>"
  54. syn keyword haxeLangClass Array BasicType Class Date DateTools EReg Hash IntHash IntIter Iterator Lambda List Math Md5 Reflect Std String StringBuf StringTools Xml XmlType
  55. HaxeHiLink haxeLangClass haxeConstant
  56. HaxeHiLink haxeLangObject haxeConstant
  57. syn cluster haxeTop add=haxeLangObject,haxeLangClass
  58. syn cluster haxeClasses add=haxeLangClass
  59. if filereadable(expand("<sfile>:p:h")."/haxeid.vim")
  60. source <sfile>:p:h/haxeid.vim
  61. endif
  62. if exists("haxe_space_errors")
  63. if !exists("haxe_no_trail_space_error")
  64. syn match haxeSpaceError "\s\+$"
  65. endif
  66. if !exists("haxe_no_tab_space_error")
  67. syn match haxeSpaceError " \+\t"me=e-1
  68. endif
  69. endif
  70. syn region haxeLabelRegion transparent matchgroup=haxeLabel start="\<case\>" matchgroup=NONE end=":" contains=haxeNumber,haxeCharacter
  71. syn match haxeUserLabel "^\s*[_$a-zA-Z][_$a-zA-Z0-9_]*\s*:"he=e-1 contains=haxeLabel
  72. syn keyword haxeLabel default
  73. " The following cluster contains all haxe groups except the contained ones
  74. syn cluster haxeTop add=haxeExternal,haxeError,haxeError,haxeBranch,haxeLabelRegion,haxeLabel,haxeConditional,haxeRepeat,haxeBoolean,haxeConstant,haxeTypedef,haxeOperator,haxeType,haxeType,haxeStatement,haxeStorageClass,haxeAssert,haxeExceptions,haxeMethodDecl,haxeClassDecl,haxeClassDecl,haxeClassDecl,haxeScopeDecl,haxeError,haxeError2,haxeUserLabel,haxeLangObject
  75. " Comments
  76. syn keyword haxeTodo contained TODO FIXME XXX
  77. if exists("haxe_comment_strings")
  78. syn region haxeCommentString contained start=+"+ end=+"+ end=+$+ end=+\*/+me=s-1,he=s-1 contains=haxeSpecial,haxeCommentStar,haxeSpecialChar,@Spell
  79. syn region haxeComment2String contained start=+"+ end=+$\|"+ contains=haxeSpecial,haxeSpecialChar,@Spell
  80. syn match haxeCommentCharacter contained "'\\[^']\{1,6\}'" contains=haxeSpecialChar
  81. syn match haxeCommentCharacter contained "'\\''" contains=haxeSpecialChar
  82. syn match haxeCommentCharacter contained "'[^\\]'"
  83. syn cluster haxeCommentSpecial add=haxeCommentString,haxeCommentCharacter,haxeNumber
  84. syn cluster haxeCommentSpecial2 add=haxeComment2String,haxeCommentCharacter,haxeNumber
  85. endif
  86. syn region haxeComment start="/\*" end="\*/" contains=@haxeCommentSpecial,haxeTodo,@Spell
  87. syn match haxeCommentStar contained "^\s*\*[^/]"me=e-1
  88. syn match haxeCommentStar contained "^\s*\*$"
  89. syn match haxeLineComment "//.*" contains=@haxeCommentSpecial2,haxeTodo,@Spell
  90. HaxeHiLink haxeCommentString haxeString
  91. HaxeHiLink haxeComment2String haxeString
  92. HaxeHiLink haxeCommentCharacter haxeCharacter
  93. syn cluster haxeTop add=haxeComment,haxeLineComment
  94. if exists("haxe_haxedoc") || main_syntax == 'jsp'
  95. syntax case ignore
  96. " syntax coloring for haxedoc comments (HTML)
  97. " syntax include @haxeHtml <sfile>:p:h/html.vim
  98. " unlet b:current_syntax
  99. syn region haxeDocComment start="/\*\*" end="\*/" keepend contains=haxeCommentTitle,@haxeHtml,haxeDocTags,haxeTodo,@Spell
  100. syn region haxeCommentTitle contained matchgroup=haxeDocComment start="/\*\*" matchgroup=haxeCommentTitle keepend end="\.$" end="\.[ \t\r<&]"me=e-1 end="[^{]@"me=s-2,he=s-1 end="\*/"me=s-1,he=s-1 contains=@haxeHtml,haxeCommentStar,haxeTodo,@Spell,haxeDocTags
  101. syn region haxeDocTags contained start="{@\(link\|linkplain\|inherit[Dd]oc\|doc[rR]oot\|value\)" end="}"
  102. syn match haxeDocTags contained "@\(see\|param\|exception\|throws\|since\)\s\+\S\+" contains=haxeDocParam
  103. syn match haxeDocParam contained "\s\S\+"
  104. syn match haxeDocTags contained "@\(version\|author\|return\|deprecated\|serial\|serialField\|serialData\)\>"
  105. syntax case match
  106. endif
  107. " match the special comment /**/
  108. syn match haxeComment "/\*\*/"
  109. " Strings and constants
  110. syn match haxeSpecialError contained "\\."
  111. syn match haxeSpecialCharError contained "[^']"
  112. syn match haxeSpecialChar contained "\\\([4-9]\d\|[0-3]\d\d\|[\"\\'ntbrf]\|u\x\{4\}\)"
  113. syn match haxeEregEscape contained "\(\\\\\|\\/\)"
  114. syn region haxeEreg start=+\~\/+ end=+\/[gims]*+ contains=haxeEregEscape
  115. syn region haxeString start=+"+ end=+"+ contains=haxeSpecialChar,haxeSpecialError,@Spell
  116. syn region haxeSingleString start=+'+ end=+'+
  117. " next line disabled, it can cause a crash for a long line
  118. "syn match haxeStringError +"\([^"\\]\|\\.\)*$+
  119. syn match haxeCharacter "'[^']*'" contains=haxeSpecialChar,haxeSpecialCharError
  120. syn match haxeCharacter "'\\''" contains=haxeSpecialChar
  121. syn match haxeCharacter "'[^\\]'"
  122. syn match haxeNumber "\<\(0[0-7]*\|0[xX]\x\+\|\d\+\)[lL]\=\>"
  123. "syn match haxeNumber "\(\<\d\+\.\d*\|\.\d\+\)\([eE][-+]\=\d\+\)\=[fFdD]\="
  124. syn match haxeNumber "\(\<\d\+\.\d\+\)\([eE][-+]\=\d\+\)\=[fFdD]\="
  125. syn match haxeNumber "\<\d\+[eE][-+]\=\d\+[fFdD]\=\>"
  126. syn match haxeNumber "\<\d\+\([eE][-+]\=\d\+\)\=[fFdD]\>"
  127. syn region haxeCondIf start="#if \+!\?" end="\W" skip="([A-Za-z0-9_ |&!]\+)"
  128. syn region haxeCondElse start="#else \+!\?" end="\W" skip="([A-Za-z0-9_ |&!]\+)"
  129. syn match haxeCondEnd "#end"
  130. syn match haxeCondError "#else *$"
  131. " unicode characters
  132. syn match haxeSpecial "\\u\d\{4\}"
  133. syn cluster haxeTop add=haxeString,haxeCharacter,haxeNumber,haxeSpecial,haxeStringError
  134. if exists("haxe_highlight_functions")
  135. if haxe_highlight_functions == "indent"
  136. syn match haxeFuncDef "^\(\t\| \{8\}\)[_$a-zA-Z][_$a-zA-Z0-9_. \[\]]*([^-+*/()]*)" contains=haxeScopeDecl,haxeType,haxeStorageClass,@haxeClasses
  137. syn region haxeFuncDef start=+^\(\t\| \{8\}\)[$_a-zA-Z][$_a-zA-Z0-9_. \[\]]*([^-+*/()]*,\s*+ end=+)+ contains=haxeScopeDecl,haxeType,haxeStorageClass,@haxeClasses
  138. syn match haxeFuncDef "^ [$_a-zA-Z][$_a-zA-Z0-9_. \[\]]*([^-+*/()]*)" contains=haxeScopeDecl,haxeType,haxeStorageClass,@haxeClasses
  139. syn region haxeFuncDef start=+^ [$_a-zA-Z][$_a-zA-Z0-9_. \[\]]*([^-+*/()]*,\s*+ end=+)+ contains=haxeScopeDecl,haxeType,haxeStorageClass,@haxeClasses
  140. else
  141. " This line catches method declarations at any indentation>0, but it assumes
  142. " two things:
  143. " 1. class names are always capitalized (ie: Button)
  144. " 2. method names are never capitalized (except constructors, of course)
  145. syn region haxeFuncDef start=+^\s\+\(\(public\|protected\|private\|static\|abstract\|override\|final\|native\|synchronized\)\s\+\)*\(\(void\|boolean\|char\|byte\|short\|int\|long\|float\|double\|\([A-Za-z_][A-Za-z0-9_$]*\.\)*[A-Z][A-Za-z0-9_$]*\)\(\[\]\)*\s\+[a-z][A-Za-z0-9_$]*\|[A-Z][A-Za-z0-9_$]*\)\s*(+ end=+)+ contains=haxeScopeDecl,haxeType,haxeStorageClass,haxeComment,haxeLineComment,@haxeClasses
  146. endif
  147. syn match haxeBraces "[{}]"
  148. syn cluster haxeTop add=haxeFuncDef,haxeBraces
  149. endif
  150. if exists("haxe_mark_braces_in_parens_as_errors")
  151. syn match haxeInParen contained "[{}]"
  152. HaxeHiLink haxeInParen haxeError
  153. syn cluster haxeTop add=haxeInParen
  154. endif
  155. " catch errors caused by wrong parenthesis
  156. syn region haxeParenT transparent matchgroup=haxeParen start="(" end=")" contains=@haxeTop,haxeParenT1
  157. syn region haxeParenT1 transparent matchgroup=haxeParen1 start="(" end=")" contains=@haxeTop,haxeParenT2 contained
  158. syn region haxeParenT2 transparent matchgroup=haxeParen2 start="(" end=")" contains=@haxeTop,haxeParenT contained
  159. syn match haxeParenError ")"
  160. HaxeHiLink haxeParenError haxeError
  161. if !exists("haxe_minlines")
  162. let haxe_minlines = 10
  163. endif
  164. exec "syn sync ccomment haxeComment minlines=" . haxe_minlines
  165. " The default highlighting.
  166. if version >= 508 || !exists("did_haxe_syn_inits")
  167. if version < 508
  168. let did_haxe_syn_inits = 1
  169. endif
  170. HaxeHiLink haxeFuncDef Function
  171. HaxeHiLink haxeBraces Function
  172. HaxeHiLink haxeBranch Conditional
  173. HaxeHiLink haxeUserLabelRef haxeUserLabel
  174. HaxeHiLink haxeLabel Label
  175. HaxeHiLink haxeUserLabel Label
  176. HaxeHiLink haxeConditional Conditional
  177. HaxeHiLink haxeRepeat Repeat
  178. HaxeHiLink haxeExceptions Exception
  179. HaxeHiLink haxeAssert Statement
  180. HaxeHiLink haxeStatic MoreMsg
  181. HaxeHiLink haxeStorageClass StorageClass
  182. HaxeHiLink haxeMethodDecl haxeStorageClass
  183. HaxeHiLink haxeClassDecl haxeStorageClass
  184. HaxeHiLink haxeScopeDecl haxeStorageClass
  185. HaxeHiLink haxeBoolean Boolean
  186. HaxeHiLink haxeSpecial Special
  187. HaxeHiLink haxeSpecialError Error
  188. HaxeHiLink haxeSpecialCharError Error
  189. HaxeHiLink haxeString String
  190. HaxeHiLink haxeSingleString String
  191. HaxeHiLink haxeEreg Special
  192. HaxeHiLink haxeEregEscape Special
  193. HaxeHiLink haxeCharacter Character
  194. HaxeHiLink haxeSpecialChar SpecialChar
  195. HaxeHiLink haxeNumber Number
  196. HaxeHiLink haxeError Error
  197. HaxeHiLink haxeStringError Error
  198. HaxeHiLink haxeStatement Statement
  199. HaxeHiLink haxeOperator Operator
  200. HaxeHiLink haxeComment Comment
  201. HaxeHiLink haxeDocComment Comment
  202. HaxeHiLink haxeLineComment Comment
  203. HaxeHiLink haxeConstant Constant
  204. HaxeHiLink haxeTypedef Typedef
  205. HaxeHiLink haxeTodo Todo
  206. HaxeHiLink haxeCommentTitle SpecialComment
  207. HaxeHiLink haxeDocTags Special
  208. HaxeHiLink haxeDocParam Function
  209. HaxeHiLink haxeCommentStar haxeComment
  210. HaxeHiLink haxeType Type
  211. HaxeHiLink haxeExternal Include
  212. HaxeHiLink htmlComment Special
  213. HaxeHiLink htmlCommentPart Special
  214. HaxeHiLink haxeSpaceError Error
  215. HaxeHiLink haxeCondIf Macro
  216. HaxeHiLink haxeCondElse Macro
  217. HaxeHiLink haxeCondEnd Macro
  218. HaxeHiLink haxeCondError Error
  219. endif
  220. delcommand HaxeHiLink
  221. let b:current_syntax = "haxe"
  222. if main_syntax == 'haxe'
  223. unlet main_syntax
  224. endif
  225. let b:spell_options="contained"
  226. " vim: ts=8