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