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