1" Vim syntax file 2" Language: Lua 4.0, Lua 5.0 and Lua 5.1 3" Maintainer: Marcus Aurelius Farias <marcus.cf 'at' bol com br> 4" First Author: Carlos Augusto Teixeira Mendes <cmendes 'at' inf puc-rio br> 5" Last Change: 2006 Aug 10 6" Options: lua_version = 4 or 5 7" lua_subversion = 0 (4.0, 5.0) or 1 (5.1) 8" default 5.1 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.1 20 let lua_version = 5 21 let lua_subversion = 1 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=ALLBUT,luaError,luaTodo,luaSpecial,luaCond,luaCondElseif,luaCondEnd,luaCondStart,luaBlock,luaRepeatBlock,luaRepeat,luaStatement 50syn match luaError ")" 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=ALLBUT,luaTodo,luaSpecial,luaCond,luaCondElseif,luaCondEnd,luaRepeat 56 57" if then else elseif end 58syn keyword luaCond contained else 59 60" then ... end 61syn region luaCondEnd contained transparent matchgroup=luaCond start="\<then\>" end="\<end\>" contains=ALLBUT,luaTodo,luaSpecial,luaRepeat 62 63" elseif ... then 64syn region luaCondElseif contained transparent matchgroup=luaCond start="\<elseif\>" end="\<then\>" contains=ALLBUT,luaTodo,luaSpecial,luaCond,luaCondElseif,luaCondEnd,luaRepeat 65 66" if ... then 67syn region luaCondStart transparent matchgroup=luaCond start="\<if\>" end="\<then\>"me=e-4 contains=ALLBUT,luaTodo,luaSpecial,luaCond,luaCondElseif,luaCondEnd,luaRepeat nextgroup=luaCondEnd skipwhite skipempty 68 69" do ... end 70syn region luaBlock transparent matchgroup=luaStatement start="\<do\>" end="\<end\>" contains=ALLBUT,luaTodo,luaSpecial,luaCond,luaCondElseif,luaCondEnd,luaRepeat 71 72" repeat ... until 73syn region luaRepeatBlock transparent matchgroup=luaRepeat start="\<repeat\>" end="\<until\>" contains=ALLBUT,luaTodo,luaSpecial,luaCond,luaCondElseif,luaCondEnd,luaRepeat 74 75" while ... do 76syn region luaRepeatBlock transparent matchgroup=luaRepeat start="\<while\>" end="\<do\>"me=e-2 contains=ALLBUT,luaTodo,luaSpecial,luaCond,luaCondElseif,luaCondEnd,luaRepeat nextgroup=luaBlock skipwhite skipempty 77 78" for ... do and for ... in ... do 79syn region luaRepeatBlock transparent matchgroup=luaRepeat start="\<for\>" end="\<do\>"me=e-2 contains=ALLBUT,luaTodo,luaSpecial,luaCond,luaCondElseif,luaCondEnd nextgroup=luaBlock skipwhite skipempty 80 81" Following 'else' example. This is another item to those 82" contains=ALLBUT,... because only the 'for' luaRepeatBlock contains it. 83syn keyword luaRepeat contained in 84 85" other keywords 86syn keyword luaStatement return local break 87syn keyword luaOperator and or not 88syn keyword luaConstant nil 89if lua_version > 4 90 syn keyword luaConstant true false 91endif 92 93" Strings 94if lua_version < 5 95 syn match luaSpecial contained "\\[\\abfnrtv\'\"]\|\\\d\{,3}" 96elseif lua_version == 5 && lua_subversion == 0 97 syn match luaSpecial contained "\\[\\abfnrtv\'\"[\]]\|\\\d\{,3}" 98 syn region luaString2 matchgroup=luaString start=+\[\[+ end=+\]\]+ contains=luaString2,@Spell 99elseif lua_version > 5 || (lua_version == 5 && lua_subversion >= 1) 100 syn match luaSpecial contained "\\[\\abfnrtv\'\"]\|\\\d\{,3}" 101 syn region luaString2 matchgroup=luaString start="\[\z(=*\)\[" end="\]\z1\]" contains=@Spell 102endif 103syn region luaString start=+'+ end=+'+ skip=+\\\\\|\\'+ contains=luaSpecial,@Spell 104syn region luaString start=+"+ end=+"+ skip=+\\\\\|\\"+ contains=luaSpecial,@Spell 105 106" integer number 107syn match luaNumber "\<\d\+\>" 108" floating point number, with dot, optional exponent 109syn match luaFloat "\<\d\+\.\d*\%(e[-+]\=\d\+\)\=\>" 110" floating point number, starting with a dot, optional exponent 111syn match luaFloat "\.\d\+\%(e[-+]\=\d\+\)\=\>" 112" floating point number, without dot, with exponent 113syn match luaFloat "\<\d\+e[-+]\=\d\+\>" 114 115" hex numbers 116if lua_version > 5 || (lua_version == 5 && lua_subversion >= 1) 117 syn match luaNumber "\<0x\x\+\>" 118endif 119 120" tables 121syn region luaTableBlock transparent matchgroup=luaTable start="{" end="}" contains=ALLBUT,luaTodo,luaSpecial,luaCond,luaCondElseif,luaCondEnd,luaCondStart,luaBlock,luaRepeatBlock,luaRepeat,luaStatement 122 123syn keyword luaFunc assert collectgarbage dofile error next 124syn keyword luaFunc print rawget rawset tonumber tostring type _VERSION 125 126if lua_version == 4 127 syn keyword luaFunc _ALERT _ERRORMESSAGE gcinfo 128 syn keyword luaFunc call copytagmethods dostring 129 syn keyword luaFunc foreach foreachi getglobal getn 130 syn keyword luaFunc gettagmethod globals newtag 131 syn keyword luaFunc setglobal settag settagmethod sort 132 syn keyword luaFunc tag tinsert tremove 133 syn keyword luaFunc _INPUT _OUTPUT _STDIN _STDOUT _STDERR 134 syn keyword luaFunc openfile closefile flush seek 135 syn keyword luaFunc setlocale execute remove rename tmpname 136 syn keyword luaFunc getenv date clock exit 137 syn keyword luaFunc readfrom writeto appendto read write 138 syn keyword luaFunc PI abs sin cos tan asin 139 syn keyword luaFunc acos atan atan2 ceil floor 140 syn keyword luaFunc mod frexp ldexp sqrt min max log 141 syn keyword luaFunc log10 exp deg rad random 142 syn keyword luaFunc randomseed strlen strsub strlower strupper 143 syn keyword luaFunc strchar strrep ascii strbyte 144 syn keyword luaFunc format strfind gsub 145 syn keyword luaFunc getinfo getlocal setlocal setcallhook setlinehook 146elseif lua_version == 5 147 " Not sure if all these functions need to be highlighted... 148 syn keyword luaFunc _G getfenv getmetatable ipairs loadfile 149 syn keyword luaFunc loadstring pairs pcall rawequal 150 syn keyword luaFunc require setfenv setmetatable unpack xpcall 151 if lua_subversion == 0 152 syn keyword luaFunc gcinfo loadlib LUA_PATH _LOADED _REQUIREDNAME 153 elseif lua_subversion == 1 154 syn keyword luaFunc load module select 155 syn match luaFunc /package\.cpath/ 156 syn match luaFunc /package\.loaded/ 157 syn match luaFunc /package\.loadlib/ 158 syn match luaFunc /package\.path/ 159 syn match luaFunc /package\.preload/ 160 syn match luaFunc /package\.seeall/ 161 syn match luaFunc /coroutine\.running/ 162 endif 163 syn match luaFunc /coroutine\.create/ 164 syn match luaFunc /coroutine\.resume/ 165 syn match luaFunc /coroutine\.status/ 166 syn match luaFunc /coroutine\.wrap/ 167 syn match luaFunc /coroutine\.yield/ 168 syn match luaFunc /string\.byte/ 169 syn match luaFunc /string\.char/ 170 syn match luaFunc /string\.dump/ 171 syn match luaFunc /string\.find/ 172 syn match luaFunc /string\.len/ 173 syn match luaFunc /string\.lower/ 174 syn match luaFunc /string\.rep/ 175 syn match luaFunc /string\.sub/ 176 syn match luaFunc /string\.upper/ 177 syn match luaFunc /string\.format/ 178 syn match luaFunc /string\.gsub/ 179 if lua_subversion == 0 180 syn match luaFunc /string\.gfind/ 181 syn match luaFunc /table\.getn/ 182 syn match luaFunc /table\.setn/ 183 syn match luaFunc /table\.foreach/ 184 syn match luaFunc /table\.foreachi/ 185 elseif lua_subversion == 1 186 syn match luaFunc /string\.gmatch/ 187 syn match luaFunc /string\.match/ 188 syn match luaFunc /string\.reverse/ 189 syn match luaFunc /table\.maxn/ 190 endif 191 syn match luaFunc /table\.concat/ 192 syn match luaFunc /table\.sort/ 193 syn match luaFunc /table\.insert/ 194 syn match luaFunc /table\.remove/ 195 syn match luaFunc /math\.abs/ 196 syn match luaFunc /math\.acos/ 197 syn match luaFunc /math\.asin/ 198 syn match luaFunc /math\.atan/ 199 syn match luaFunc /math\.atan2/ 200 syn match luaFunc /math\.ceil/ 201 syn match luaFunc /math\.sin/ 202 syn match luaFunc /math\.cos/ 203 syn match luaFunc /math\.tan/ 204 syn match luaFunc /math\.deg/ 205 syn match luaFunc /math\.exp/ 206 syn match luaFunc /math\.floor/ 207 syn match luaFunc /math\.log/ 208 syn match luaFunc /math\.log10/ 209 syn match luaFunc /math\.max/ 210 syn match luaFunc /math\.min/ 211 if lua_subversion == 0 212 syn match luaFunc /math\.mod/ 213 elseif lua_subversion == 1 214 syn match luaFunc /math\.fmod/ 215 syn match luaFunc /math\.modf/ 216 syn match luaFunc /math\.cosh/ 217 syn match luaFunc /math\.sinh/ 218 syn match luaFunc /math\.tanh/ 219 endif 220 syn match luaFunc /math\.pow/ 221 syn match luaFunc /math\.rad/ 222 syn match luaFunc /math\.sqrt/ 223 syn match luaFunc /math\.frexp/ 224 syn match luaFunc /math\.ldexp/ 225 syn match luaFunc /math\.random/ 226 syn match luaFunc /math\.randomseed/ 227 syn match luaFunc /math\.pi/ 228 syn match luaFunc /io\.stdin/ 229 syn match luaFunc /io\.stdout/ 230 syn match luaFunc /io\.stderr/ 231 syn match luaFunc /io\.close/ 232 syn match luaFunc /io\.flush/ 233 syn match luaFunc /io\.input/ 234 syn match luaFunc /io\.lines/ 235 syn match luaFunc /io\.open/ 236 syn match luaFunc /io\.output/ 237 syn match luaFunc /io\.popen/ 238 syn match luaFunc /io\.read/ 239 syn match luaFunc /io\.tmpfile/ 240 syn match luaFunc /io\.type/ 241 syn match luaFunc /io\.write/ 242 syn match luaFunc /os\.clock/ 243 syn match luaFunc /os\.date/ 244 syn match luaFunc /os\.difftime/ 245 syn match luaFunc /os\.execute/ 246 syn match luaFunc /os\.exit/ 247 syn match luaFunc /os\.getenv/ 248 syn match luaFunc /os\.remove/ 249 syn match luaFunc /os\.rename/ 250 syn match luaFunc /os\.setlocale/ 251 syn match luaFunc /os\.time/ 252 syn match luaFunc /os\.tmpname/ 253 syn match luaFunc /debug\.debug/ 254 syn match luaFunc /debug\.gethook/ 255 syn match luaFunc /debug\.getinfo/ 256 syn match luaFunc /debug\.getlocal/ 257 syn match luaFunc /debug\.getupvalue/ 258 syn match luaFunc /debug\.setlocal/ 259 syn match luaFunc /debug\.setupvalue/ 260 syn match luaFunc /debug\.sethook/ 261 syn match luaFunc /debug\.traceback/ 262 if lua_subversion == 1 263 syn match luaFunc /debug\.getfenv/ 264 syn match luaFunc /debug\.getmetatable/ 265 syn match luaFunc /debug\.getregistry/ 266 syn match luaFunc /debug\.setfenv/ 267 syn match luaFunc /debug\.setmetatable/ 268 endif 269endif 270 271" Define the default highlighting. 272" For version 5.7 and earlier: only when not done already 273" For version 5.8 and later: only when an item doesn't have highlighting yet 274if version >= 508 || !exists("did_lua_syntax_inits") 275 if version < 508 276 let did_lua_syntax_inits = 1 277 command -nargs=+ HiLink hi link <args> 278 else 279 command -nargs=+ HiLink hi def link <args> 280 endif 281 282 HiLink luaStatement Statement 283 HiLink luaRepeat Repeat 284 HiLink luaString String 285 HiLink luaString2 String 286 HiLink luaNumber Number 287 HiLink luaFloat Float 288 HiLink luaOperator Operator 289 HiLink luaConstant Constant 290 HiLink luaCond Conditional 291 HiLink luaFunction Function 292 HiLink luaComment Comment 293 HiLink luaTodo Todo 294 HiLink luaTable Structure 295 HiLink luaError Error 296 HiLink luaSpecial SpecialChar 297 HiLink luaFunc Identifier 298 299 delcommand HiLink 300endif 301 302let b:current_syntax = "lua" 303 304" vim: et ts=8 305