luau.vim (12275B)
1 " Vim syntax file 2 " Language: Luau 3 " Maintainer: Lopy (@lopi-py) 4 " Last Change: 2026 Jun 17 5 6 " quit when a syntax file was already loaded 7 if exists("b:current_syntax") 8 finish 9 endif 10 11 let s:cpo_save = &cpo 12 set cpo&vim 13 14 syn case match 15 syn sync minlines=300 16 17 " comments 18 syn keyword luauTodo contained TODO FIXME 19 syn match luauDirective contained "--!\%(strict\|nonstrict\|nocheck\|nolint\%(Global\)\=\|native\|optimize\)\>.*" 20 21 " strings 22 syn match luauSpecial contained #\\[[:digit:]]\{1,3}\|\\x[[:xdigit:]]\{2}\|\\u{[[:xdigit:]]\+}\|\\z\s*\|\\\n\|\\[^xu[:digit:]\r\n]# 23 syn region luauString2 matchgroup=luauStringDelimiter start="\[\z(=*\)\[" end="\]\z1\]" contains=@Spell 24 syn region luauString matchgroup=luauStringDelimiter start=+'+ end=+'+ skip=+\\\\\|\\'+ contains=luauSpecial,@Spell 25 syn region luauString matchgroup=luauStringDelimiter start=+"+ end=+"+ skip=+\\\\\|\\"+ contains=luauSpecial,@Spell 26 syn region luauInterpString matchgroup=luauStringDelimiter start=+`+ end=+`+ skip=+\\`+ contains=luauSpecial,luauInterp,@Spell 27 syn region luauInterp contained transparent matchgroup=luauInterpDelimiter start=+\\\@<!{+ end=+}+ contains=TOP,luauInterpBlock 28 syn region luauInterpBlock contained transparent start=+{+ end=+}+ contains=TOP,luauInterpBlock 29 30 " numbers 31 syn match luauNumber "\<0_*[xX][[:xdigit:]_]*[[:xdigit:]][[:xdigit:]_]*\>" 32 syn match luauNumber "\<0_*[bB][01_]*[01][01_]*\>" 33 syn match luauNumber "\<\d[[:digit:]_]*\%(\.[[:digit:]_]*\)\=\%([eE][-+]\=[[:digit:]_]*\d[[:digit:]_]*\)\=\>" 34 syn match luauNumber "\.\d[[:digit:]_]*\%([eE][-+]\=[[:digit:]_]*\d[[:digit:]_]*\)\=\>" 35 36 " keywords 37 syn keyword luauStatement return local break end 38 syn keyword luauStatement do nextgroup=luauStatement skipwhite 39 syn keyword luauStatement contained continue 40 syn match luauStatement "^\s*\zscontinue\>\ze\s*\%(;\|end\>\|else\>\|elseif\>\|until\>\|--.*\|$\)" 41 syn match luauStatement ";\s*\zscontinue\>\ze\s*\%(;\|end\>\|else\>\|elseif\>\|until\>\|--.*\|$\)" 42 syn keyword luauFunction function nextgroup=luauFunctionName,luauGenericParams skipwhite 43 syn match luauStatement "^\s*\%(@\%(\h\w*\|\[[^]]*\]\)\s*\)*\zsconst\>\ze\s\+\%(function\>\|\h\)" 44 syn match luauStatement "^\s*\%(@\%(\h\w*\|\[[^]]*\]\)\s*\)*\zsdeclare\>\ze\s\+\%(function\>\|class\>\s\+\h\|extern\s\+type\>\|\h\w*\s*:\)" nextgroup=luauStatement,luauDeclareName,luauFunction skipwhite 45 syn match luauStatement contained "\<class\>\ze\s\+\h" nextgroup=luauTypedef skipwhite 46 syn match luauDeclareName contained "\h\w*\ze\s*:" nextgroup=luauTypeColon skipwhite 47 syn match luauStatement "\<export\>\ze\s\+type\>" 48 syn match luauStatement contained "\<extern\>\ze\s\+type\>" 49 syn match luauStatement "\<extends\>\ze\s\+\h" nextgroup=luauTypeName skipwhite 50 syn match luauStatement "\<with\>\ze\s*\%(--.*\)\=$" 51 syn match luauModifier "\<public\>\ze\s\+\%(function\|\h\)" 52 syn match luauTypeKeyword "\<type\>\ze\s\+\h" nextgroup=luauTypeFunction,luauTypedef skipwhite 53 syn keyword luauTypeFunction contained function nextgroup=luauFunctionName skipwhite 54 syn match luauFunctionName contained transparent "\h\w*\%([.:]\h\w*\)*" nextgroup=luauGenericParams skipwhite 55 syn keyword luauCond if elseif 56 syn keyword luauCond then else nextgroup=luauStatement skipwhite 57 syn keyword luauRepeat while for until in 58 syn keyword luauRepeat repeat nextgroup=luauStatement skipwhite 59 syn keyword luauOperator and or not 60 61 " operators and punctuation 62 syn match luauSymbolOperator "[#+*/%^=<>~?-]\|\.\{3}\|\.\.=\=" 63 syn match luauSymbolOperator "->" nextgroup=luauSymbolOperator,luauConstant,luauTableType,luauTypePack,luauTypeName skipwhite 64 syn match luauSymbolOperator "[|&]" nextgroup=luauConstant,luauTableType,luauTypePack,luauTypeName skipwhite 65 syn match luauSymbolOperator "::" 66 67 " tables 68 syn region luauTableBlock transparent matchgroup=luauTable start="{" end="}" contains=TOP,luauStatement 69 70 syn match luauComment "--.*$" contains=luauTodo,luauDirective,@Spell 71 syn region luauComment matchgroup=luauCommentDelimiter start="--\[\z(=*\)\[" end="\]\z1\]" contains=luauTodo,@Spell 72 73 " the first line may start with #! 74 syn match luauComment "\%^#!.*" 75 76 " attributes 77 syn match luauAttribute "@\h\w*" 78 syn region luauAttributeBlock matchgroup=luauAttributeDelimiter start="@\[" end="\]" contains=luauAttributeName,luauAttributeTable,luauString,luauString2,luauInterpString,luauNumber,luauConstant 79 syn region luauAttributeTable contained transparent matchgroup=luauTable start="{" end="}" contains=luauAttributeTable,luauString,luauString2,luauInterpString,luauNumber,luauConstant,luauSymbolOperator 80 syn keyword luauAttributeName contained checked native deprecated 81 82 " constants and types 83 syn keyword luauConstant nil true false 84 syn match luauConstant "\.\.\." 85 syn keyword luauSelf self 86 syn match luauSelf contained "(\s*\zsself\>\ze\s*:" 87 syn cluster luauTypeCommon contains=luauGenericParams,luauString,luauString2,luauInterpString,luauNumber,luauConstant,luauSymbolOperator 88 syn cluster luauTypeExpr contains=luauFunctionTypeParams,luauTableType,luauTypeParam,luauType,luauTypeKeyword,@luauTypeCommon 89 syn region luauGenericParams contained transparent matchgroup=luauSymbolOperator start="<" end=">" contains=@luauTypeExpr 90 syn region luauTypedefGenericParams contained transparent matchgroup=luauSymbolOperator start="<" end=">" contains=@luauTypeExpr nextgroup=luauTypeAliasAssign skipwhite 91 syn region luauExplicitTypeArgs transparent matchgroup=luauSymbolOperator start="<<" end=">>" contains=@luauTypeExpr 92 syn match luauTypeParam contained "\h\w*\%(\.\.\.\)\=" 93 syn match luauTypedef "\h\w*" contained nextgroup=luauTypedefGenericParams,luauTypeAliasAssign skipwhite 94 syn match luauTypeAliasAssign contained "=" nextgroup=luauSymbolOperator,luauConstant,luauTableType,luauTypeName skipwhite 95 syn region luauTableType contained transparent matchgroup=luauTable start="{" end="}" contains=luauFunctionTypeParams,luauTableType,luauSelf,luauTypeIndexer,luauTableElementType,luauTypeColon,luauTypeKeyword,@luauTypeCommon 96 syn match luauTypeIndexer "^\s*\[\s*" nextgroup=luauType skipwhite 97 syn match luauTypeIndexer contained transparent "\[\s*" nextgroup=luauType skipwhite 98 syn match luauType contained "\h\w*\%(\.\h\w*\)*\ze\s*\]\s*:" nextgroup=luauGenericParams skipwhite 99 syn match luauTableElementType contained "\h\w*\%(\.\h\w*\)*\ze\s*[<?|&,;})]" nextgroup=luauGenericParams skipwhite 100 syn match luauTypeColon transparent ":" nextgroup=luauSymbolOperator,luauConstant,luauTableType,luauTypeAfterColon skipwhite 101 syn match luauTypeAfterColon contained "\h\w*\%(\.\h\w*\)*\%(\.\.\.\)\=\ze\s*\%([?=},)\]|&]\|,\|<\|->\|$\)" nextgroup=luauGenericParams skipwhite 102 syn region luauFunctionTypeParams transparent start="(\ze\%([^()]*\))\s*->" end=")\ze\s*->" contains=luauFunctionTypeParam,luauTypeColon,luauSelf,@luauTypeCommon 103 syn match luauFunctionTypeParam contained "\h\w*\%(\.\h\w*\)*\%(\.\.\.\)\=\ze\s*?\=\s*[,)|&]" nextgroup=luauGenericParams skipwhite 104 syn match luauFunctionReturnStart transparent ")\s*:\s*" nextgroup=luauSymbolOperator,luauFunctionTypeParams,luauConstant,luauTableType,luauTypePack,luauTypeName skipwhite 105 syn region luauTypePack contained transparent start="(\%([^()]*)\s*->\)\@!" end=")" contains=luauFunctionTypeParams,luauTableType,luauTypeName,@luauTypeCommon 106 syn match luauTypeName contained "\h\w*\%(\.\h\w*\)*\%(\.\.\.\)\=" nextgroup=luauGenericParams skipwhite 107 syn match luauTypeKeyword "\<\%(read\|write\)\>\ze\s*\%(\[\|\h\+\s*:\)" nextgroup=luauTypeIndexer skipwhite 108 109 " metamethods 110 syn keyword luauMetaMethod __index __newindex __mode __namecall __call __iter __len 111 syn keyword luauMetaMethod __eq __add __sub __mul __div __idiv __mod __pow __unm 112 syn keyword luauMetaMethod __lt __le __concat __type __metatable __tostring 113 114 " methods 115 syn match luauMethodColon transparent ":\ze\s*\h\w*\s*\%(<<.\{-}>>\s*\|<[^>]*>\s*\)\=\%((\|{\|'\|\"\|\[\)" nextgroup=luauFunc skipwhite 116 syn match luauFunc contained "\h\w*\ze\s*\%(<<.\{-}>>\s*\|<[^>]*>\s*\)\=\%((\|{\|'\|\"\|\[\)" 117 118 " global functions and values 119 syn keyword luauFunc assert error gcinfo getfenv getmetatable 120 syn keyword luauFunc ipairs loadstring newproxy next pairs pcall print 121 syn keyword luauFunc rawequal rawget rawlen rawset require select setfenv 122 syn keyword luauFunc setmetatable tonumber tostring unpack xpcall 123 syn keyword luauGlobal _G 124 syn keyword luauBuiltinConstant _VERSION 125 syn match luauFunc "\<type\>\ze\s*\%(<<.\{-}>>\s*\)\=(" 126 syn match luauFunc "\<typeof\>\ze\s*\%(<<.\{-}>>\s*\)\=(" 127 128 " standard library members 129 syn match luauFunc /\<bit32\.\%(arshift\|band\|bnot\|bor\|btest\|bxor\|byteswap\|countlz\|countrz\|extract\|lrotate\|lshift\|replace\|rrotate\|rshift\)\>/ 130 syn match luauFunc /\<buffer\.\%(copy\|create\|fill\|fromstring\|len\|readbits\|readf32\|readf64\|readi16\|readi32\|readi8\|readstring\|readu16\|readu32\|readu8\)\>/ 131 syn match luauFunc /\<buffer\.\%(tostring\|writebits\|writef32\|writef64\|writei16\|writei32\|writei8\|writestring\|writeu16\|writeu32\|writeu8\)\>/ 132 syn match luauFunc /\<coroutine\.\%(close\|create\|isyieldable\|resume\|running\|status\|wrap\|yield\)\>/ 133 syn match luauFunc /\<debug\.\%(info\|traceback\)\>/ 134 syn match luauFunc /\<math\.\%(abs\|acos\|asin\|atan2\=\|ceil\|clamp\|cosh\=\|deg\|exp\|floor\|fmod\|frexp\)\>/ 135 syn match luauFunc /\<math\.\%(isfinite\|isinf\|isnan\|ldexp\|lerp\|log\|log10\|map\|max\|min\|modf\|noise\)\>/ 136 syn match luauFunc /\<math\.\%(pow\|rad\|random\%(seed\)\=\|round\|sign\|sinh\=\|sqrt\|tanh\=\)\>/ 137 syn match luauBuiltinConstant /\<math\.\%(huge\|pi\)\>/ 138 syn match luauFunc /\<os\.\%(clock\|date\|difftime\|time\)\>/ 139 syn match luauFunc /\<string\.\%(byte\|char\|find\|format\|gmatch\|gsub\|len\|lower\|match\|pack\%(size\)\=\|rep\|reverse\|split\|sub\|unpack\|upper\)\>/ 140 syn match luauFunc /\<table\.\%(clear\|clone\|concat\|create\|find\|foreachi\=\|freeze\|getn\|insert\|isfrozen\|maxn\|move\|pack\|remove\|sort\|unpack\)\>/ 141 syn match luauFunc /\<utf8\.\%(char\|codepoint\|codes\|len\|offset\)\>/ 142 syn match luauBuiltinConstant /\<utf8\.charpattern\>/ 143 syn match luauFunc /\<vector\.\%(abs\|angle\|ceil\|clamp\|create\|cross\|dot\|floor\|lerp\|magnitude\|max\|min\|normalize\|sign\)\>/ 144 syn match luauBuiltinConstant /\<vector\.\%(one\|zero\)\>/ 145 syn match luauFunc /\<types\.\%(any\|boolean\|buffer\|copy\|generic\|intersectionof\|never\|negationof\|newfunction\|newtable\|number\|optional\|singleton\|string\|thread\|unionof\|unknown\)\>/ 146 147 " define the default highlighting 148 hi def link luauStatement Statement 149 hi def link luauRepeat Repeat 150 hi def link luauString String 151 hi def link luauString2 String 152 hi def link luauInterpString String 153 hi def link luauStringDelimiter luauString 154 hi def link luauInterpDelimiter Special 155 hi def link luauNumber Number 156 hi def link luauOperator Operator 157 hi def link luauSymbolOperator luauOperator 158 hi def link luauConstant Constant 159 hi def link luauCond Conditional 160 hi def link luauFunction Function 161 hi def link luauMetaMethod Function 162 hi def link luauTable Structure 163 hi def link luauComment Comment 164 hi def link luauCommentDelimiter luauComment 165 hi def link luauDirective PreProc 166 hi def link luauTodo Todo 167 hi def link luauSpecial SpecialChar 168 hi def link luauFunc Identifier 169 hi def link luauGlobal Identifier 170 hi def link luauBuiltinConstant Constant 171 hi def link luauSelf Identifier 172 hi def link luauModifier StorageClass 173 hi def link luauType Type 174 hi def link luauTypeAfterColon luauType 175 hi def link luauTableElementType luauType 176 hi def link luauTypeAliasAssign luauSymbolOperator 177 hi def link luauFunctionTypeParam luauType 178 hi def link luauTypeName luauType 179 hi def link luauTypedef Typedef 180 hi def link luauTypeParam Type 181 hi def link luauTypeKeyword Keyword 182 hi def link luauTypeFunction luauFunction 183 hi def link luauDeclareName Identifier 184 hi def link luauAttribute PreProc 185 hi def link luauAttributeName PreProc 186 hi def link luauAttributeDelimiter PreProc 187 188 let b:current_syntax = "luau" 189 190 let &cpo = s:cpo_save 191 unlet s:cpo_save 192 193 " vim: nowrap sw=2 sts=2 ts=8 noet: