1" Vim syntax file 2" Language: Lua 4.0, Lua 5.0, Lua 5.1 and Lua 5.2 3" Maintainer: Marcus Aurelius Farias <masserahguard-lua 'at' yahoo com> 4" First Author: Carlos Augusto Teixeira Mendes <cmendes 'at' inf puc-rio br> 5" Last Change: 2012 Aug 12 6" Options: lua_version = 4 or 5 7" lua_subversion = 0 (4.0, 5.0) or 1 (5.1) or 2 (5.2) 8" default 5.2 9 10" quit when a syntax file was already loaded 11if exists("b:current_syntax") 12 finish 13endif 14 15let s:cpo_save = &cpo 16set cpo&vim 17 18if !exists("lua_version") 19 " Default is lua 5.2 20 let lua_version = 5 21 let lua_subversion = 2 22elseif !exists("lua_subversion") 23 " lua_version exists, but lua_subversion doesn't. So, set it to 0 24 let lua_subversion = 0 25endif 26 27syn case match 28 29" syncing method 30syn sync minlines=100 31 32" Comments 33syn keyword luaTodo contained TODO FIXME XXX 34syn match luaComment "--.*$" contains=luaTodo,@Spell 35if lua_version == 5 && lua_subversion == 0 36 syn region luaComment matchgroup=luaComment start="--\[\[" end="\]\]" contains=luaTodo,luaInnerComment,@Spell 37 syn region luaInnerComment contained transparent start="\[\[" end="\]\]" 38elseif lua_version > 5 || (lua_version == 5 && lua_subversion >= 1) 39 " Comments in Lua 5.1: --[[ ... ]], [=[ ... ]=], [===[ ... ]===], etc. 40 syn region luaComment matchgroup=luaComment start="--\[\z(=*\)\[" end="\]\z1\]" contains=luaTodo,@Spell 41endif 42 43" First line may start with #! 44syn match luaComment "\%^#!.*" 45 46" catch errors caused by wrong parenthesis and wrong curly brackets or 47" keywords placed outside their respective blocks 48syn region luaParen transparent start='(' end=')' contains=ALLBUT,luaParenError,luaTodo,luaSpecial,luaIfThen,luaElseifThen,luaElse,luaThenEnd,luaBlock,luaLoopBlock,luaIn,luaStatement 49syn region luaTableBlock transparent matchgroup=luaTable start="{" end="}" contains=ALLBUT,luaBraceError,luaTodo,luaSpecial,luaIfThen,luaElseifThen,luaElse,luaThenEnd,luaBlock,luaLoopBlock,luaIn,luaStatement 50 51syn match luaParenError ")" 52syn match luaBraceError "}" 53syn match luaError "\<\%(end\|else\|elseif\|then\|until\|in\)\>" 54 55" function ... end 56syn region luaFunctionBlock transparent matchgroup=luaFunction start="\<function\>" end="\<end\>" contains=ALLBUT,luaTodo,luaSpecial,luaElseifThen,luaElse,luaThenEnd,luaIn 57 58" if ... then 59syn region luaIfThen transparent matchgroup=luaCond start="\<if\>" end="\<then\>"me=e-4 contains=ALLBUT,luaTodo,luaSpecial,luaElseifThen,luaElse,luaIn nextgroup=luaThenEnd skipwhite skipempty 60 61" then ... end 62syn region luaThenEnd contained transparent matchgroup=luaCond start="\<then\>" end="\<end\>" contains=ALLBUT,luaTodo,luaSpecial,luaThenEnd,luaIn 63 64" elseif ... then 65syn region luaElseifThen contained transparent matchgroup=luaCond start="\<elseif\>" end="\<then\>" contains=ALLBUT,luaTodo,luaSpecial,luaElseifThen,luaElse,luaThenEnd,luaIn 66 67" else 68syn keyword luaElse contained else 69 70" do ... end 71syn region luaBlock transparent matchgroup=luaStatement start="\<do\>" end="\<end\>" contains=ALLBUT,luaTodo,luaSpecial,luaElseifThen,luaElse,luaThenEnd,luaIn 72 73" repeat ... until 74syn region luaLoopBlock transparent matchgroup=luaRepeat start="\<repeat\>" end="\<until\>" contains=ALLBUT,luaTodo,luaSpecial,luaElseifThen,luaElse,luaThenEnd,luaIn 75 76" while ... do 77syn region luaLoopBlock transparent matchgroup=luaRepeat start="\<while\>" end="\<do\>"me=e-2 contains=ALLBUT,luaTodo,luaSpecial,luaIfThen,luaElseifThen,luaElse,luaThenEnd,luaIn nextgroup=luaBlock skipwhite skipempty 78 79" for ... do and for ... in ... do 80syn region luaLoopBlock transparent matchgroup=luaRepeat start="\<for\>" end="\<do\>"me=e-2 contains=ALLBUT,luaTodo,luaSpecial,luaIfThen,luaElseifThen,luaElse,luaThenEnd nextgroup=luaBlock skipwhite skipempty 81 82syn keyword luaIn contained in 83 84" other keywords 85syn keyword luaStatement return local break 86if lua_version > 5 || (lua_version == 5 && lua_subversion >= 2) 87 syn keyword luaStatement goto 88 syn match luaLabel "::\I\i*::" 89endif 90syn keyword luaOperator and or not 91syn keyword luaConstant nil 92if lua_version > 4 93 syn keyword luaConstant true false 94endif 95 96" Strings 97if lua_version < 5 98 syn match luaSpecial contained "\\[\\abfnrtv\'\"]\|\\[[:digit:]]\{,3}" 99elseif lua_version == 5 100 if lua_subversion == 0 101 syn match luaSpecial contained #\\[\\abfnrtv'"[\]]\|\\[[:digit:]]\{,3}# 102 syn region luaString2 matchgroup=luaString start=+\[\[+ end=+\]\]+ contains=luaString2,@Spell 103 else 104 if lua_subversion == 1 105 syn match luaSpecial contained #\\[\\abfnrtv'"]\|\\[[:digit:]]\{,3}# 106 else " Lua 5.2 107 syn match luaSpecial contained #\\[\\abfnrtvz'"]\|\\x[[:xdigit:]]\{2}\|\\[[:digit:]]\{,3}# 108 endif 109 syn region luaString2 matchgroup=luaString start="\[\z(=*\)\[" end="\]\z1\]" contains=@Spell 110 endif 111endif 112syn region luaString start=+'+ end=+'+ skip=+\\\\\|\\'+ contains=luaSpecial,@Spell 113syn region luaString start=+"+ end=+"+ skip=+\\\\\|\\"+ contains=luaSpecial,@Spell 114 115" integer number 116syn match luaNumber "\<\d\+\>" 117" floating point number, with dot, optional exponent 118syn match luaNumber "\<\d\+\.\d*\%([eE][-+]\=\d\+\)\=\>" 119" floating point number, starting with a dot, optional exponent 120syn match luaNumber "\.\d\+\%([eE][-+]\=\d\+\)\=\>" 121" floating point number, without dot, with exponent 122syn match luaNumber "\<\d\+[eE][-+]\=\d\+\>" 123 124" hex numbers 125if lua_version >= 5 126 if lua_subversion == 1 127 syn match luaNumber "\<0[xX]\x\+\>" 128 elseif lua_subversion >= 2 129 syn match luaNumber "\<0[xX][[:xdigit:].]\+\%([pP][-+]\=\d\+\)\=\>" 130 endif 131endif 132 133syn keyword luaFunc assert collectgarbage dofile error next 134syn keyword luaFunc print rawget rawset tonumber tostring type _VERSION 135 136if lua_version == 4 137 syn keyword luaFunc _ALERT _ERRORMESSAGE gcinfo 138 syn keyword luaFunc call copytagmethods dostring 139 syn keyword luaFunc foreach foreachi getglobal getn 140 syn keyword luaFunc gettagmethod globals newtag 141 syn keyword luaFunc setglobal settag settagmethod sort 142 syn keyword luaFunc tag tinsert tremove 143 syn keyword luaFunc _INPUT _OUTPUT _STDIN _STDOUT _STDERR 144 syn keyword luaFunc openfile closefile flush seek 145 syn keyword luaFunc setlocale execute remove rename tmpname 146 syn keyword luaFunc getenv date clock exit 147 syn keyword luaFunc readfrom writeto appendto read write 148 syn keyword luaFunc PI abs sin cos tan asin 149 syn keyword luaFunc acos atan atan2 ceil floor 150 syn keyword luaFunc mod frexp ldexp sqrt min max log 151 syn keyword luaFunc log10 exp deg rad random 152 syn keyword luaFunc randomseed strlen strsub strlower strupper 153 syn keyword luaFunc strchar strrep ascii strbyte 154 syn keyword luaFunc format strfind gsub 155 syn keyword luaFunc getinfo getlocal setlocal setcallhook setlinehook 156elseif lua_version == 5 157 syn keyword luaFunc getmetatable setmetatable 158 syn keyword luaFunc ipairs pairs 159 syn keyword luaFunc pcall xpcall 160 syn keyword luaFunc _G loadfile rawequal require 161 if lua_subversion == 0 162 syn keyword luaFunc getfenv setfenv 163 syn keyword luaFunc loadstring unpack 164 syn keyword luaFunc gcinfo loadlib LUA_PATH _LOADED _REQUIREDNAME 165 else 166 syn keyword luaFunc load select 167 syn match luaFunc /\<package\.cpath\>/ 168 syn match luaFunc /\<package\.loaded\>/ 169 syn match luaFunc /\<package\.loadlib\>/ 170 syn match luaFunc /\<package\.path\>/ 171 if lua_subversion == 1 172 syn keyword luaFunc getfenv setfenv 173 syn keyword luaFunc loadstring module unpack 174 syn match luaFunc /\<package\.loaders\>/ 175 syn match luaFunc /\<package\.preload\>/ 176 syn match luaFunc /\<package\.seeall\>/ 177 elseif lua_subversion == 2 178 syn keyword luaFunc _ENV rawlen 179 syn match luaFunc /\<package\.config\>/ 180 syn match luaFunc /\<package\.preload\>/ 181 syn match luaFunc /\<package\.searchers\>/ 182 syn match luaFunc /\<package\.searchpath\>/ 183 syn match luaFunc /\<bit32\.arshift\>/ 184 syn match luaFunc /\<bit32\.band\>/ 185 syn match luaFunc /\<bit32\.bnot\>/ 186 syn match luaFunc /\<bit32\.bor\>/ 187 syn match luaFunc /\<bit32\.btest\>/ 188 syn match luaFunc /\<bit32\.bxor\>/ 189 syn match luaFunc /\<bit32\.extract\>/ 190 syn match luaFunc /\<bit32\.lrotate\>/ 191 syn match luaFunc /\<bit32\.lshift\>/ 192 syn match luaFunc /\<bit32\.replace\>/ 193 syn match luaFunc /\<bit32\.rrotate\>/ 194 syn match luaFunc /\<bit32\.rshift\>/ 195 endif 196 syn match luaFunc /\<coroutine\.running\>/ 197 endif 198 syn match luaFunc /\<coroutine\.create\>/ 199 syn match luaFunc /\<coroutine\.resume\>/ 200 syn match luaFunc /\<coroutine\.status\>/ 201 syn match luaFunc /\<coroutine\.wrap\>/ 202 syn match luaFunc /\<coroutine\.yield\>/ 203 syn match luaFunc /\<string\.byte\>/ 204 syn match luaFunc /\<string\.char\>/ 205 syn match luaFunc /\<string\.dump\>/ 206 syn match luaFunc /\<string\.find\>/ 207 syn match luaFunc /\<string\.format\>/ 208 syn match luaFunc /\<string\.gsub\>/ 209 syn match luaFunc /\<string\.len\>/ 210 syn match luaFunc /\<string\.lower\>/ 211 syn match luaFunc /\<string\.rep\>/ 212 syn match luaFunc /\<string\.sub\>/ 213 syn match luaFunc /\<string\.upper\>/ 214 if lua_subversion == 0 215 syn match luaFunc /\<string\.gfind\>/ 216 else 217 syn match luaFunc /\<string\.gmatch\>/ 218 syn match luaFunc /\<string\.match\>/ 219 syn match luaFunc /\<string\.reverse\>/ 220 endif 221 if lua_subversion == 0 222 syn match luaFunc /\<table\.getn\>/ 223 syn match luaFunc /\<table\.setn\>/ 224 syn match luaFunc /\<table\.foreach\>/ 225 syn match luaFunc /\<table\.foreachi\>/ 226 elseif lua_subversion == 1 227 syn match luaFunc /\<table\.maxn\>/ 228 elseif lua_subversion == 2 229 syn match luaFunc /\<table\.pack\>/ 230 syn match luaFunc /\<table\.unpack\>/ 231 endif 232 syn match luaFunc /\<table\.concat\>/ 233 syn match luaFunc /\<table\.sort\>/ 234 syn match luaFunc /\<table\.insert\>/ 235 syn match luaFunc /\<table\.remove\>/ 236 syn match luaFunc /\<math\.abs\>/ 237 syn match luaFunc /\<math\.acos\>/ 238 syn match luaFunc /\<math\.asin\>/ 239 syn match luaFunc /\<math\.atan\>/ 240 syn match luaFunc /\<math\.atan2\>/ 241 syn match luaFunc /\<math\.ceil\>/ 242 syn match luaFunc /\<math\.sin\>/ 243 syn match luaFunc /\<math\.cos\>/ 244 syn match luaFunc /\<math\.tan\>/ 245 syn match luaFunc /\<math\.deg\>/ 246 syn match luaFunc /\<math\.exp\>/ 247 syn match luaFunc /\<math\.floor\>/ 248 syn match luaFunc /\<math\.log\>/ 249 syn match luaFunc /\<math\.max\>/ 250 syn match luaFunc /\<math\.min\>/ 251 if lua_subversion == 0 252 syn match luaFunc /\<math\.mod\>/ 253 syn match luaFunc /\<math\.log10\>/ 254 else 255 if lua_subversion == 1 256 syn match luaFunc /\<math\.log10\>/ 257 endif 258 syn match luaFunc /\<math\.huge\>/ 259 syn match luaFunc /\<math\.fmod\>/ 260 syn match luaFunc /\<math\.modf\>/ 261 syn match luaFunc /\<math\.cosh\>/ 262 syn match luaFunc /\<math\.sinh\>/ 263 syn match luaFunc /\<math\.tanh\>/ 264 endif 265 syn match luaFunc /\<math\.pow\>/ 266 syn match luaFunc /\<math\.rad\>/ 267 syn match luaFunc /\<math\.sqrt\>/ 268 syn match luaFunc /\<math\.frexp\>/ 269 syn match luaFunc /\<math\.ldexp\>/ 270 syn match luaFunc /\<math\.random\>/ 271 syn match luaFunc /\<math\.randomseed\>/ 272 syn match luaFunc /\<math\.pi\>/ 273 syn match luaFunc /\<io\.close\>/ 274 syn match luaFunc /\<io\.flush\>/ 275 syn match luaFunc /\<io\.input\>/ 276 syn match luaFunc /\<io\.lines\>/ 277 syn match luaFunc /\<io\.open\>/ 278 syn match luaFunc /\<io\.output\>/ 279 syn match luaFunc /\<io\.popen\>/ 280 syn match luaFunc /\<io\.read\>/ 281 syn match luaFunc /\<io\.stderr\>/ 282 syn match luaFunc /\<io\.stdin\>/ 283 syn match luaFunc /\<io\.stdout\>/ 284 syn match luaFunc /\<io\.tmpfile\>/ 285 syn match luaFunc /\<io\.type\>/ 286 syn match luaFunc /\<io\.write\>/ 287 syn match luaFunc /\<os\.clock\>/ 288 syn match luaFunc /\<os\.date\>/ 289 syn match luaFunc /\<os\.difftime\>/ 290 syn match luaFunc /\<os\.execute\>/ 291 syn match luaFunc /\<os\.exit\>/ 292 syn match luaFunc /\<os\.getenv\>/ 293 syn match luaFunc /\<os\.remove\>/ 294 syn match luaFunc /\<os\.rename\>/ 295 syn match luaFunc /\<os\.setlocale\>/ 296 syn match luaFunc /\<os\.time\>/ 297 syn match luaFunc /\<os\.tmpname\>/ 298 syn match luaFunc /\<debug\.debug\>/ 299 syn match luaFunc /\<debug\.gethook\>/ 300 syn match luaFunc /\<debug\.getinfo\>/ 301 syn match luaFunc /\<debug\.getlocal\>/ 302 syn match luaFunc /\<debug\.getupvalue\>/ 303 syn match luaFunc /\<debug\.setlocal\>/ 304 syn match luaFunc /\<debug\.setupvalue\>/ 305 syn match luaFunc /\<debug\.sethook\>/ 306 syn match luaFunc /\<debug\.traceback\>/ 307 if lua_subversion == 1 308 syn match luaFunc /\<debug\.getfenv\>/ 309 syn match luaFunc /\<debug\.setfenv\>/ 310 syn match luaFunc /\<debug\.getmetatable\>/ 311 syn match luaFunc /\<debug\.setmetatable\>/ 312 syn match luaFunc /\<debug\.getregistry\>/ 313 elseif lua_subversion == 2 314 syn match luaFunc /\<debug\.getmetatable\>/ 315 syn match luaFunc /\<debug\.setmetatable\>/ 316 syn match luaFunc /\<debug\.getregistry\>/ 317 syn match luaFunc /\<debug\.getuservalue\>/ 318 syn match luaFunc /\<debug\.setuservalue\>/ 319 syn match luaFunc /\<debug\.upvalueid\>/ 320 syn match luaFunc /\<debug\.upvaluejoin\>/ 321 endif 322endif 323 324" Define the default highlighting. 325" Only when an item doesn't have highlighting yet 326 327hi def link luaStatement Statement 328hi def link luaRepeat Repeat 329hi def link luaFor Repeat 330hi def link luaString String 331hi def link luaString2 String 332hi def link luaNumber Number 333hi def link luaOperator Operator 334hi def link luaIn Operator 335hi def link luaConstant Constant 336hi def link luaCond Conditional 337hi def link luaElse Conditional 338hi def link luaFunction Function 339hi def link luaComment Comment 340hi def link luaTodo Todo 341hi def link luaTable Structure 342hi def link luaError Error 343hi def link luaParenError Error 344hi def link luaBraceError Error 345hi def link luaSpecial SpecialChar 346hi def link luaFunc Identifier 347hi def link luaLabel Label 348 349 350let b:current_syntax = "lua" 351 352let &cpo = s:cpo_save 353unlet s:cpo_save 354" vim: et ts=8 sw=2 355