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