Skip to content

Instantly share code, notes, and snippets.

@deltaluca
Last active December 21, 2015 15:59
Show Gist options
  • Save deltaluca/6330630 to your computer and use it in GitHub Desktop.
Save deltaluca/6330630 to your computer and use it in GitHub Desktop.
Improved haxe syntax file for vim http://i.imgur.com/ViMwoeh.png
" Vim syntax file
" Language: Haxe
" Maintainer: Luca Deltodesco <[email protected]>
" Last Change: 2013 August 26
if exists("b:current_syntax")
finish
endif
command! -nargs=+ HaxeHiLink hi def link <args>
" characters that cannot be in a haxe program (outside a string)
syn match haxeError "[\\`]"
" keywords
" --------
syn keyword haxeTypedef typedef extends implements
syn keyword haxeTypeDecl class enum abstract interface import using package from to
syn keyword haxeStorageClass static inline public private macro dynamic extern override
syn keyword haxeException try catch throw
syn keyword haxeRepeat for do while in
syn keyword haxeLabel case
syn keyword haxeConditional switch
syn match haxeConditional "\<\#\@<!\(if\|else\)\>"
syn keyword haxeConstant null never super this default get set
syn keyword haxeFunction function __dollar__new new
syn match haxeFunction "\<__[^_]\+__\>"
syn keyword haxeKeyword untyped cast continue break return trace var
syn match haxeKeyword "\$type"
syn match haxeError "\<#\@<!elseif\>"
" type identifiers
" ----------------
syn match haxeType "\<[A-Z][a-zA-Z_0-9]*\>"
" operators
" ---------
" Did a lot of work here to ensure a lot of invalid operators are highlighted as errors.
" put ,; in seperate highlight group to .: to avoid mistakes.
syn match haxeOperator "[:?]"
syn match haxeOperator2 "[;,]"
" match . and ... as operators, and .. and more than 4 . as errors
syn match haxeOperator "\.\@<!\(\.\|\.\.\.\)\.\@!"
syn match haxeError "\.\@<!\.\.\.\@!"
syn match haxeError "\.\{4,\}"
" match <,>,<<,>>,>>> as operators and more than 3 < or more than 4 > as errors
syn match haxeOperator ">\@<!\(>\|>>\|>>>\)>\@!"
syn match haxeOperator "<\@<!\(<\|<<\)<\@!"
syn match haxeError ">\{4,\}\|<\{3,}"
" match &| in 1 or 2 as operator, and more than 2 as error
" match &&= and ||= as errors
syn match haxeOperator "&\@<!&&\?&\@!"
syn match haxeOperator "|\@<!||\?|\@!"
syn match haxeError "&\{3,\}\||\{3,}\|&&=\|||="
" match = in 1 or 2 as operator, and more than 2 as error
" match !== as an error
syn match haxeOperator "=\@<!==\?=\@!"
syn match haxeError "=\{3,\}\|!=="
" match (+-*/%&!<>)=? as operators
" have to match &!<> seperate to avoid highlighting things like &&= &&& <<< as okay
syn match haxeOperator "[+\-*/%^!]=\?=\@!"
syn match haxeOperator "<\@<!<=\?[=<]\@!"
syn match haxeOperator ">\@<![>]=\?[=>]\@!"
syn match haxeOperator "&\@<!&=\?[=&]\@!"
syn match haxeOperator "|\@<!|=\?[=|]\@!"
" string literals
" ---------------
" Did a lot of work to ensure that string interpolations are handled nicely
syn match haxeErrorCharacter contained "\\\(x.\{0,2}\|u.\{0,4\}\|[^"'\\/nrt]\)"
syn match haxeSpecialCharacter contained "\\\(x[a-fA-F0-9]\{2\}\|[0-7]\{3\}\|["'\\/nrt]\)"
syn match haxeIntSpecialChar contained "\$\@<!\(\$\$\)\+\(\(\$\$\)\+\)\@!"
syn match haxeInterpolatedIdent contained "\((\$\$)\+\)\@<!\$[a-zA-Z_][a-zA-Z_0-9]*"
syn region haxeInterpolated contained start=+\((\$\$)\+\)\@<!\${+ end=+}+ contains=TOP
syn region haxeDString start=+"+ end=+"+ contains=haxeSpecialCharacter,haxeErrorCharacter,@Spell
syn region haxeSString start=+'+ end=+'+ contains=haxeSpecialCharacter,haxeErrorCharacter,haxeIntSpecialChar,haxeInterpolatedIdent,haxeInterpolated,@Spell
" int/float/bool literal
" ----------------------
syn match haxeInt "\<\([0-9]\+\|0x[0-9a-fA-F]\+\)\>"
syn match haxeFloat "\<\([\-+]\?[0-9]*\.\?[0-9]\+([eE][\-+]\?[0-9]\+)\?\)\>"
syn keyword haxeBool true false
" comments
" --------
syn keyword haxeTODO contained TODO FIXME XXX
syn match haxeComment "//.*" contains=haxeTODO,@Spell
syn region haxeComment2 start=+/\*+ end=+\*/+ contains=haxeTODO,@Spell
" preprocessing
" -------------
syn match haxePre "\(#if\|#elseif\|#else\|#end\)"
syn match haxePreError "#error"
" regex
" -----
syn region haxeRegex start=+\~\/+ end=+\/+ contains=haxeSpecialCharacter,haxeErrorCharacter,@Spell
" meta
" ----
syn match haxeMeta "@:\?[a-zA-Z_][a-zA-Z_0-9]*\>"
syn match haxeCompilerMeta "@:\(abstract\|access\|allow\|annotation\|arrayAccess\|autoBuild\|bind\|bitmap\|build\|buildXml\|classCode\|commutative\|compilerGenerated\|coreApi\|coreType\|cppFileCode\|cppNamespaceCode\|debug\|decl\|defParam\|depend\|deprecated\|expose\|extern\|fakeEnum\|file\|final\|font\|from\|functionCode\|functionTailCode\|generic\|getter\|hack\|headerClassCode\|headerCode\|headerNamespaceCode\|hxGen\|ifFeature\|include\|initPackage\|internal\|isVar\|keep\|keepInit\|keepSub\|macro\|meta\|multiType\|native\|nativeGen\|noCompletion\|noDebug\|noDoc\|noImportGlobal\|noPackageRestrict\|noStack\|noUsing\|notNull\|ns\|op\|optional\|overload\|privateAccess\|protected\|public\|publicFields\|readOnly\|remove\|require\|rtti\|runtime\|runtimeValue\|setter\|sound\|struct\|suppressWarnings\|throws\|to\|transient\|unifyMinDynamic\|unreflective\|unsafe\|usage\|volatile\)\>"
HaxeHiLink haxeMeta Macro
HaxeHiLink haxeCompilerMeta Identifier
HaxeHiLink haxeRegex String
HaxeHiLink haxeDString String
HaxeHiLink haxeSString Character
HaxeHiLink haxeSpecialCharacter SpecialChar
HaxeHiLink haxeIntSpecialChar SpecialChar
HaxeHiLink haxeErrorCharacter Error
HaxeHiLink haxeInterpolatedIdent Normal
HaxeHiLink haxeInterpolated Normal
HaxeHiLink haxeError Error
HaxeHiLink haxeOperator Operator
HaxeHiLink haxeOperator2 Identifier
HaxeHiLink haxeSpecial SpecialChar
HaxeHiLink haxeInt Number
HaxeHiLink haxeFloat Float
HaxeHiLink haxeBool Boolean
HaxeHiLink haxeComment Comment
HaxeHiLink haxeComment2 Comment
HaxeHiLink haxeTODO Todo
HaxeHiLink haxePre PreCondit
HaxeHiLink haxePreError PreProc
HaxeHiLink haxeType Type
HaxeHiLink haxeTypedef Typedef
HaxeHiLink haxeTypeDecl Keyword " Structure just gives me same colour as Type and looks bad.
HaxeHiLink haxeStorageClass StorageClass
HaxeHiLink haxeException Exception
HaxeHiLink haxeRepeat Repeat
HaxeHiLink haxeLabel Label
HaxeHiLink haxeConditional Conditional
HaxeHiLink haxeConstant Constant
HaxeHiLink haxeFunction Function
HaxeHiLink haxeKeyword Keyword
delcommand HaxeHiLink
let b:current_syntax = "haxe"
let b:spell_options = "contained"
" vim: ts=8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment