Bram Moolenaar | 8424a62 | 2006-04-19 21:23:36 +0000 | [diff] [blame^] | 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 Apr. 19
|
| 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
|
| 12 | if version < 600
|
| 13 | syntax clear
|
| 14 | elseif exists("b:current_syntax")
|
| 15 | finish
|
| 16 | endif
|
| 17 |
|
| 18 | if !exists("lua_version")
|
| 19 | " Default is lua 5.1
|
| 20 | let lua_version = 5
|
| 21 | let lua_subversion = 1
|
| 22 | elseif !exists("lua_subversion")
|
| 23 | " lua_version exists, but lua_subversion doesn't. So, set it to 0
|
| 24 | let lua_subversion = 0
|
| 25 | endif
|
| 26 |
|
| 27 | syn case match
|
| 28 |
|
| 29 | " syncing method
|
| 30 | syn sync minlines=100
|
| 31 |
|
| 32 | " Comments
|
| 33 | syn keyword luaTodo contained TODO FIXME XXX
|
| 34 | syn match luaComment "--.*$" contains=luaTodo
|
| 35 | if lua_version == 5 && lua_subversion == 0
|
| 36 | syn region luaComment matchgroup=luaComment start="--\[\[" end="\]\]" contains=luaTodo,luaInnerComment
|
| 37 | syn region luaInnerComment contained transparent start="\[\[" end="\]\]"
|
| 38 | elseif 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\]"
|
| 41 | endif
|
| 42 |
|
| 43 | " First line may start with #!
|
| 44 | syn match luaComment "\%^#!.*"
|
| 45 |
|
| 46 | " catch errors caused by wrong parenthesis and wrong curly brackets or
|
| 47 | " keywords placed outside their respective blocks
|
| 48 |
|
| 49 | syn region luaParen transparent start='(' end=')' contains=ALLBUT,luaError,luaTodo,luaSpecial,luaCond,luaCondElseif,luaCondEnd,luaCondStart,luaBlock,luaRepeatBlock,luaRepeat,luaStatement
|
| 50 | syn match luaError ")"
|
| 51 | syn match luaError "}"
|
| 52 | syn match luaError "\<\%(end\|else\|elseif\|then\|until\|in\)\>"
|
| 53 |
|
| 54 | " Function declaration
|
| 55 | syn region luaFunctionBlock transparent matchgroup=luaFunction start="\<function\>" end="\<end\>" contains=ALLBUT,luaTodo,luaSpecial,luaCond,luaCondElseif,luaCondEnd,luaRepeat
|
| 56 |
|
| 57 | " if then else elseif end
|
| 58 | syn keyword luaCond contained else
|
| 59 |
|
| 60 | " then ... end
|
| 61 | syn region luaCondEnd contained transparent matchgroup=luaCond start="\<then\>" end="\<end\>" contains=ALLBUT,luaTodo,luaSpecial,luaRepeat
|
| 62 |
|
| 63 | " elseif ... then
|
| 64 | syn region luaCondElseif contained transparent matchgroup=luaCond start="\<elseif\>" end="\<then\>" contains=ALLBUT,luaTodo,luaSpecial,luaCond,luaCondElseif,luaCondEnd,luaRepeat
|
| 65 |
|
| 66 | " if ... then
|
| 67 | syn 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
|
| 70 | syn region luaBlock transparent matchgroup=luaStatement start="\<do\>" end="\<end\>" contains=ALLBUT,luaTodo,luaSpecial,luaCond,luaCondElseif,luaCondEnd,luaRepeat
|
| 71 |
|
| 72 | " repeat ... until
|
| 73 | syn region luaRepeatBlock transparent matchgroup=luaRepeat start="\<repeat\>" end="\<until\>" contains=ALLBUT,luaTodo,luaSpecial,luaCond,luaCondElseif,luaCondEnd,luaRepeat
|
| 74 |
|
| 75 | " while ... do
|
| 76 | syn 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
|
| 79 | syn 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.
|
| 83 | syn keyword luaRepeat contained in
|
| 84 |
|
| 85 | " other keywords
|
| 86 | syn keyword luaStatement return local break
|
| 87 | syn keyword luaOperator and or not
|
| 88 | syn keyword luaConstant nil
|
| 89 | if lua_version > 4
|
| 90 | syn keyword luaConstant true false
|
| 91 | endif
|
| 92 |
|
| 93 | " Strings
|
| 94 | syn match luaSpecial contained "\\[\\abfnrtv\'\"[\]]\|\\\d\{,3}"
|
| 95 | syn region luaString start=+'+ end=+'+ skip=+\\\\\|\\'+ contains=luaSpecial
|
| 96 | syn region luaString start=+"+ end=+"+ skip=+\\\\\|\\"+ contains=luaSpecial
|
| 97 | " Nested strings
|
| 98 | if (lua_version == 5 && lua_subversion == 0) || lua_version < 5
|
| 99 | syn region luaString2 matchgroup=luaString start=+\[\[+ end=+\]\]+ contains=luaString2
|
| 100 | elseif lua_version > 5 || (lua_version == 5 && lua_subversion >= 1)
|
| 101 | syn region luaString2 matchgroup=luaString start="\[\z(=*\)\[" end="\]\z1\]"
|
| 102 | endif
|
| 103 |
|
| 104 | " integer number
|
| 105 | syn match luaNumber "\<[0-9]\+\>"
|
| 106 | " floating point number, with dot, optional exponent
|
| 107 | syn match luaFloat "\<[0-9]\+\.[0-9]*\%(e[-+]\=[0-9]\+\)\=\>"
|
| 108 | " floating point number, starting with a dot, optional exponent
|
| 109 | syn match luaFloat "\.[0-9]\+\%(e[-+]\=[0-9]\+\)\=\>"
|
| 110 | " floating point number, without dot, with exponent
|
| 111 | syn match luaFloat "\<[0-9]\+e[-+]\=[0-9]\+\>"
|
| 112 |
|
| 113 | " tables
|
| 114 | syn region luaTableBlock transparent matchgroup=luaTable start="{" end="}" contains=ALLBUT,luaTodo,luaSpecial,luaCond,luaCondElseif,luaCondEnd,luaCondStart,luaBlock,luaRepeatBlock,luaRepeat,luaStatement
|
| 115 |
|
| 116 | syn keyword luaFunc assert collectgarbage dofile error gcinfo next
|
| 117 | syn keyword luaFunc print rawget rawset tonumber tostring type _VERSION
|
| 118 |
|
| 119 | if lua_version == 4
|
| 120 | syn keyword luaFunc _ALERT _ERRORMESSAGE
|
| 121 | syn keyword luaFunc call copytagmethods dostring
|
| 122 | syn keyword luaFunc foreach foreachi getglobal getn
|
| 123 | syn keyword luaFunc gettagmethod globals newtag
|
| 124 | syn keyword luaFunc setglobal settag settagmethod sort
|
| 125 | syn keyword luaFunc tag tinsert tremove
|
| 126 | syn keyword luaFunc _INPUT _OUTPUT _STDIN _STDOUT _STDERR
|
| 127 | syn keyword luaFunc openfile closefile flush seek
|
| 128 | syn keyword luaFunc setlocale execute remove rename tmpname
|
| 129 | syn keyword luaFunc getenv date clock exit
|
| 130 | syn keyword luaFunc readfrom writeto appendto read write
|
| 131 | syn keyword luaFunc PI abs sin cos tan asin
|
| 132 | syn keyword luaFunc acos atan atan2 ceil floor
|
| 133 | syn keyword luaFunc mod frexp ldexp sqrt min max log
|
| 134 | syn keyword luaFunc log10 exp deg rad random
|
| 135 | syn keyword luaFunc randomseed strlen strsub strlower strupper
|
| 136 | syn keyword luaFunc strchar strrep ascii strbyte
|
| 137 | syn keyword luaFunc format strfind gsub
|
| 138 | syn keyword luaFunc getinfo getlocal setlocal setcallhook setlinehook
|
| 139 | elseif lua_version == 5
|
| 140 | " Not sure if all these functions need to be highlighted...
|
| 141 | syn keyword luaFunc _G getfenv getmetatable ipairs loadfile
|
| 142 | syn keyword luaFunc loadstring pairs pcall rawequal
|
| 143 | syn keyword luaFunc require setfenv setmetatable unpack xpcall
|
| 144 | if lua_subversion == 0
|
| 145 | syn keyword luaFunc loadlib LUA_PATH _LOADED _REQUIREDNAME
|
| 146 | elseif lua_subversion == 1
|
| 147 | syn keyword luaFunc load module select
|
| 148 | syn match luaFunc /package\.cpath/
|
| 149 | syn match luaFunc /package\.loaded/
|
| 150 | syn match luaFunc /package\.loadlib/
|
| 151 | syn match luaFunc /package\.path/
|
| 152 | syn match luaFunc /package\.preload/
|
| 153 | syn match luaFunc /package\.seeall/
|
| 154 | syn match luaFunc /coroutine\.running/
|
| 155 | endif
|
| 156 | syn match luaFunc /coroutine\.create/
|
| 157 | syn match luaFunc /coroutine\.resume/
|
| 158 | syn match luaFunc /coroutine\.status/
|
| 159 | syn match luaFunc /coroutine\.wrap/
|
| 160 | syn match luaFunc /coroutine\.yield/
|
| 161 | syn match luaFunc /string\.byte/
|
| 162 | syn match luaFunc /string\.char/
|
| 163 | syn match luaFunc /string\.dump/
|
| 164 | syn match luaFunc /string\.find/
|
| 165 | syn match luaFunc /string\.len/
|
| 166 | syn match luaFunc /string\.lower/
|
| 167 | syn match luaFunc /string\.rep/
|
| 168 | syn match luaFunc /string\.sub/
|
| 169 | syn match luaFunc /string\.upper/
|
| 170 | syn match luaFunc /string\.format/
|
| 171 | syn match luaFunc /string\.gsub/
|
| 172 | if lua_subversion == 0
|
| 173 | syn match luaFunc /string\.gfind/
|
| 174 | elseif lua_subversion == 1
|
| 175 | syn match luaFunc /string\.gmatch/
|
| 176 | syn match luaFunc /string\.match/
|
| 177 | syn match luaFunc /string\.reverse/
|
| 178 | syn match luaFunc /table\.maxn/
|
| 179 | endif
|
| 180 | syn match luaFunc /table\.concat/
|
| 181 | syn match luaFunc /table\.foreach/
|
| 182 | syn match luaFunc /table\.foreachi/
|
| 183 | syn match luaFunc /table\.getn/
|
| 184 | syn match luaFunc /table\.sort/
|
| 185 | syn match luaFunc /table\.insert/
|
| 186 | syn match luaFunc /table\.remove/
|
| 187 | syn match luaFunc /table\.setn/
|
| 188 | syn match luaFunc /math\.abs/
|
| 189 | syn match luaFunc /math\.acos/
|
| 190 | syn match luaFunc /math\.asin/
|
| 191 | syn match luaFunc /math\.atan/
|
| 192 | syn match luaFunc /math\.atan2/
|
| 193 | syn match luaFunc /math\.ceil/
|
| 194 | syn match luaFunc /math\.sin/
|
| 195 | syn match luaFunc /math\.cos/
|
| 196 | syn match luaFunc /math\.tan/
|
| 197 | syn match luaFunc /math\.deg/
|
| 198 | syn match luaFunc /math\.exp/
|
| 199 | syn match luaFunc /math\.floor/
|
| 200 | syn match luaFunc /math\.log/
|
| 201 | syn match luaFunc /math\.log10/
|
| 202 | syn match luaFunc /math\.max/
|
| 203 | syn match luaFunc /math\.min/
|
| 204 | if lua_subversion == 0
|
| 205 | syn match luaFunc /math\.mod/
|
| 206 | elseif lua_subversion == 1
|
| 207 | syn match luaFunc /math\.fmod/
|
| 208 | syn match luaFunc /math\.modf/
|
| 209 | syn match luaFunc /math\.cosh/
|
| 210 | syn match luaFunc /math\.sinh/
|
| 211 | syn match luaFunc /math\.tanh/
|
| 212 | endif
|
| 213 | syn match luaFunc /math\.pow/
|
| 214 | syn match luaFunc /math\.rad/
|
| 215 | syn match luaFunc /math\.sqrt/
|
| 216 | syn match luaFunc /math\.frexp/
|
| 217 | syn match luaFunc /math\.ldexp/
|
| 218 | syn match luaFunc /math\.random/
|
| 219 | syn match luaFunc /math\.randomseed/
|
| 220 | syn match luaFunc /math\.pi/
|
| 221 | syn match luaFunc /io\.stdin/
|
| 222 | syn match luaFunc /io\.stdout/
|
| 223 | syn match luaFunc /io\.stderr/
|
| 224 | syn match luaFunc /io\.close/
|
| 225 | syn match luaFunc /io\.flush/
|
| 226 | syn match luaFunc /io\.input/
|
| 227 | syn match luaFunc /io\.lines/
|
| 228 | syn match luaFunc /io\.open/
|
| 229 | syn match luaFunc /io\.output/
|
| 230 | syn match luaFunc /io\.popen/
|
| 231 | syn match luaFunc /io\.read/
|
| 232 | syn match luaFunc /io\.tmpfile/
|
| 233 | syn match luaFunc /io\.type/
|
| 234 | syn match luaFunc /io\.write/
|
| 235 | syn match luaFunc /os\.clock/
|
| 236 | syn match luaFunc /os\.date/
|
| 237 | syn match luaFunc /os\.difftime/
|
| 238 | syn match luaFunc /os\.execute/
|
| 239 | syn match luaFunc /os\.exit/
|
| 240 | syn match luaFunc /os\.getenv/
|
| 241 | syn match luaFunc /os\.remove/
|
| 242 | syn match luaFunc /os\.rename/
|
| 243 | syn match luaFunc /os\.setlocale/
|
| 244 | syn match luaFunc /os\.time/
|
| 245 | syn match luaFunc /os\.tmpname/
|
| 246 | syn match luaFunc /debug\.debug/
|
| 247 | syn match luaFunc /debug\.gethook/
|
| 248 | syn match luaFunc /debug\.getinfo/
|
| 249 | syn match luaFunc /debug\.getlocal/
|
| 250 | syn match luaFunc /debug\.getupvalue/
|
| 251 | syn match luaFunc /debug\.setlocal/
|
| 252 | syn match luaFunc /debug\.setupvalue/
|
| 253 | syn match luaFunc /debug\.sethook/
|
| 254 | syn match luaFunc /debug\.traceback/
|
| 255 | if lua_subversion == 1
|
| 256 | syn match luaFunc /debug\.getfenv/
|
| 257 | syn match luaFunc /debug\.getmetatable/
|
| 258 | syn match luaFunc /debug\.getregistry/
|
| 259 | syn match luaFunc /debug\.setfenv/
|
| 260 | syn match luaFunc /debug\.setmetatable/
|
| 261 | endif
|
| 262 | endif
|
| 263 |
|
| 264 | " Define the default highlighting.
|
| 265 | " For version 5.7 and earlier: only when not done already
|
| 266 | " For version 5.8 and later: only when an item doesn't have highlighting yet
|
| 267 | if version >= 508 || !exists("did_lua_syntax_inits")
|
| 268 | if version < 508
|
| 269 | let did_lua_syntax_inits = 1
|
| 270 | command -nargs=+ HiLink hi link <args>
|
| 271 | else
|
| 272 | command -nargs=+ HiLink hi def link <args>
|
| 273 | endif
|
| 274 |
|
| 275 | HiLink luaStatement Statement
|
| 276 | HiLink luaRepeat Repeat
|
| 277 | HiLink luaString String
|
| 278 | HiLink luaString2 String
|
| 279 | HiLink luaNumber Number
|
| 280 | HiLink luaFloat Float
|
| 281 | HiLink luaOperator Operator
|
| 282 | HiLink luaConstant Constant
|
| 283 | HiLink luaCond Conditional
|
| 284 | HiLink luaFunction Function
|
| 285 | HiLink luaComment Comment
|
| 286 | HiLink luaTodo Todo
|
| 287 | HiLink luaTable Structure
|
| 288 | HiLink luaError Error
|
| 289 | HiLink luaSpecial SpecialChar
|
| 290 | HiLink luaFunc Identifier
|
| 291 |
|
| 292 | delcommand HiLink
|
| 293 | endif
|
| 294 |
|
| 295 | let b:current_syntax = "lua"
|
| 296 |
|
| 297 | " vim: et ts=8
|