xref: /vim-8.2.3635/runtime/syntax/lua.vim (revision fc1421eb)
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 21
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
35if 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="\]\]"
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\]"
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
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\]"
102endif
103syn region luaString  start=+'+ end=+'+ skip=+\\\\\|\\'+ contains=luaSpecial
104syn region luaString  start=+"+ end=+"+ skip=+\\\\\|\\"+ contains=luaSpecial
105
106" integer number
107syn match luaNumber "\<[0-9]\+\>"
108" floating point number, with dot, optional exponent
109syn match luaFloat  "\<[0-9]\+\.[0-9]*\%(e[-+]\=[0-9]\+\)\=\>"
110" floating point number, starting with a dot, optional exponent
111syn match luaFloat  "\.[0-9]\+\%(e[-+]\=[0-9]\+\)\=\>"
112" floating point number, without dot, with exponent
113syn match luaFloat  "\<[0-9]\+e[-+]\=[0-9]\+\>"
114
115" tables
116syn region  luaTableBlock transparent matchgroup=luaTable start="{" end="}" contains=ALLBUT,luaTodo,luaSpecial,luaCond,luaCondElseif,luaCondEnd,luaCondStart,luaBlock,luaRepeatBlock,luaRepeat,luaStatement
117
118syn keyword luaFunc assert collectgarbage dofile error next
119syn keyword luaFunc print rawget rawset tonumber tostring type _VERSION
120
121if lua_version == 4
122  syn keyword luaFunc _ALERT _ERRORMESSAGE gcinfo
123  syn keyword luaFunc call copytagmethods dostring
124  syn keyword luaFunc foreach foreachi getglobal getn
125  syn keyword luaFunc gettagmethod globals newtag
126  syn keyword luaFunc setglobal settag settagmethod sort
127  syn keyword luaFunc tag tinsert tremove
128  syn keyword luaFunc _INPUT _OUTPUT _STDIN _STDOUT _STDERR
129  syn keyword luaFunc openfile closefile flush seek
130  syn keyword luaFunc setlocale execute remove rename tmpname
131  syn keyword luaFunc getenv date clock exit
132  syn keyword luaFunc readfrom writeto appendto read write
133  syn keyword luaFunc PI abs sin cos tan asin
134  syn keyword luaFunc acos atan atan2 ceil floor
135  syn keyword luaFunc mod frexp ldexp sqrt min max log
136  syn keyword luaFunc log10 exp deg rad random
137  syn keyword luaFunc randomseed strlen strsub strlower strupper
138  syn keyword luaFunc strchar strrep ascii strbyte
139  syn keyword luaFunc format strfind gsub
140  syn keyword luaFunc getinfo getlocal setlocal setcallhook setlinehook
141elseif lua_version == 5
142  " Not sure if all these functions need to be highlighted...
143  syn keyword luaFunc _G getfenv getmetatable ipairs loadfile
144  syn keyword luaFunc loadstring pairs pcall rawequal
145  syn keyword luaFunc require setfenv setmetatable unpack xpcall
146  if lua_subversion == 0
147    syn keyword luaFunc gcinfo loadlib LUA_PATH _LOADED _REQUIREDNAME
148  elseif lua_subversion == 1
149    syn keyword luaFunc load module select
150    syn match luaFunc /package\.cpath/
151    syn match luaFunc /package\.loaded/
152    syn match luaFunc /package\.loadlib/
153    syn match luaFunc /package\.path/
154    syn match luaFunc /package\.preload/
155    syn match luaFunc /package\.seeall/
156    syn match luaFunc /coroutine\.running/
157  endif
158  syn match   luaFunc /coroutine\.create/
159  syn match   luaFunc /coroutine\.resume/
160  syn match   luaFunc /coroutine\.status/
161  syn match   luaFunc /coroutine\.wrap/
162  syn match   luaFunc /coroutine\.yield/
163  syn match   luaFunc /string\.byte/
164  syn match   luaFunc /string\.char/
165  syn match   luaFunc /string\.dump/
166  syn match   luaFunc /string\.find/
167  syn match   luaFunc /string\.len/
168  syn match   luaFunc /string\.lower/
169  syn match   luaFunc /string\.rep/
170  syn match   luaFunc /string\.sub/
171  syn match   luaFunc /string\.upper/
172  syn match   luaFunc /string\.format/
173  syn match   luaFunc /string\.gsub/
174  if lua_subversion == 0
175    syn match luaFunc /string\.gfind/
176    syn match luaFunc /table\.getn/
177    syn match luaFunc /table\.setn/
178    syn match luaFunc /table\.foreach/
179    syn match luaFunc /table\.foreachi/
180  elseif lua_subversion == 1
181    syn match luaFunc /string\.gmatch/
182    syn match luaFunc /string\.match/
183    syn match luaFunc /string\.reverse/
184    syn match luaFunc /table\.maxn/
185  endif
186  syn match   luaFunc /table\.concat/
187  syn match   luaFunc /table\.sort/
188  syn match   luaFunc /table\.insert/
189  syn match   luaFunc /table\.remove/
190  syn match   luaFunc /math\.abs/
191  syn match   luaFunc /math\.acos/
192  syn match   luaFunc /math\.asin/
193  syn match   luaFunc /math\.atan/
194  syn match   luaFunc /math\.atan2/
195  syn match   luaFunc /math\.ceil/
196  syn match   luaFunc /math\.sin/
197  syn match   luaFunc /math\.cos/
198  syn match   luaFunc /math\.tan/
199  syn match   luaFunc /math\.deg/
200  syn match   luaFunc /math\.exp/
201  syn match   luaFunc /math\.floor/
202  syn match   luaFunc /math\.log/
203  syn match   luaFunc /math\.log10/
204  syn match   luaFunc /math\.max/
205  syn match   luaFunc /math\.min/
206  if lua_subversion == 0
207    syn match luaFunc /math\.mod/
208  elseif lua_subversion == 1
209    syn match luaFunc /math\.fmod/
210    syn match luaFunc /math\.modf/
211    syn match luaFunc /math\.cosh/
212    syn match luaFunc /math\.sinh/
213    syn match luaFunc /math\.tanh/
214  endif
215  syn match   luaFunc /math\.pow/
216  syn match   luaFunc /math\.rad/
217  syn match   luaFunc /math\.sqrt/
218  syn match   luaFunc /math\.frexp/
219  syn match   luaFunc /math\.ldexp/
220  syn match   luaFunc /math\.random/
221  syn match   luaFunc /math\.randomseed/
222  syn match   luaFunc /math\.pi/
223  syn match   luaFunc /io\.stdin/
224  syn match   luaFunc /io\.stdout/
225  syn match   luaFunc /io\.stderr/
226  syn match   luaFunc /io\.close/
227  syn match   luaFunc /io\.flush/
228  syn match   luaFunc /io\.input/
229  syn match   luaFunc /io\.lines/
230  syn match   luaFunc /io\.open/
231  syn match   luaFunc /io\.output/
232  syn match   luaFunc /io\.popen/
233  syn match   luaFunc /io\.read/
234  syn match   luaFunc /io\.tmpfile/
235  syn match   luaFunc /io\.type/
236  syn match   luaFunc /io\.write/
237  syn match   luaFunc /os\.clock/
238  syn match   luaFunc /os\.date/
239  syn match   luaFunc /os\.difftime/
240  syn match   luaFunc /os\.execute/
241  syn match   luaFunc /os\.exit/
242  syn match   luaFunc /os\.getenv/
243  syn match   luaFunc /os\.remove/
244  syn match   luaFunc /os\.rename/
245  syn match   luaFunc /os\.setlocale/
246  syn match   luaFunc /os\.time/
247  syn match   luaFunc /os\.tmpname/
248  syn match   luaFunc /debug\.debug/
249  syn match   luaFunc /debug\.gethook/
250  syn match   luaFunc /debug\.getinfo/
251  syn match   luaFunc /debug\.getlocal/
252  syn match   luaFunc /debug\.getupvalue/
253  syn match   luaFunc /debug\.setlocal/
254  syn match   luaFunc /debug\.setupvalue/
255  syn match   luaFunc /debug\.sethook/
256  syn match   luaFunc /debug\.traceback/
257  if lua_subversion == 1
258    syn match luaFunc /debug\.getfenv/
259    syn match luaFunc /debug\.getmetatable/
260    syn match luaFunc /debug\.getregistry/
261    syn match luaFunc /debug\.setfenv/
262    syn match luaFunc /debug\.setmetatable/
263  endif
264endif
265
266" Define the default highlighting.
267" For version 5.7 and earlier: only when not done already
268" For version 5.8 and later: only when an item doesn't have highlighting yet
269if version >= 508 || !exists("did_lua_syntax_inits")
270  if version < 508
271    let did_lua_syntax_inits = 1
272    command -nargs=+ HiLink hi link <args>
273  else
274    command -nargs=+ HiLink hi def link <args>
275  endif
276
277  HiLink luaStatement		Statement
278  HiLink luaRepeat		Repeat
279  HiLink luaString		String
280  HiLink luaString2		String
281  HiLink luaNumber		Number
282  HiLink luaFloat		Float
283  HiLink luaOperator		Operator
284  HiLink luaConstant		Constant
285  HiLink luaCond		Conditional
286  HiLink luaFunction		Function
287  HiLink luaComment		Comment
288  HiLink luaTodo		Todo
289  HiLink luaTable		Structure
290  HiLink luaError		Error
291  HiLink luaSpecial		SpecialChar
292  HiLink luaFunc		Identifier
293
294  delcommand HiLink
295endif
296
297let b:current_syntax = "lua"
298
299" vim: et ts=8
300