xref: /vim-8.2.3635/runtime/syntax/lua.vim (revision 071d4279)
1" Vim syntax file
2" Language:	Lua 4.0 and Lua 5.0
3" Maintainer:	Marcus Aurelius Farias <[email protected]>
4" First Author:	Carlos Augusto Teixeira Mendes <[email protected]>
5" Last Change:	2003 May 04
6" Options:	lua_version = 4 or 5 [default]
7"
8" Still has some syncing problems (long [[strings]])...
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  let lua_version = 5
20endif
21
22syn case match
23
24" Comments
25syn keyword luaTodo		contained TODO FIXME XXX
26syn match   luaComment		"--.*$" contains=luaTodo
27if lua_version > 4
28  syn region  luaComment	matchgroup=luaComment start="--\[\[" end="\]\]" contains=luaTodo,luaInnerComment
29  syn region  luaInnerComment	contained transparent start="\[\[" end="\]\]"
30endif
31" First line may start with #!
32syn match   luaComment		"\%^#!.*"
33
34" catch errors caused by wrong parenthesis and wrong curly brackets or
35" keywords placed outside their respective blocks
36
37syn region  luaParen		transparent start='(' end=')' contains=ALLBUT,luaError,luaTodo,luaSpecial,luaCond,luaCondElseif,luaCondEnd,luaCondStart,luaBlock,luaRepeatBlock,luaRepeat,luaStatement
38syn match   luaError		")"
39syn match   luaError		"}"
40syn match   luaError		"\<\(end\|else\|elseif\|then\|until\|in\)\>"
41
42
43" Function declaration
44syn region  luaFunctionBlock    transparent matchgroup=luaFunction start="\<function\>" end="\<end\>" contains=ALLBUT,luaTodo,luaSpecial,luaCond,luaCondElseif,luaCondEnd,luaRepeat
45
46" if then else elseif end
47syn keyword luaCond		contained else
48
49" then ... end
50syn region  luaCondEnd		contained transparent matchgroup=luaCond start="\<then\>" end="\<end\>" contains=ALLBUT,luaTodo,luaSpecial,luaRepeat
51
52" elseif ... then
53syn region  luaCondElseif	contained transparent matchgroup=luaCond start="\<elseif\>" end="\<then\>" contains=ALLBUT,luaTodo,luaSpecial,luaCond,luaCondElseif,luaCondEnd,luaRepeat
54
55" if ... then
56syn region  luaCondStart	transparent matchgroup=luaCond start="\<if\>" end="\<then\>"me=e-4 contains=ALLBUT,luaTodo,luaSpecial,luaCond,luaCondElseif,luaCondEnd,luaRepeat nextgroup=luaCondEnd skipwhite skipempty
57
58" do ... end
59syn region  luaBlock		transparent matchgroup=luaStatement start="\<do\>" end="\<end\>" contains=ALLBUT,luaTodo,luaSpecial,luaCond,luaCondElseif,luaCondEnd,luaRepeat
60
61" repeat ... until
62syn region  luaRepeatBlock	transparent matchgroup=luaRepeat start="\<repeat\>" end="\<until\>" contains=ALLBUT,luaTodo,luaSpecial,luaCond,luaCondElseif,luaCondEnd,luaRepeat
63
64" while ... do
65syn region  luaRepeatBlock	transparent matchgroup=luaRepeat start="\<while\>" end="\<do\>"me=e-2 contains=ALLBUT,luaTodo,luaSpecial,luaCond,luaCondElseif,luaCondEnd,luaRepeat nextgroup=luaBlock skipwhite skipempty
66
67" for ... do and for ... in ... do
68syn region luaRepeatBlock	transparent matchgroup=luaRepeat start="\<for\>" end="\<do\>"me=e-2 contains=ALLBUT,luaTodo,luaSpecial,luaCond,luaCondElseif,luaCondEnd nextgroup=luaBlock skipwhite skipempty
69
70" Following 'else' example. This is another item to those
71" contains=ALLBUT,... because only the 'for' luaRepeatBlock contains it.
72syn keyword luaRepeat		contained in
73
74" other keywords
75syn keyword luaStatement	return local break
76syn keyword luaOperator		and or not
77syn keyword luaConstant		nil
78if lua_version > 4
79  syn keyword luaConstant	true false
80endif
81
82" Pre processor doesn't exist since Lua 4.0
83" syn match   luaPreProc	  "^\s*$\(debug\|nodebug\|if\|ifnot\|end\|else\|endinput\)\>"
84
85" Strings
86syn match   luaSpecial		contained "\\[\\abfnrtv\'\"[\]]\|\\\d\{,3}"
87syn region  luaString		start=+'+  end=+'+ skip=+\\\\\|\\'+ contains=luaSpecial
88syn region  luaString		start=+"+  end=+"+ skip=+\\\\\|\\"+ contains=luaSpecial
89" Nested strings
90syn region  luaString2		matchgroup=luaString start=+\[\[+ end=+\]\]+ contains=luaString2
91
92" integer number
93syn match luaNumber		"\<[0-9]\+\>"
94" floating point number, with dot, optional exponent
95syn match luaFloat		"\<[0-9]\+\.[0-9]*\(e[-+]\=[0-9]\+\)\=\>"
96" floating point number, starting with a dot, optional exponent
97syn match luaFloat		"\.[0-9]\+\(e[-+]\=[0-9]\+\)\=\>"
98" floating point number, without dot, with exponent
99syn match luaFloat		"\<[0-9]\+e[-+]\=[0-9]\+\>"
100
101" tables
102syn region  luaTableBlock       transparent matchgroup=luaTable start="{" end="}" contains=ALLBUT,luaTodo,luaSpecial,luaCond,luaCondElseif,luaCondEnd,luaCondStart,luaBlock,luaRepeatBlock,luaRepeat,luaStatement
103
104syn keyword luaFunc	assert collectgarbage dofile error gcinfo next
105syn keyword luaFunc	print rawget rawset tonumber tostring type _VERSION
106
107if lua_version == 4
108  syn keyword luaFunc	_ALERT _ERRORMESSAGE
109  syn keyword luaFunc	call copytagmethods dostring
110  syn keyword luaFunc	foreach foreachi getglobal getn
111  syn keyword luaFunc	gettagmethod globals newtag
112  syn keyword luaFunc	setglobal settag settagmethod sort
113  syn keyword luaFunc	tag tinsert tremove
114  syn keyword luaFunc	_INPUT _OUTPUT _STDIN _STDOUT _STDERR
115  syn keyword luaFunc	openfile closefile flush seek
116  syn keyword luaFunc	setlocale execute remove rename tmpname
117  syn keyword luaFunc	getenv date clock exit
118  syn keyword luaFunc	readfrom writeto appendto read write
119  syn keyword luaFunc	PI abs sin cos tan asin
120  syn keyword luaFunc	acos atan atan2 ceil floor
121  syn keyword luaFunc	mod frexp ldexp sqrt min max log
122  syn keyword luaFunc	log10 exp deg rad random
123  syn keyword luaFunc	randomseed strlen strsub strlower strupper
124  syn keyword luaFunc	strchar strrep ascii strbyte
125  syn keyword luaFunc	format strfind gsub
126  syn keyword luaFunc	getinfo getlocal setlocal setcallhook setlinehook
127else
128  syn keyword luaFunc	_G getfenv getmetatable ipairs loadfile
129  syn keyword luaFunc	loadlib loadstring pairs pcall rawequal
130  syn keyword luaFunc	require setfenv setmetatable unpack xpcall
131  syn keyword luaFunc	LUA_PATH _LOADED _REQUIREDNAME
132" Not sure if all these functions need to be highlighted...
133  syn match   luaFunc	/coroutine\.create/
134  syn match   luaFunc	/coroutine\.resume/
135  syn match   luaFunc	/coroutine\.status/
136  syn match   luaFunc	/coroutine\.wrap/
137  syn match   luaFunc	/coroutine\.yield/
138  syn match   luaFunc	/string\.byte/
139  syn match   luaFunc	/string\.char/
140  syn match   luaFunc	/string\.dump/
141  syn match   luaFunc	/string\.find/
142  syn match   luaFunc	/string\.len/
143  syn match   luaFunc	/string\.lower/
144  syn match   luaFunc	/string\.rep/
145  syn match   luaFunc	/string\.sub/
146  syn match   luaFunc	/string\.upper/
147  syn match   luaFunc	/string\.format/
148  syn match   luaFunc	/string\.gfind/
149  syn match   luaFunc	/string\.gsub/
150  syn match   luaFunc	/table\.concat/
151  syn match   luaFunc	/table\.foreach/
152  syn match   luaFunc	/table\.foreachi/
153  syn match   luaFunc	/table\.getn/
154  syn match   luaFunc	/table\.sort/
155  syn match   luaFunc	/table\.insert/
156  syn match   luaFunc	/table\.remove/
157  syn match   luaFunc	/table\.setn/
158  syn match   luaFunc	/math\.abs/
159  syn match   luaFunc	/math\.acos/
160  syn match   luaFunc	/math\.asin/
161  syn match   luaFunc	/math\.atan/
162  syn match   luaFunc	/math\.atan2/
163  syn match   luaFunc	/math\.ceil/
164  syn match   luaFunc	/math\.cos/
165  syn match   luaFunc	/math\.deg/
166  syn match   luaFunc	/math\.exp/
167  syn match   luaFunc	/math\.floor/
168  syn match   luaFunc	/math\.log/
169  syn match   luaFunc	/math\.log10/
170  syn match   luaFunc	/math\.max/
171  syn match   luaFunc	/math\.min/
172  syn match   luaFunc	/math\.mod/
173  syn match   luaFunc	/math\.pow/
174  syn match   luaFunc	/math\.rad/
175  syn match   luaFunc	/math\.sin/
176  syn match   luaFunc	/math\.sqrt/
177  syn match   luaFunc	/math\.tan/
178  syn match   luaFunc	/math\.frexp/
179  syn match   luaFunc	/math\.ldexp/
180  syn match   luaFunc	/math\.random/
181  syn match   luaFunc	/math\.randomseed/
182  syn match   luaFunc	/math\.pi/
183  syn match   luaFunc	/io\.stdin/
184  syn match   luaFunc	/io\.stdout/
185  syn match   luaFunc	/io\.stderr/
186  syn match   luaFunc	/io\.close/
187  syn match   luaFunc	/io\.flush/
188  syn match   luaFunc	/io\.input/
189  syn match   luaFunc	/io\.lines/
190  syn match   luaFunc	/io\.open/
191  syn match   luaFunc	/io\.output/
192  syn match   luaFunc	/io\.popen/
193  syn match   luaFunc	/io\.read/
194  syn match   luaFunc	/io\.tmpfile/
195  syn match   luaFunc	/io\.type/
196  syn match   luaFunc	/io\.write/
197  syn match   luaFunc	/os\.clock/
198  syn match   luaFunc	/os\.date/
199  syn match   luaFunc	/os\.difftime/
200  syn match   luaFunc	/os\.execute/
201  syn match   luaFunc	/os\.exit/
202  syn match   luaFunc	/os\.getenv/
203  syn match   luaFunc	/os\.remove/
204  syn match   luaFunc	/os\.rename/
205  syn match   luaFunc	/os\.setlocale/
206  syn match   luaFunc	/os\.time/
207  syn match   luaFunc	/os\.tmpname/
208  syn match   luaFunc	/debug\.debug/
209  syn match   luaFunc	/debug\.gethook/
210  syn match   luaFunc	/debug\.getinfo/
211  syn match   luaFunc	/debug\.getlocal/
212  syn match   luaFunc	/debug\.getupvalue/
213  syn match   luaFunc	/debug\.setlocal/
214  syn match   luaFunc	/debug\.setupvalue/
215  syn match   luaFunc	/debug\.sethook/
216  syn match   luaFunc	/debug\.traceback/
217endif
218
219"syncing method
220syn sync minlines=100
221
222" Define the default highlighting.
223" For version 5.7 and earlier: only when not done already
224" For version 5.8 and later: only when an item doesn't have highlighting yet
225if version >= 508 || !exists("did_lua_syntax_inits")
226  if version < 508
227    let did_lua_syntax_inits = 1
228    command -nargs=+ HiLink hi link <args>
229  else
230    command -nargs=+ HiLink hi def link <args>
231  endif
232
233  HiLink luaStatement		Statement
234  HiLink luaRepeat		Repeat
235  HiLink luaString		String
236  HiLink luaString2		String
237  HiLink luaNumber		Number
238  HiLink luaFloat		Float
239  HiLink luaOperator		Operator
240  HiLink luaConstant		Constant
241  HiLink luaCond		Conditional
242  HiLink luaFunction		Function
243  HiLink luaComment		Comment
244  HiLink luaTodo		Todo
245  HiLink luaTable		Structure
246  HiLink luaError		Error
247  HiLink luaSpecial		SpecialChar
248  " HiLink luaPreProc		PreProc
249  HiLink luaFunc		Identifier
250
251  delcommand HiLink
252endif
253
254let b:current_syntax = "lua"
255
256" vim: noet ts=8
257