robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
2b0f967b77
master
1" Vim syntax file 2" Language: Lua 4.0, Lua 5.0, Lua 5.1, Lua 5.2 and Lua 5.3 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: 2025 Feb 25 6" Options: lua_version = 4 or 5 7" lua_subversion = 0 (for 4.0 or 5.0) 8" or 1, 2, 3 (for 5.1, 5.2 or 5.3) 9" the default is 5.3 10 11" quit when a syntax file was already loaded 12if exists ( "b:current_syntax" ) 13finish 14endif 15 16let s: cpo_save = & cpo 17set cpo & vim 18 19" keep in sync with ftplugin/lua.vim 20if ! exists ( "lua_version" ) 21" Default is lua 5.3 22let lua_version = 5 23let lua_subversion = 3 24elseif ! exists ( "lua_subversion" ) 25" lua_version exists, but lua_subversion doesn't. In this case set it to 0 26let lua_subversion = 0 27endif 28 29syn case match 30 31" syncing method 32syn sync minlines= 1000 33 34if lua_version >= 5 35syn keyword luaMetaMethod __add __sub __mul __div __pow __unm __concat 36syn keyword luaMetaMethod __eq __lt __le 37syn keyword luaMetaMethod __index __newindex __call 38syn keyword luaMetaMethod __metatable __mode __gc __tostring 39endif 40 41if lua_version > 5 || ( lua_version == 5 && lua_subversion >= 1 ) 42syn keyword luaMetaMethod __mod __len 43endif 44 45if lua_version > 5 || ( lua_version == 5 && lua_subversion >= 2 ) 46syn keyword luaMetaMethod __pairs 47endif 48 49if lua_version > 5 || ( lua_version == 5 && lua_subversion >= 3 ) 50syn keyword luaMetaMethod __idiv __name 51syn keyword luaMetaMethod __band __bor __bxor __bnot __shl __shr 52endif 53 54if lua_version > 5 || ( lua_version == 5 && lua_subversion >= 4 ) 55syn keyword luaMetaMethod __close 56endif 57 58" catch errors caused by wrong parenthesis and wrong curly brackets or 59" keywords placed outside their respective blocks 60 61syn region luaParen transparent start = '( 'end = ') 'contains = TOP , luaParenError 62syn match luaParenError ") " 63syn match luaError "} " 64syn match luaError "\<\%(end\|else\|elseif\|then\|until\|in\)\> " 65 66" Function declaration 67syn region luaFunctionBlock transparent matchgroup = luaFunction start = "\<function\> "end = "\<end\> "contains = TOP 68 69" else 70syn keyword luaCondElse matchgroup =luaCond contained containedin=luaCondEnd else 71 72" then ... end 73syn region luaCondEnd contained transparent matchgroup = luaCond start = "\<then\> "end = "\<end\> "contains = TOP 74 75" elseif ... then 76syn region luaCondElseif contained containedin = luaCondEnd transparent matchgroup = luaCond start = "\<elseif\> "end = "\<then\> "contains = TOP 77 78" if ... then 79syn region luaCondStart transparent matchgroup = luaCond start = "\<if\> "end = "\<then\> "me= e-4contains = TOP nextgroup = luaCondEnd skipwhite skipempty 80 81" do ... end 82syn region luaBlock transparent matchgroup = luaStatement start = "\<do\> "end = "\<end\> "contains = TOP 83" repeat ... until 84syn region luaRepeatBlock transparent matchgroup = luaRepeat start = "\<repeat\> "end = "\<until\> "contains = TOP 85 86" while ... do 87syn region luaWhile transparent matchgroup = luaRepeat start = "\<while\> "end = "\<do\> "me= e-2contains = TOP nextgroup = luaBlock skipwhite skipempty 88 89" for ... do and for ... in ... do 90syn region luaFor transparent matchgroup = luaRepeat start = "\<for\> "end = "\<do\> "me= e-2contains = TOP nextgroup = luaBlock skipwhite skipempty 91 92syn keyword luaFor contained containedin = luaFor in 93 94" other keywords 95syn keyword luaStatement return local break 96if lua_version > 5 || ( lua_version == 5 && lua_subversion >= 2 ) 97syn keyword luaStatement goto 98syn match luaLabel "::\I\i * :: " 99endif 100 101" operators 102syn keyword luaOperator and or not 103 104if ( lua_version == 5 && lua_subversion >= 3 ) || lua_version > 5 105syn match luaSymbolOperator "[ #<>=~^&|*/%+- ] \|\.\{2,3} " 106elseif lua_version == 5 && ( lua_subversion == 1 || lua_subversion == 2 ) 107syn match luaSymbolOperator "[ #<>=~^*/%+- ] \|\.\{2,3} " 108else 109syn match luaSymbolOperator "[ <>=~^*/+- ] \|\.\{2,3} " 110endif 111 112" comments 113syn keyword luaTodo contained TODO FIXME XXX 114syn match luaComment "--. * $ "contains = luaTodo , @Spell 115if lua_version == 5 && lua_subversion == 0 116syn region luaComment matchgroup = luaCommentDelimiter start = "--\[\[ "end = "\]\] "contains = luaTodo , luaInnerComment , @Spell 117syn region luaInnerComment contained transparent start = "\[\[ "end = "\]\] " 118elseif lua_version > 5 || ( lua_version == 5 && lua_subversion >= 1 ) 119" Comments in Lua 5.1: --[[ ... ]], [=[ ... ]=], [===[ ... ]===], etc. 120syn region luaComment matchgroup = luaCommentDelimiter start = "--\[\z(= * \)\[ "end = "\]\z1\] "contains = luaTodo , @Spell 121endif 122 123" first line may start with #! 124syn match luaComment "\%^#!. * " 125 126syn keyword luaConstant nil 127if lua_version > 4 128syn keyword luaConstant true false 129endif 130 131" strings 132syn match luaSpecial contained #\\ [ \\abfnrtv'"[\] ] \|\\ [ [:digit: ] ]\{,3} # 133if lua_version == 5 134if lua_subversion == 0 135syn region luaString2 matchgroup = luaStringDelimiter start = +\[\[ +end = +\]\] +contains = luaString2 , @Spell 136else 137if lua_subversion >= 2 138syn match luaSpecial contained #\\z\|\\x [ [:xdigit: ] ]\{2} # 139endif 140if lua_subversion >= 3 141syn match luaSpecial contained #\\u{ [ [:xdigit: ] ]\+} # 142endif 143syn region luaString2 matchgroup = luaStringDelimiter start = "\[\z(= * \)\[ "end = "\]\z1\] "contains = @Spell 144endif 145endif 146syn region luaString matchgroup = luaStringDelimiter start = +' +end = +' + skip=+\\\\\|\\'+ contains =luaSpecial,@Spell 147syn region luaString matchgroup = luaStringDelimiter start = +" +end = +" + skip=+\\\\\|\\"+ contains =luaSpecial,@Spell 148 149" integer number 150syn match luaNumber "\<\d\+\> " 151" floating point number, with dot, optional exponent 152syn match luaNumber "\<\d\+\.\d * \%( [ eE ][ -+ ] \=\d\+\)\= " 153" floating point number, starting with a dot, optional exponent 154syn match luaNumber "\.\d\+\%( [ eE ][ -+ ] \=\d\+\)\=\> " 155" floating point number, without dot, with exponent 156syn match luaNumber "\<\d\+ [ eE ][ -+ ] \=\d\+\> " 157 158" hex numbers 159if lua_version >= 5 160if lua_subversion == 1 161syn match luaNumber "\<0 [ xX ] \x\+\> " 162elseif lua_subversion >= 2 163syn match luaNumber "\<0 [ xX ][ [:xdigit: ] .]\+\%( [ pP ][ -+ ] \=\d\+\)\=\> " 164endif 165endif 166 167" tables 168syn region luaTableBlock transparent matchgroup = luaTable start = "{ "end = "} "contains = TOP , luaStatement 169 170" methods 171syntax match luaFunc ":\@<=\k\+ " 172 173" built-in functions 174syn keyword luaFunc assert collectgarbage dofile error next 175syn keyword luaFunc rawget rawset self tonumber tostring type _VERSION 176 177if lua_version == 4 178syn keyword luaFunc _ALERT _ERRORMESSAGE gcinfo 179syn keyword luaFunc call copytagmethods dostring 180syn keyword luaFunc foreach foreachi getglobal getn 181syn keyword luaFunc gettagmethod globals newtag 182syn keyword luaFunc setglobal settag settagmethod sort 183syn keyword luaFunc tag tinsert tremove 184syn keyword luaFunc _INPUT _OUTPUT _STDIN _STDOUT _STDERR 185syn keyword luaFunc openfile closefile flush seek 186syn keyword luaFunc setlocale execute remove rename tmpname 187syn keyword luaFunc getenv date clock exit 188syn keyword luaFunc readfrom writeto appendto read write 189syn keyword luaFunc PI abs sin cos tan asin 190syn keyword luaFunc acos atan atan2 ceil floor 191syn keyword luaFunc mod frexp ldexp sqrt min max log 192syn keyword luaFunc log10 exp deg rad random 193syn keyword luaFunc randomseed strlen strsub strlower strupper 194syn keyword luaFunc strchar strrep ascii strbyte 195syn keyword luaFunc format strfind gsub 196syn keyword luaFunc getinfo getlocal setlocal setcallhook setlinehook 197elseif lua_version == 5 198syn keyword luaFunc getmetatable setmetatable 199syn keyword luaFunc ipairs pairs 200syn keyword luaFunc pcall xpcall 201syn keyword luaFunc _G loadfile rawequal require 202if lua_subversion == 0 203syn keyword luaFunc getfenv setfenv 204syn keyword luaFunc loadstring unpack 205syn keyword luaFunc gcinfo loadlib LUA_PATH _LOADED _REQUIREDNAME 206else 207syn keyword luaFunc load select 208syn match luaFunc /\<package\.cpath\> / 209syn match luaFunc /\<package\.loaded\> / 210syn match luaFunc /\<package\.loadlib\> / 211syn match luaFunc /\<package\.path\> / 212syn match luaFunc /\<package\.preload\> / 213if lua_subversion == 1 214syn keyword luaFunc getfenv setfenv 215syn keyword luaFunc loadstring module unpack 216syn match luaFunc /\<package\.loaders\> / 217syn match luaFunc /\<package\.seeall\> / 218elseif lua_subversion >= 2 219syn keyword luaFunc _ENV rawlen 220syn match luaFunc /\<package\.config\> / 221syn match luaFunc /\<package\.preload\> / 222syn match luaFunc /\<package\.searchers\> / 223syn match luaFunc /\<package\.searchpath\> / 224endif 225 226if lua_subversion >= 3 227syn match luaFunc /\<coroutine\.isyieldable\> / 228endif 229if lua_subversion >= 4 230syn keyword luaFunc warn 231syn match luaFunc /\<coroutine\.close\> / 232endif 233syn match luaFunc /\<coroutine\.running\> / 234endif 235syn match luaFunc /\<coroutine\.create\> / 236syn match luaFunc /\<coroutine\.resume\> / 237syn match luaFunc /\<coroutine\.status\> / 238syn match luaFunc /\<coroutine\.wrap\> / 239syn match luaFunc /\<coroutine\.yield\> / 240 241syn match luaFunc /\<string\.byte\> / 242syn match luaFunc /\<string\.char\> / 243syn match luaFunc /\<string\.dump\> / 244syn match luaFunc /\<string\.find\> / 245syn match luaFunc /\<string\.format\> / 246syn match luaFunc /\<string\.gsub\> / 247syn match luaFunc /\<string\.len\> / 248syn match luaFunc /\<string\.lower\> / 249syn match luaFunc /\<string\.rep\> / 250syn match luaFunc /\<string\.sub\> / 251syn match luaFunc /\<string\.upper\> / 252if lua_subversion == 0 253syn match luaFunc /\<string\.gfind\> / 254else 255syn match luaFunc /\<string\.gmatch\> / 256syn match luaFunc /\<string\.match\> / 257syn match luaFunc /\<string\.reverse\> / 258endif 259if lua_subversion >= 3 260syn match luaFunc /\<string\.pack\> / 261syn match luaFunc /\<string\.packsize\> / 262syn match luaFunc /\<string\.unpack\> / 263syn match luaFunc /\<utf8\.char\> / 264syn match luaFunc /\<utf8\.charpattern\> / 265syn match luaFunc /\<utf8\.codes\> / 266syn match luaFunc /\<utf8\.codepoint\> / 267syn match luaFunc /\<utf8\.len\> / 268syn match luaFunc /\<utf8\.offset\> / 269endif 270 271if lua_subversion == 0 272syn match luaFunc /\<table\.getn\> / 273syn match luaFunc /\<table\.setn\> / 274syn match luaFunc /\<table\.foreach\> / 275syn match luaFunc /\<table\.foreachi\> / 276elseif lua_subversion == 1 277syn match luaFunc /\<table\.maxn\> / 278elseif lua_subversion >= 2 279syn match luaFunc /\<table\.pack\> / 280syn match luaFunc /\<table\.unpack\> / 281if lua_subversion >= 3 282syn match luaFunc /\<table\.move\> / 283endif 284endif 285syn match luaFunc /\<table\.concat\> / 286syn match luaFunc /\<table\.insert\> / 287syn match luaFunc /\<table\.sort\> / 288syn match luaFunc /\<table\.remove\> / 289 290if lua_subversion == 2 291syn match luaFunc /\<bit32\.arshift\> / 292syn match luaFunc /\<bit32\.band\> / 293syn match luaFunc /\<bit32\.bnot\> / 294syn match luaFunc /\<bit32\.bor\> / 295syn match luaFunc /\<bit32\.btest\> / 296syn match luaFunc /\<bit32\.bxor\> / 297syn match luaFunc /\<bit32\.extract\> / 298syn match luaFunc /\<bit32\.lrotate\> / 299syn match luaFunc /\<bit32\.lshift\> / 300syn match luaFunc /\<bit32\.replace\> / 301syn match luaFunc /\<bit32\.rrotate\> / 302syn match luaFunc /\<bit32\.rshift\> / 303endif 304 305syn match luaFunc /\<math\.abs\> / 306syn match luaFunc /\<math\.acos\> / 307syn match luaFunc /\<math\.asin\> / 308syn match luaFunc /\<math\.atan\> / 309if lua_subversion < 3 310syn match luaFunc /\<math\.atan2\> / 311endif 312syn match luaFunc /\<math\.ceil\> / 313syn match luaFunc /\<math\.sin\> / 314syn match luaFunc /\<math\.cos\> / 315syn match luaFunc /\<math\.tan\> / 316syn match luaFunc /\<math\.deg\> / 317syn match luaFunc /\<math\.exp\> / 318syn match luaFunc /\<math\.floor\> / 319syn match luaFunc /\<math\.log\> / 320syn match luaFunc /\<math\.max\> / 321syn match luaFunc /\<math\.min\> / 322if lua_subversion == 0 323syn match luaFunc /\<math\.mod\> / 324syn match luaFunc /\<math\.log10\> / 325elseif lua_subversion == 1 326syn match luaFunc /\<math\.log10\> / 327endif 328if lua_subversion >= 1 329syn match luaFunc /\<math\.huge\> / 330syn match luaFunc /\<math\.fmod\> / 331syn match luaFunc /\<math\.modf\> / 332if lua_subversion == 1 || lua_subversion == 2 333syn match luaFunc /\<math\.cosh\> / 334syn match luaFunc /\<math\.sinh\> / 335syn match luaFunc /\<math\.tanh\> / 336endif 337endif 338syn match luaFunc /\<math\.rad\> / 339syn match luaFunc /\<math\.sqrt\> / 340if lua_subversion < 3 341syn match luaFunc /\<math\.pow\> / 342syn match luaFunc /\<math\.frexp\> / 343syn match luaFunc /\<math\.ldexp\> / 344else 345syn match luaFunc /\<math\.maxinteger\> / 346syn match luaFunc /\<math\.mininteger\> / 347syn match luaFunc /\<math\.tointeger\> / 348syn match luaFunc /\<math\.type\> / 349syn match luaFunc /\<math\.ult\> / 350endif 351syn match luaFunc /\<math\.random\> / 352syn match luaFunc /\<math\.randomseed\> / 353syn match luaFunc /\<math\.pi\> / 354 355syn match luaFunc /\<io\.close\> / 356syn match luaFunc /\<io\.flush\> / 357syn match luaFunc /\<io\.input\> / 358syn match luaFunc /\<io\.lines\> / 359syn match luaFunc /\<io\.open\> / 360syn match luaFunc /\<io\.output\> / 361syn match luaFunc /\<io\.popen\> / 362syn match luaFunc /\<io\.read\> / 363syn match luaFunc /\<io\.stderr\> / 364syn match luaFunc /\<io\.stdin\> / 365syn match luaFunc /\<io\.stdout\> / 366syn match luaFunc /\<io\.tmpfile\> / 367syn match luaFunc /\<io\.type\> / 368syn match luaFunc /\<io\.write\> / 369 370syn match luaFunc /\<os\.clock\> / 371syn match luaFunc /\<os\.date\> / 372syn match luaFunc /\<os\.difftime\> / 373syn match luaFunc /\<os\.execute\> / 374syn match luaFunc /\<os\.exit\> / 375syn match luaFunc /\<os\.getenv\> / 376syn match luaFunc /\<os\.remove\> / 377syn match luaFunc /\<os\.rename\> / 378syn match luaFunc /\<os\.setlocale\> / 379syn match luaFunc /\<os\.time\> / 380syn match luaFunc /\<os\.tmpname\> / 381 382syn match luaFunc /\<debug\.debug\> / 383syn match luaFunc /\<debug\.gethook\> / 384syn match luaFunc /\<debug\.getinfo\> / 385syn match luaFunc /\<debug\.getlocal\> / 386syn match luaFunc /\<debug\.getupvalue\> / 387syn match luaFunc /\<debug\.setlocal\> / 388syn match luaFunc /\<debug\.setupvalue\> / 389syn match luaFunc /\<debug\.sethook\> / 390syn match luaFunc /\<debug\.traceback\> / 391if lua_subversion == 1 392syn match luaFunc /\<debug\.getfenv\> / 393syn match luaFunc /\<debug\.setfenv\> / 394endif 395if lua_subversion >= 1 396syn match luaFunc /\<debug\.getmetatable\> / 397syn match luaFunc /\<debug\.setmetatable\> / 398syn match luaFunc /\<debug\.getregistry\> / 399if lua_subversion >= 2 400syn match luaFunc /\<debug\.getuservalue\> / 401syn match luaFunc /\<debug\.setuservalue\> / 402syn match luaFunc /\<debug\.upvalueid\> / 403syn match luaFunc /\<debug\.upvaluejoin\> / 404endif 405if lua_subversion >= 4 406syn match luaFunc /\<debug.setcstacklimit\> / 407endif 408endif 409endif 410 411" Define the default highlighting. 412" Only when an item doesn't have highlighting yet 413 414hi def link luaStatement Statement 415hi def link luaRepeat Repeat 416hi def link luaFor Repeat 417hi def link luaString String 418hi def link luaString2 String 419hi def link luaStringDelimiter luaString 420hi def link luaNumber Number 421hi def link luaOperator Operator 422hi def link luaSymbolOperator luaOperator 423hi def link luaConstant Constant 424hi def link luaCond Conditional 425hi def link luaCondElse Conditional 426hi def link luaFunction Function 427hi def link luaMetaMethod Function 428hi def link luaComment Comment 429hi def link luaCommentDelimiter luaComment 430hi def link luaTodo Todo 431hi def link luaTable Structure 432hi def link luaError Error 433hi def link luaParenError Error 434hi def link luaSpecial SpecialChar 435hi def link luaFunc Identifier 436hi def link luaLabel Label 437 438 439let b: current_syntax = "lua" 440 441let & cpo = s: cpo_save 442unlet s: cpo_save 443" vim: et ts=8 sw=2