Warning, /frameworks/syntax-highlighting/autotests/input/highlight.lua is written in an unsupported language. File is not indexed.
0001 #!/usr/bin/env lua
0002
0003 -- Metatables
0004 t = {
0005 __add=function(a,b)return a+b end,
0006 __sub=function(a,b)return a-b end,
0007 __mul=function(a,b)return a*b end,
0008 __div=function(a,b)return a/b end,
0009 __mod=function(a,b)return a%b end,
0010 __pow=function(a,b)return a^b end,
0011 __unm=function(a)return -a end,
0012 __idiv=function(a,b)return a//b end,
0013 __band=function(a,b)return a&b end,
0014 __bor=function(a,b)return a|b end,
0015 __bxor=function(a,b)return a~b end,
0016 __bnot=function(a)return ~a end,
0017 __shl=function(a,b)return a<<b end,
0018 __shr=function(a,b)return a>>b end,
0019 __concat=function(a,b)return a..b end,
0020 __len=function(a)return #a end,
0021 __eq=function(a,b)return a==b end,
0022 __lt=function(a,b)return a<b end,
0023 __le=function(a,b)return a<=b end,
0024 __index=function(t,k)return t[k] end,
0025 __newindex=function(t,k,v)return t[k]=v end,
0026 __call=function(f, ...)return f(...) end,
0027
0028 __tostring=function(a)return tostring(a) end,
0029 __pairs=function(t)return pairs(a) end,
0030 -- setmetatable
0031 __metatable=true
0032 -- Garbage collector
0033 __gc=function() end
0034 -- Weak table
0035 __mode='k' -- or 'v'
0036 }
0037
0038 a or b
0039 a and b
0040 a~=b
0041 a>=b
0042 true or false
0043 a or nil
0044 a::m
0045 a.m
0046 a;a
0047
0048
0049 -- String
0050 '\a'
0051 '\b'
0052 '\f'
0053 '\n'
0054 '\r'
0055 '\t'
0056 '\v'
0057 '\\'
0058 '\"'
0059 '\''
0060 '\z'
0061 '\xff'
0062 '\xFF'
0063 '\231'
0064 '\23'
0065 '\2'
0066 '\u{100201}' -- max 6 digits
0067 '\2a\ks' -- error
0068
0069 'multi\
0070 line'
0071 'multi\z
0072 line'
0073 'multi\z line\
0074 2'
0075
0076 a = 'alo\n123"'
0077 a = "alo\n123\""
0078 a = '\97lo\10\04923"'
0079 a = [[alo
0080 123"]]
0081 a = [==[
0082 alo
0083 123"]==]
0084
0085
0086 -- Decimal
0087 3
0088 345
0089 0xff
0090 0xBEBADA
0091
0092 -- Float
0093 3.
0094 .3
0095 3.0
0096 3.1416
0097 314.16e-2
0098 314.e+2
0099 0.31416E1
0100 34e1
0101 0.e3
0102 0x0.1E
0103 0xA23p-4
0104 0xA.p+4
0105 0x.ap4
0106 0X1.921FB54442D18P+1
0107 -- error
0108 32p
0109 0xp-4
0110 0x.p-4
0111 3.x
0112
0113
0114 -- single comment
0115 xyz()
0116 --[[
0117 long comment
0118 ]]
0119 xyz()
0120
0121 -- TODO bla bla
0122 --[[ TODO bla bla ]]
0123
0124 a = { [f(1)] = g; "x", "y"; x = 1, f(x), [30] = 23; 45 }
0125
0126 -- is equivalent to
0127
0128 do
0129 local t = {}
0130 t[f(1)] = g
0131 t[1] = "x" -- 1st exp
0132 t[2] = "y" -- 2nd exp
0133 t.x = 1 -- t["x"] = 1
0134 t[3] = f(x) -- 3rd exp
0135 t[30] = 23
0136 t[4] = 45 -- 4th exp
0137 a = t
0138 end
0139
0140 32-0x43+0x2-5
0141 return"a"
0142 return'a'
0143 return{}
0144 f(3)
0145 f'a'
0146 f"a"
0147 f{s=2}
0148 f[[s]]
0149 f[=[s]=]
0150 #a
0151
0152 local CONSTANT = a
0153
0154 a = {}
0155 local x = 20
0156 for i=1,10 do
0157 local y = 0
0158 a[i] = function () y=y+1; return x+y end
0159 end
0160
0161 local function foo()
0162 end
0163
0164 function obj:foo()
0165 print(self:bar())
0166 end
0167
0168 function obj.bar(self)
0169 print(self)
0170 print(self.value)
0171 end
0172
0173 --! \brief gfind is deprecated
0174 string.gfind('s')
0175 string.gmatch('f')
0176
0177 function foo()
0178 if x then
0179 function() end
0180 bar=function()
0181 if y then
0182 if z then end
0183 end
0184 end
0185 end
0186 end
0187
0188 -- attributes
0189 local a<const> = 2
0190 local a<const> print(a)
0191 local f <close>, const < const >
0192 local a <cloe>, b< cons >, c<const, d<close> ; a<b
0193 local a <cloe> -- bla,
0194 b< cons >
0195 local a <close> --[[
0196 b <const>]], b <const> --[[ xyz ]] , c <close>
0197 b< cons >
0198
0199 --- \code
0200 --! a = 3
0201 --! \endcode
0202 a = 3