diff --git a/autotests/folding/highlight.lua.fold b/autotests/folding/highlight.lua.fold index 183a258..3b8d88d 100644 --- a/autotests/folding/highlight.lua.fold +++ b/autotests/folding/highlight.lua.fold @@ -1,160 +1,171 @@ #!/usr/bin/env lua -- Metatables t = { __add=function(a,b)return a+b end, __sub=function(a,b)return a-b end, __mul=function(a,b)return a*b end, __div=function(a,b)return a/b end, __mod=function(a,b)return a%b end, __pow=function(a,b)return a^b end, __unm=function(a)return -a end, __idiv=function(a,b)return a//b end, __band=function(a,b)return a&b end, __bor=function(a,b)return a|b end, __bxor=function(a,b)return a~b end, __bnot=function(a)return ~a end, __shl=function(a,b)return a<end, __shr=function(a,b)return a>>b end, __concat=function(a,b)return a..b end, __len=function(a)return #a end, __eq=function(a,b)return a==b end, __lt=function(a,b)return aend, __le=function(a,b)return a<=b end, __index=function(t,k)return t[k] end, __newindex=function(t,k,v)return t[k]=v end, __call=function(f, ...)return f(...) end, __tostring=function(a)return tostring(a) end, __pairs=function(t)return pairs(a) end, -- setmetatable __metatable=true -- Garbage collector __gc=function() end -- Weak table __mode='k' -- or 'v' } a or b a and b a~=b a>=b true or false a or nil a::m a.m a;a -- String '\a' '\b' '\f' '\n' '\r' '\t' '\v' '\\' '\"' '\'' '\z' '\xff' '\xFF' '\231' '\23' '\2' '\u{100201}' -- max 6 digits '\2a\ks' -- error 'multi\ line' 'multi\z line' 'multi\z line\ 2' a = 'alo\n123"' a = "alo\n123\"" a = '\97lo\10\04923"' a = [[alo 123"]] a = [==[ alo 123"]==] -- Decimal 3 345 0xff 0xBEBADA -- Float 3. .3 3.0 3.1416 314.16e-2 314.e+2 0.31416E1 34e1 0.e3 0x0.1E 0xA23p-4 0xA.p+4 0x.ap4 0X1.921FB54442D18P+1 -- error 32p 0xp-4 0x.p-4 -- single comment xyz() --[[ long comment ]] xyz() a = { [f(1)] = g; "x", "y"; x = 1, f(x), [30] = 23; 45 } -- is equivalent to do local t = {} t[f(1)] = g t[1] = "x" -- 1st exp t[2] = "y" -- 2nd exp t.x = 1 -- t["x"] = 1 t[3] = f(x) -- 3rd exp t[30] = 23 t[4] = 45 -- 4th exp a = t end 32-0x43+0x2-5 return"a" return'a' return{} f(3) f'a' f"a" f{s=2} f[[s]] f[=[s]=] #a local CONSTANT = a a = {} local x = 20 for i=1,10 do local y = 0 a[i] = function () y=y+1; return x+y end end --! \brief gfind is deprecated string.gfind('s') string.gmatch('f') + +function foo() + if x then + function() end + bar=function() + if y then + if z then end + end + end + end +end diff --git a/autotests/html/highlight.lua.html b/autotests/html/highlight.lua.html index 7226f6b..bcaa02b 100644 --- a/autotests/html/highlight.lua.html +++ b/autotests/html/highlight.lua.html @@ -1,167 +1,178 @@ highlight.lua
 #!/usr/bin/env lua
 
 -- Metatables
 t = {
     __add=function(a,b)return a+b end,
     __sub=function(a,b)return a-b end,
     __mul=function(a,b)return a*b end,
     __div=function(a,b)return a/b end,
     __mod=function(a,b)return a%b end,
     __pow=function(a,b)return a^b end,
     __unm=function(a)return -a end,
     __idiv=function(a,b)return a//b end,
     __band=function(a,b)return a&b end,
     __bor=function(a,b)return a|b end,
     __bxor=function(a,b)return a~b end,
     __bnot=function(a)return ~a end,
     __shl=function(a,b)return a<<b end,
     __shr=function(a,b)return a>>b end,
     __concat=function(a,b)return a..b end,
     __len=function(a)return #a end,
     __eq=function(a,b)return a==b end,
     __lt=function(a,b)return a<b end,
     __le=function(a,b)return a<=b end,
     __index=function(t,k)return t[k] end,
     __newindex=function(t,k,v)return t[k]=v end,
     __call=function(f, ...)return f(...) end,
 
    __tostring=function(a)return tostring(a) end,
    __pairs=function(t)return pairs(a) end,
    -- setmetatable
    __metatable=true
    -- Garbage collector
    __gc=function() end
    -- Weak table
    __mode='k' -- or 'v'
 }
 
 a or b
 a and b
 a~=b
 a>=b
 true or false
 a or nil
 a::m
 a.m
 a;a
 
 
 -- String
 '\a'
 '\b'
 '\f'
 '\n'
 '\r'
 '\t'
 '\v'
 '\\'
 '\"'
 '\''
 '\z'
 '\xff'
 '\xFF'
 '\231'
 '\23'
 '\2'
 '\u{100201}' -- max 6 digits
 '\2a\ks' -- error
 
 'multi\
 line'
 'multi\z
 line'
 'multi\z    line\
 2'
 
 a = 'alo\n123"'
 a = "alo\n123\""
 a = '\97lo\10\04923"'
 a = [[alo
 123"]]
 a = [==[
 alo
 123"]==]
 
 
 -- Decimal
 3
 345
 0xff
 0xBEBADA
 
 -- Float
 3.
 .3
 3.0
 3.1416
 314.16e-2
 314.e+2
 0.31416E1
 34e1
 0.e3
 0x0.1E
 0xA23p-4
 0xA.p+4
 0x.ap4
 0X1.921FB54442D18P+1
 -- error
 32p
 0xp-4
 0x.p-4
 
 
 -- single comment
 xyz()
 --[[
  long comment
 ]]
 xyz()
 
 
 a = { [f(1)] = g; "x", "y"; x = 1, f(x), [30] = 23; 45 }
 
 -- is equivalent to
 
 do
   local t = {}
   t[f(1)] = g
   t[1] = "x" -- 1st exp
   t[2] = "y" -- 2nd exp
   t.x = 1 -- t["x"] = 1
   t[3] = f(x) -- 3rd exp
   t[30] = 23
   t[4] = 45 -- 4th exp
   a = t
 end
 
 32-0x43+0x2-5
 return"a"
 return'a'
 return{}
 f(3)
 f'a'
 f"a"
 f{s=2}
 f[[s]]
 f[=[s]=]
 #a
 
 local CONSTANT = a
 
 a = {}
 local x = 20
 for i=1,10 do
   local y = 0
   a[i] = function () y=y+1; return x+y end
 end
 
 --! \brief gfind is deprecated
 string.gfind('s')
 string.gmatch('f')
+
+function foo()
+  if x then
+    function() end
+    bar=function()
+      if y then
+        if z then end
+      end
+    end
+  end
+end
 
diff --git a/autotests/input/highlight.lua b/autotests/input/highlight.lua index 85ac95d..1291eed 100644 --- a/autotests/input/highlight.lua +++ b/autotests/input/highlight.lua @@ -1,160 +1,171 @@ #!/usr/bin/env lua -- Metatables t = { __add=function(a,b)return a+b end, __sub=function(a,b)return a-b end, __mul=function(a,b)return a*b end, __div=function(a,b)return a/b end, __mod=function(a,b)return a%b end, __pow=function(a,b)return a^b end, __unm=function(a)return -a end, __idiv=function(a,b)return a//b end, __band=function(a,b)return a&b end, __bor=function(a,b)return a|b end, __bxor=function(a,b)return a~b end, __bnot=function(a)return ~a end, __shl=function(a,b)return a<>b end, __concat=function(a,b)return a..b end, __len=function(a)return #a end, __eq=function(a,b)return a==b end, __lt=function(a,b)return a=b true or false a or nil a::m a.m a;a -- String '\a' '\b' '\f' '\n' '\r' '\t' '\v' '\\' '\"' '\'' '\z' '\xff' '\xFF' '\231' '\23' '\2' '\u{100201}' -- max 6 digits '\2a\ks' -- error 'multi\ line' 'multi\z line' 'multi\z line\ 2' a = 'alo\n123"' a = "alo\n123\"" a = '\97lo\10\04923"' a = [[alo 123"]] a = [==[ alo 123"]==] -- Decimal 3 345 0xff 0xBEBADA -- Float 3. .3 3.0 3.1416 314.16e-2 314.e+2 0.31416E1 34e1 0.e3 0x0.1E 0xA23p-4 0xA.p+4 0x.ap4 0X1.921FB54442D18P+1 -- error 32p 0xp-4 0x.p-4 -- single comment xyz() --[[ long comment ]] xyz() a = { [f(1)] = g; "x", "y"; x = 1, f(x), [30] = 23; 45 } -- is equivalent to do local t = {} t[f(1)] = g t[1] = "x" -- 1st exp t[2] = "y" -- 2nd exp t.x = 1 -- t["x"] = 1 t[3] = f(x) -- 3rd exp t[30] = 23 t[4] = 45 -- 4th exp a = t end 32-0x43+0x2-5 return"a" return'a' return{} f(3) f'a' f"a" f{s=2} f[[s]] f[=[s]=] #a local CONSTANT = a a = {} local x = 20 for i=1,10 do local y = 0 a[i] = function () y=y+1; return x+y end end --! \brief gfind is deprecated string.gfind('s') string.gmatch('f') + +function foo() + if x then + function() end + bar=function() + if y then + if z then end + end + end + end +end diff --git a/autotests/reference/highlight.lua.ref b/autotests/reference/highlight.lua.ref index 48151ea..7b3bd29 100644 --- a/autotests/reference/highlight.lua.ref +++ b/autotests/reference/highlight.lua.ref @@ -1,160 +1,171 @@ #!/usr/bin/env lua

-- Metatables
t = {
__add=function(a,b)return a+b end,
__sub=function(a,b)return a-b end,
__mul=function(a,b)return a*b end,
__div=function(a,b)return a/b end,
__mod=function(a,b)return a%b end,
__pow=function(a,b)return a^b end,
__unm=function(a)return -a end,
__idiv=function(a,b)return a//b end,
__band=function(a,b)return a&b end,
__bor=function(a,b)return a|b end,
__bxor=function(a,b)return a~b end,
__bnot=function(a)return ~a end,
__shl=function(a,b)return a<<b end,
__shr=function(a,b)return a>>b end,
__concat=function(a,b)return a..b end,
__len=function(a)return #a end,
__eq=function(a,b)return a==b end,
__lt=function(a,b)return a<b end,
__le=function(a,b)return a<=b end,
__index=function(t,k)return t[k] end,
__newindex=function(t,k,v)return t[k]=v end,
__call=function(f, ...)return f(...) end,

__tostring=function(a)return tostring(a) end,
__pairs=function(t)return pairs(a) end,
-- setmetatable
__metatable=true
-- Garbage collector
__gc=function() end
-- Weak table
__mode='k' -- or 'v'
}

a or b
a and b
a~=b
a>=b
true or false
a or nil
a::m
a.m
a;a


-- String
'\a'
'\b'
'\f'
'\n'
'\r'
'\t'
'\v'
'\\'
'\"'
'\''
'\z'
'\xff'
'\xFF'
'\231'
'\23'
'\2'
'\u{100201}' -- max 6 digits
'\2a\ks' -- error

'multi\
line'
'multi\z
line'
'multi\z line\
2'

a = 'alo\n123"'
a = "alo\n123\""
a = '\97lo\10\04923"'
a = [[alo
123"]]
a = [==[
alo
123"]==]


-- Decimal
3
345
0xff
0xBEBADA

-- Float
3.
.3
3.0
3.1416
314.16e-2
314.e+2
0.31416E1
34e1
0.e3
0x0.1E
0xA23p-4
0xA.p+4
0x.ap4
0X1.921FB54442D18P+1
-- error
32p
0xp-4
0x.p-4


-- single comment
xyz()
--[[
long comment
]]
xyz()


a = { [f(1)] = g; "x", "y"; x = 1, f(x), [30] = 23; 45 }

-- is equivalent to

do
local t = {}
t[f(1)] = g
t[1] = "x" -- 1st exp
t[2] = "y" -- 2nd exp
t.x = 1 -- t["x"] = 1
t[3] = f(x) -- 3rd exp
t[30] = 23
t[4] = 45 -- 4th exp
a = t
end

32-0x43+0x2-5
return"a"
return'a'
return{}
f(3)
f'a'
f"a"
f{s=2}
f[[s]]
f[=[s]=]
#a

local CONSTANT = a

a = {}
local x = 20
for i=1,10 do
local y = 0
a[i] = function () y=y+1; return x+y end
end

--! \brief gfind is deprecated
string.gfind('s')
string.gmatch('f')
+
+function foo()
+ if x then
+ function() end
+ bar=function()
+ if y then
+ if z then end
+ end
+ end
+ end
+end
diff --git a/data/syntax/lua.xml b/data/syntax/lua.xml index 14a0dcd..0413e56 100644 --- a/data/syntax/lua.xml +++ b/data/syntax/lua.xml @@ -1,551 +1,569 @@ ]> - + and function in local not or nil false true break do else elseif end for goto if repeat return then until while + + do + if + repeat + + + + else + elseif + + + + end + until + + _PROMPT _PROMPT2 LUA_PATH LUA_CPATH LUA_INIT _ENV _VERSION _G package.config package.cpath package.loaded package.path package.preload package.searchers utf8.charpattern math.maxinteger math.mininteger math.pi assert collectgarbage dofile error getmetatable ipairs load loadfile next pairs pcall print rawequal rawget rawlen rawset select setmetatable tonumber tostring type warn xpcall coroutine.create coroutine.isyieldable coroutine.resume coroutine.kill coroutine.running coroutine.status coroutine.wrap coroutine.yield require package.loadlib package.searchpath string.byte string.char string.dump string.find string.format string.gmatch string.gsub string.len string.lower string.match string.pack string.packsize string.rep string.reverse string.sub string.unpack string.upper utf8.char utf8.codes utf8.codepoint utf8.len utf8.offset table.concat table.insert table.move table.pack table.remove table.sort table.unpack math.abs math.acos math.asin math.atan math.ceil math.cos math.deg math.exp math.floor math.fmod math.huge math.log math.max math.min math.modf math.rad math.random math.randomseed math.sin math.sqrt math.tan math.tointeger math.type math.utl io.close io.flush io.input io.lines io.open io.output io.popen io.read io.stderr io.stdin io.stdout io.tmpfile io.type io.write os.clock os.date os.difftime os.execute os.exit os.getenv os.remove os.rename os.setlocale os.time os.tmpname debug.debug debug.gethook debug.getinfo debug.getlocal debug.getmetatable debug.getregistry debug.getupvalue debug.getuservalue debug.sethook debug.setlocal debug.setmetatable debug.setupvalue debug.setuservalue debug.traceback debug.upvalueid debug.upvaluejoin cgilua cgilua.addclosefunction cgilua.addopenfunction cgilua.addopenfunction cgilua.addscripthandler cgilua.addscripthandler cgilua.buildprocesshandler cgilua.contentheader cgilua.cookies.delete cgilua.cookies.get cgilua.cookies.set cgilua.cookies.sethtml cgilua.cookies cgilua.doif cgilua.doscript cgilua.errorlog cgilua.handlelp cgilua.header cgilua.htmlheader cgilua.lp.compile cgilua.lp.include cgilua.lp.setcompatmode cgilua.lp.setoutfunc cgilua.lp.translate cgilua.mkabsoluteurl cgilua.mkurlpath cgilua.pack cgilua.put cgilua.redirect cgilua.script_file cgilua.script_path cgilua.script_pdir cgilua.script_vdir cgilua.script_vpath cgilua.serialize cgilua.servervariable cgilua.session.close cgilua.session.data cgilua.session.delete cgilua.session.load cgilua.session.new cgilua.session.open cgilua.session.save cgilua.session.setsessiondir cgilua.session cgilua.seterrorhandler cgilua.seterroroutput cgilua.setmaxfilesize cgilua.setmaxinput cgilua.setoutfunc cgilua.splitpath cgilua.urlcode.encodetable cgilua.urlcode.escape cgilua.urlcode.insertfield cgilua.urlcode.parsequery cgilua.urlcode.unescape cgilua.urlpath lfs lfs.attributes lfs.chdir lfs.currentdir lfs.dir lfs.lock lfs.mkdir lfs.rmdir lfs.touch lfs.unlock zip zip.open zip.openfile byte char dump find format gmatch gsub len lower match pack packsize rep reverse sub unpack upper concat insert move pack remove sort unpack close commit connect escape execute fetch getcolnames getcoltypes getlastautoid numrows rollback setautocommit files close flush lines read seek setvbuf write __add __sub __mul __div __mod __pow __unm __idiv __band __bor __bxor __bnot __shl __shr __concat __len __eq __lt __le __index __newindex __call __tostring __pairs __metatable __gc __mode _ALERT _ERRORMESSAGE _LOADED __ipairs foreach foreachi loadstring math.atan2 math.cosh math.frexp math.ldexp math.log10 math.mod math.pow math.sinh math.tanh string.gfind table.foreach table.foreachi table.getn table.setn - - - - - + + + + + + +