if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'vim') == -1 " Vim syntax file " Language: Lua 4.0, Lua 5.0, Lua 5.1 and Lua 5.2 " Maintainer: Marcus Aurelius Farias " First Author: Carlos Augusto Teixeira Mendes " Last Change: 2012 Aug 12 " Options: lua_version = 4 or 5 " lua_subversion = 0 (4.0, 5.0) or 1 (5.1) or 2 (5.2) " default 5.2 " quit when a syntax file was already loaded if exists("b:current_syntax") finish endif let s:cpo_save = &cpo set cpo&vim if !exists("lua_version") " Default is lua 5.2 let lua_version = 5 let lua_subversion = 2 elseif !exists("lua_subversion") " lua_version exists, but lua_subversion doesn't. So, set it to 0 let lua_subversion = 0 endif syn case match " syncing method syn sync minlines=100 " Comments syn keyword luaTodo contained TODO FIXME XXX syn match luaComment "--.*$" contains=luaTodo,@Spell if lua_version == 5 && lua_subversion == 0 syn region luaComment matchgroup=luaComment start="--\[\[" end="\]\]" contains=luaTodo,luaInnerComment,@Spell syn region luaInnerComment contained transparent start="\[\[" end="\]\]" elseif lua_version > 5 || (lua_version == 5 && lua_subversion >= 1) " Comments in Lua 5.1: --[[ ... ]], [=[ ... ]=], [===[ ... ]===], etc. syn region luaComment matchgroup=luaComment start="--\[\z(=*\)\[" end="\]\z1\]" contains=luaTodo,@Spell endif " First line may start with #! syn match luaComment "\%^#!.*" " catch errors caused by wrong parenthesis and wrong curly brackets or " keywords placed outside their respective blocks syn region luaParen transparent start='(' end=')' contains=ALLBUT,luaParenError,luaTodo,luaSpecial,luaIfThen,luaElseifThen,luaElse,luaThenEnd,luaBlock,luaLoopBlock,luaIn,luaStatement syn region luaTableBlock transparent matchgroup=luaTable start="{" end="}" contains=ALLBUT,luaBraceError,luaTodo,luaSpecial,luaIfThen,luaElseifThen,luaElse,luaThenEnd,luaBlock,luaLoopBlock,luaIn,luaStatement syn match luaParenError ")" syn match luaBraceError "}" syn match luaError "\<\%(end\|else\|elseif\|then\|until\|in\)\>" " function ... end syn region luaFunctionBlock transparent matchgroup=luaFunction start="\" end="\" contains=ALLBUT,luaTodo,luaSpecial,luaElseifThen,luaElse,luaThenEnd,luaIn " if ... then syn region luaIfThen transparent matchgroup=luaCond start="\" end="\"me=e-4 contains=ALLBUT,luaTodo,luaSpecial,luaElseifThen,luaElse,luaIn nextgroup=luaThenEnd skipwhite skipempty " then ... end syn region luaThenEnd contained transparent matchgroup=luaCond start="\" end="\" contains=ALLBUT,luaTodo,luaSpecial,luaThenEnd,luaIn " elseif ... then syn region luaElseifThen contained transparent matchgroup=luaCond start="\" end="\" contains=ALLBUT,luaTodo,luaSpecial,luaElseifThen,luaElse,luaThenEnd,luaIn " else syn keyword luaElse contained else " do ... end syn region luaBlock transparent matchgroup=luaStatement start="\" end="\" contains=ALLBUT,luaTodo,luaSpecial,luaElseifThen,luaElse,luaThenEnd,luaIn " repeat ... until syn region luaLoopBlock transparent matchgroup=luaRepeat start="\" end="\" contains=ALLBUT,luaTodo,luaSpecial,luaElseifThen,luaElse,luaThenEnd,luaIn " while ... do syn region luaLoopBlock transparent matchgroup=luaRepeat start="\" end="\"me=e-2 contains=ALLBUT,luaTodo,luaSpecial,luaIfThen,luaElseifThen,luaElse,luaThenEnd,luaIn nextgroup=luaBlock skipwhite skipempty " for ... do and for ... in ... do syn region luaLoopBlock transparent matchgroup=luaRepeat start="\" end="\"me=e-2 contains=ALLBUT,luaTodo,luaSpecial,luaIfThen,luaElseifThen,luaElse,luaThenEnd nextgroup=luaBlock skipwhite skipempty syn keyword luaIn contained in " other keywords syn keyword luaStatement return local break if lua_version > 5 || (lua_version == 5 && lua_subversion >= 2) syn keyword luaStatement goto syn match luaLabel "::\I\i*::" endif syn keyword luaOperator and or not syn keyword luaConstant nil if lua_version > 4 syn keyword luaConstant true false endif " Strings if lua_version < 5 syn match luaSpecial contained "\\[\\abfnrtv\'\"]\|\\[[:digit:]]\{,3}" elseif lua_version == 5 if lua_subversion == 0 syn match luaSpecial contained #\\[\\abfnrtv'"[\]]\|\\[[:digit:]]\{,3}# syn region luaString2 matchgroup=luaString start=+\[\[+ end=+\]\]+ contains=luaString2,@Spell else if lua_subversion == 1 syn match luaSpecial contained #\\[\\abfnrtv'"]\|\\[[:digit:]]\{,3}# else " Lua 5.2 syn match luaSpecial contained #\\[\\abfnrtvz'"]\|\\x[[:xdigit:]]\{2}\|\\[[:digit:]]\{,3}# endif syn region luaString2 matchgroup=luaString start="\[\z(=*\)\[" end="\]\z1\]" contains=@Spell endif endif syn region luaString start=+'+ end=+'+ skip=+\\\\\|\\'+ contains=luaSpecial,@Spell syn region luaString start=+"+ end=+"+ skip=+\\\\\|\\"+ contains=luaSpecial,@Spell " integer number syn match luaNumber "\<\d\+\>" " floating point number, with dot, optional exponent syn match luaNumber "\<\d\+\.\d*\%([eE][-+]\=\d\+\)\=\>" " floating point number, starting with a dot, optional exponent syn match luaNumber "\.\d\+\%([eE][-+]\=\d\+\)\=\>" " floating point number, without dot, with exponent syn match luaNumber "\<\d\+[eE][-+]\=\d\+\>" " hex numbers if lua_version >= 5 if lua_subversion == 1 syn match luaNumber "\<0[xX]\x\+\>" elseif lua_subversion >= 2 syn match luaNumber "\<0[xX][[:xdigit:].]\+\%([pP][-+]\=\d\+\)\=\>" endif endif syn keyword luaFunc assert collectgarbage dofile error next syn keyword luaFunc print rawget rawset tonumber tostring type _VERSION if lua_version == 4 syn keyword luaFunc _ALERT _ERRORMESSAGE gcinfo syn keyword luaFunc call copytagmethods dostring syn keyword luaFunc foreach foreachi getglobal getn syn keyword luaFunc gettagmethod globals newtag syn keyword luaFunc setglobal settag settagmethod sort syn keyword luaFunc tag tinsert tremove syn keyword luaFunc _INPUT _OUTPUT _STDIN _STDOUT _STDERR syn keyword luaFunc openfile closefile flush seek syn keyword luaFunc setlocale execute remove rename tmpname syn keyword luaFunc getenv date clock exit syn keyword luaFunc readfrom writeto appendto read write syn keyword luaFunc PI abs sin cos tan asin syn keyword luaFunc acos atan atan2 ceil floor syn keyword luaFunc mod frexp ldexp sqrt min max log syn keyword luaFunc log10 exp deg rad random syn keyword luaFunc randomseed strlen strsub strlower strupper syn keyword luaFunc strchar strrep ascii strbyte syn keyword luaFunc format strfind gsub syn keyword luaFunc getinfo getlocal setlocal setcallhook setlinehook elseif lua_version == 5 syn keyword luaFunc getmetatable setmetatable syn keyword luaFunc ipairs pairs syn keyword luaFunc pcall xpcall syn keyword luaFunc _G loadfile rawequal require if lua_subversion == 0 syn keyword luaFunc getfenv setfenv syn keyword luaFunc loadstring unpack syn keyword luaFunc gcinfo loadlib LUA_PATH _LOADED _REQUIREDNAME else syn keyword luaFunc load select syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ if lua_subversion == 1 syn keyword luaFunc getfenv setfenv syn keyword luaFunc loadstring module unpack syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ elseif lua_subversion == 2 syn keyword luaFunc _ENV rawlen syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ endif syn match luaFunc /\/ endif syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ if lua_subversion == 0 syn match luaFunc /\/ else syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ endif if lua_subversion == 0 syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ elseif lua_subversion == 1 syn match luaFunc /\/ elseif lua_subversion == 2 syn match luaFunc /\/ syn match luaFunc /\/ endif syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ if lua_subversion == 0 syn match luaFunc /\/ syn match luaFunc /\/ else if lua_subversion == 1 syn match luaFunc /\/ endif syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ endif syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ if lua_subversion == 1 syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ elseif lua_subversion == 2 syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ syn match luaFunc /\/ endif endif " Define the default highlighting. " Only when an item doesn't have highlighting yet hi def link luaStatement Statement hi def link luaRepeat Repeat hi def link luaFor Repeat hi def link luaString String hi def link luaString2 String hi def link luaNumber Number hi def link luaOperator Operator hi def link luaIn Operator hi def link luaConstant Constant hi def link luaCond Conditional hi def link luaElse Conditional hi def link luaFunction Function hi def link luaComment Comment hi def link luaTodo Todo hi def link luaTable Structure hi def link luaError Error hi def link luaParenError Error hi def link luaBraceError Error hi def link luaSpecial SpecialChar hi def link luaFunc Identifier hi def link luaLabel Label let b:current_syntax = "lua" let &cpo = s:cpo_save unlet s:cpo_save " vim: et ts=8 sw=2 endif if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'lua') == -1 " Vim syntax file " Language: Lua " URL: https://github.com/tbastos/vim-lua if !exists("main_syntax") if version < 600 syntax clear elseif exists("b:current_syntax") finish endif let main_syntax = 'lua' endif syntax sync fromstart function! s:FoldableRegion(tag, name, expr) let synexpr = 'syntax region ' . a:name . ' ' . a:expr let pfx = 'g:lua_syntax_fold_' if !exists('g:lua_syntax_nofold') || exists(pfx . a:tag) || exists(pfx . a:name) let synexpr .= ' fold' end exec synexpr endfunction " Clusters syntax cluster luaBase contains=luaComment,luaCommentLong,luaConstant,luaNumber,luaString,luaStringLong,luaBuiltIn syntax cluster luaExpr contains=@luaBase,luaTable,luaParen,luaBracket,luaSpecialTable,luaSpecialValue,luaOperator,luaSymbolOperator,luaEllipsis,luaComma,luaFunc,luaFuncCall,luaError syntax cluster luaStat \ contains=@luaExpr,luaIfThen,luaBlock,luaLoop,luaGoto,luaLabel,luaLocal,luaStatement,luaSemiCol,luaErrHand syntax match luaNoise /\%(\.\|,\|:\|\;\)/ " Symbols call s:FoldableRegion('table', 'luaTable', \ 'transparent matchgroup=luaBraces start="{" end="}" contains=@luaExpr') syntax region luaParen transparent matchgroup=luaParens start='(' end=')' contains=@luaExpr syntax region luaBracket transparent matchgroup=luaBrackets start="\[" end="\]" contains=@luaExpr syntax match luaComma "," syntax match luaSemiCol ";" if !exists('g:lua_syntax_nosymboloperator') syntax match luaSymbolOperator "[#<>=~^&|*/%+-]\|\.\." endi syntax match luaEllipsis "\.\.\." " Catch errors caused by unbalanced brackets and keywords syntax match luaError ")" syntax match luaError "}" syntax match luaError "\]" syntax match luaError "\<\%(end\|else\|elseif\|then\|until\)\>" " Shebang at the start syntax match luaComment "\%^#!.*" " Comments syntax keyword luaCommentTodo contained TODO FIXME XXX TBD syntax match luaComment "--.*$" contains=luaCommentTodo,luaDocTag,@Spell call s:FoldableRegion('comment', 'luaCommentLong', \ 'matchgroup=luaCommentLongTag start="--\[\z(=*\)\[" end="\]\z1\]" contains=luaCommentTodo,luaDocTag,@Spell') syntax match luaDocTag contained "\s@\k\+" " Function calls syntax match luaFuncCall /\k\+\%(\s*[{('"]\)\@=/ " Functions call s:FoldableRegion('function', 'luaFunc', \ 'transparent matchgroup=luaFuncKeyword start="\" end="\" contains=@luaStat,luaFuncSig') syntax region luaFuncSig contained transparent start="\(\\)\@<=" end=")" contains=luaFuncId,luaFuncArgs keepend syntax match luaFuncId contained "[^(]*(\@=" contains=luaFuncTable,luaFuncName syntax match luaFuncTable contained /\k\+\%(\s*[.:]\)\@=/ syntax match luaFuncName contained "[^(.:]*(\@=" syntax region luaFuncArgs contained transparent matchgroup=luaFuncParens start=/(/ end=/)/ contains=@luaBase,luaFuncArgName,luaFuncArgComma,luaEllipsis syntax match luaFuncArgName contained /\k\+/ syntax match luaFuncArgComma contained /,/ " if ... then syntax region luaIfThen transparent matchgroup=luaCond start="\" end="\"me=e-4 contains=@luaExpr nextgroup=luaThenEnd skipwhite skipempty " then ... end call s:FoldableRegion('control', 'luaThenEnd', \ 'contained transparent matchgroup=luaCond start="\" end="\" contains=@luaStat,luaElseifThen,luaElse') " elseif ... then syntax region luaElseifThen contained transparent matchgroup=luaCond start="\" end="\" contains=@luaExpr " else syntax keyword luaElse contained else " do ... end call s:FoldableRegion('control', 'luaLoopBlock', \ 'transparent matchgroup=luaRepeat start="\" end="\" contains=@luaStat contained') call s:FoldableRegion('control', 'luaBlock', \ 'transparent matchgroup=luaStatement start="\" end="\" contains=@luaStat') " repeat ... until call s:FoldableRegion('control', 'luaLoop', \ 'transparent matchgroup=luaRepeat start="\" end="\" contains=@luaStat nextgroup=@luaExpr') " while ... do syntax region luaLoop transparent matchgroup=luaRepeat start="\" end="\"me=e-2 contains=@luaExpr nextgroup=luaLoopBlock skipwhite skipempty " for ... do and for ... in ... do syntax region luaLoop transparent matchgroup=luaRepeat start="\" end="\"me=e-2 contains=@luaExpr,luaIn nextgroup=luaLoopBlock skipwhite skipempty syntax keyword luaIn contained in " goto and labels syntax keyword luaGoto goto nextgroup=luaGotoLabel skipwhite syntax match luaGotoLabel "\k\+" contained syntax match luaLabel "::\k\+::" " Other Keywords syntax keyword luaConstant nil true false syntax keyword luaBuiltIn _ENV self syntax keyword luaLocal local syntax keyword luaOperator and or not syntax keyword luaStatement break return " Strings syntax match luaStringSpecial contained #\\[\\abfnrtvz'"]\|\\x[[:xdigit:]]\{2}\|\\[[:digit:]]\{,3}# call s:FoldableRegion('string', 'luaStringLong', \ 'matchgroup=luaStringLongTag start="\[\z(=*\)\[" end="\]\z1\]" contains=@Spell') syntax region luaString start=+'+ end=+'+ skip=+\\\\\|\\'+ contains=luaStringSpecial,@Spell syntax region luaString start=+"+ end=+"+ skip=+\\\\\|\\"+ contains=luaStringSpecial,@Spell " Decimal constant syntax match luaNumber "\<\d\+\>" " Hex constant syntax match luaNumber "\<0[xX][[:xdigit:].]\+\%([pP][-+]\=\d\+\)\=\>" " Floating point constant, with dot, optional exponent syntax match luaFloat "\<\d\+\.\d*\%([eE][-+]\=\d\+\)\=\>" " Floating point constant, starting with a dot, optional exponent syntax match luaFloat "\.\d\+\%([eE][-+]\=\d\+\)\=\>" " Floating point constant, without dot, with exponent syntax match luaFloat "\<\d\+[eE][-+]\=\d\+\>" " Special names from the Standard Library if !exists('g:lua_syntax_nostdlib') syntax keyword luaSpecialValue \ module \ require syntax keyword luaSpecialTable _G syntax keyword luaErrHand \ assert \ error \ pcall \ xpcall if !exists('g:lua_syntax_noextendedstdlib') syntax keyword luaSpecialTable \ bit32 \ coroutine \ debug \ io \ math \ os \ package \ string \ table \ utf8 syntax keyword luaSpecialValue \ _VERSION \ collectgarbage \ dofile \ getfenv \ getmetatable \ ipairs \ load \ loadfile \ loadstring \ next \ pairs \ print \ rawequal \ rawget \ rawlen \ rawset \ select \ setfenv \ setmetatable \ tonumber \ tostring \ type \ unpack endif endif " Define the default highlighting. " For version 5.7 and earlier: only when not done already " For version 5.8 and later: only when an item doesn't have highlighting yet if version >= 508 || !exists("did_lua_syn_inits") if version < 508 let did_lua_syn_inits = 1 command -nargs=+ HiLink hi link else command -nargs=+ HiLink hi def link endif HiLink luaParens Noise HiLink luaBraces Structure HiLink luaBrackets Noise HiLink luaBuiltIn Special HiLink luaComment Comment HiLink luaCommentLongTag luaCommentLong HiLink luaCommentLong luaComment HiLink luaCommentTodo Todo HiLink luaCond Conditional HiLink luaConstant Constant HiLink luaDocTag Underlined HiLink luaEllipsis Special HiLink luaElse Conditional HiLink luaError Error HiLink luaFloat Float HiLink luaFuncArgName Noise HiLink luaFuncCall PreProc HiLink luaFuncId Function HiLink luaFuncName luaFuncId HiLink luaFuncTable luaFuncId HiLink luaFuncKeyword luaFunction HiLink luaFunction Structure HiLink luaFuncParens Noise HiLink luaGoto luaStatement HiLink luaGotoLabel Noise HiLink luaIn Repeat HiLink luaLabel Label HiLink luaLocal Type HiLink luaNumber Number HiLink luaSymbolOperator luaOperator HiLink luaOperator Operator HiLink luaRepeat Repeat HiLink luaSemiCol Delimiter HiLink luaSpecialTable Special HiLink luaSpecialValue PreProc HiLink luaStatement Statement HiLink luaString String HiLink luaStringLong luaString HiLink luaStringSpecial SpecialChar HiLink luaErrHand Exception delcommand HiLink end let b:current_syntax = "lua" if main_syntax == 'lua' unlet main_syntax endif endif