aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/test_lparser_mk2.lua
diff options
context:
space:
mode:
Diffstat (limited to 'LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/test_lparser_mk2.lua')
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/test_lparser_mk2.lua329
1 files changed, 0 insertions, 329 deletions
diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/test_lparser_mk2.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/test_lparser_mk2.lua
deleted file mode 100644
index 11f2827..0000000
--- a/LuaSL/testLua/yueliang-0.4.1/nat-5.1.3/test/test_lparser_mk2.lua
+++ /dev/null
@@ -1,329 +0,0 @@
1--[[--------------------------------------------------------------------
2
3 test_lparser_mk2.lua
4 Test for lparser_mk2.lua
5 This file is part of Yueliang.
6
7 Copyright (c) 2008 Kein-Hong Man <khman@users.sf.net>
8 The COPYRIGHT file describes the conditions
9 under which this software may be distributed.
10
11 See the ChangeLog for more information.
12
13----------------------------------------------------------------------]]
14
15------------------------------------------------------------------------
16-- test the whole kaboodle
17------------------------------------------------------------------------
18
19package.path = "../?.lua;"..package.path
20local llex = require "llex_mk2"
21local lparser = require "lparser_mk2"
22
23------------------------------------------------------------------------
24-- dump contents of log table
25------------------------------------------------------------------------
26
27local function dump_log(fs)
28 local log = fs.log
29 for i = 1, #log do
30 print(log[i])
31 end
32end
33
34------------------------------------------------------------------------
35-- try 1
36------------------------------------------------------------------------
37
38--[=[
39llex.init("local a = 1", "=string")
40lparser.init(llex)
41-- nothing is returned, so hope there is an error if problem occurs
42local fs = lparser.parser()
43dump_log(fs)
44--]=]
45
46------------------------------------------------------------------------
47-- try 2
48------------------------------------------------------------------------
49
50-- a slightly larger sample
51--[=[
52llex.init([[
53local a = 47
54local b = "hello, world!"
55print(a, b)
56]], "@sample.lua")
57lparser.init(llex)
58-- nothing is returned, so hope there is an error if problem occurs
59local fs = lparser.parser()
60dump_log(fs)
61--]=]
62
63------------------------------------------------------------------------
64-- automatic dumper of output log data
65------------------------------------------------------------------------
66
67local test_case = {
68-- 1 attempts to exercise most parts, extent of coverage not known
69[[
70]],
71-- 2
72[[
73-- foobar
74]],
75-- 3
76[[
77do
78end
79]],
80-- 4
81[[
82do end
83do end
84]],
85-- 5
86[[
87foo()
88foo{}
89foo""
90foo:bar()
91foo=false
92foo.bar=true
93foo[true]=nil
94foo,bar=1,"a"
95]],
96-- 6
97[[
98foo=true
99foo=false
100foo=nil
101foo=1.23e45
102foo=-1
103foo=(0)
104foo=1+2
105foo=1+2*3-4/5
106]],
107-- 7
108[[
109if foo then foo=1 end
110if foo then foo=1 else foo=0 end
111if foo then foo=1 elseif not foo then foo=0 end
112]],
113-- 8
114[[
115do return end
116do return 123 end
117do return "foo","bar" end
118]],
119-- 9
120[[
121while true do foo=not foo end
122while foo~=42 do foo=foo-1 end
123while true do break end
124]],
125-- 10
126[[
127repeat foo=foo.."bar" until false
128repeat foo=foo/2 until foo<1
129repeat break until false
130]],
131-- 11
132[[
133for i=1,10 do foo=i end
134for i=1,10,2 do break end
135for i in foo do bar=0 end
136for i,j in foo,bar do baz=0 end
137]],
138-- 12
139[[
140local foo
141local foo,bar,baz
142local foo,bar="foo","bar"
143]],
144-- 13
145[[
146local function foo() return end
147local function foo(a) return end
148local function foo(x,y,z) return end
149local function foo(x,...) return end
150]],
151-- 14
152[[
153function foo() return end
154function foo(a) return end
155function foo(x,y,z) return end
156function foo(x,...) return end
157]],
158-- 15
159[[
160function foo.bar(p) return end
161function foo.bar.baz(p) return end
162function foo:bar(p) return end
163function foo.bar.baz(p) return end
164]],
165-- 16
166[[
167foo = function() return end
168foo = function(x,y) return end
169foo = function(...) return end
170foo = function(...) local bar = ... return end
171]],
172-- 17
173[[
174foo = {}
175foo = { 1,2,3; "foo"; }
176foo = { bar=77, baz=88, }
177foo = { ["bar"]=77, ["baz"]=88, }
178]],
179-- 18 simple tests for variable management follows
180[[
181 print(a)
182]],
183-- 19
184[[
185 local a
186 print(a)
187]],
188-- 20
189[[
190 do
191 local a
192 print(a)
193 end
194 print(a)
195]],
196-- 21
197[[
198 local a,b,c
199 do
200 local b
201 print(b)
202 end
203 print(b)
204]],
205-- 22
206[[
207 local function foo() end
208 bar = foo
209]],
210-- 23
211[[
212 do
213 local function foo() end
214 bar = foo
215 end
216 baz = foo
217]],
218-- 24
219[[
220 local foo
221 local function bar()
222 baz = nil
223 foo = bar()
224 end
225 foo = bar
226]],
227-- 25
228[[
229 local foo
230 local function bar()
231 local function baz()
232 local foo, bar
233 foo = bar
234 foo = baz
235 end
236 foo = bar
237 foo = baz
238 end
239 foo = bar
240 foo = baz
241]],
242-- 26
243[[
244 function foo:bar()
245 print(self)
246 end
247]],
248-- 27
249[[
250 function foo(...)
251 print(arg)
252 end
253]],
254-- 28
255[[
256 local c,d
257 function foo(a,b,c)
258 print(a,c,d,e)
259 end
260]],
261-- 29
262[[
263 function foo(a,b)
264 local bar = function(c,d)
265 print(a,b,c,d)
266 end
267 end
268]],
269-- 30
270[[
271 for i = 1,10 do
272 print(i)
273 end
274 for i = 1,10,-2 do
275 print(i)
276 end
277]],
278-- 31
279[[
280 for foo in bar() do
281 print(foo)
282 end
283 for foo,bar,baz in spring() do
284 print(foo,bar,baz)
285 end
286]],
287}
288
289-- helps to skip old stuff during development of snippets
290local do_beg, do_end = 1, #test_case
291
292-- loop for all example snippets
293for i = do_beg, do_end do
294 local fname = "parser_log/sample_"..string.format("%02d", i)..".lua"
295 local src = test_case[i]
296 local OUTF = io.open(fname, "wb")
297 if not OUTF then error("failed to write to file '"..fname.."'") end
298 -- write out actual source for comparison
299 OUTF:write(
300 "-- START OF SOURCE --\n"..
301 src..
302 "-- END OF SOURCE --\n"..
303 "\n"
304 )
305 -- attempt to parse
306 llex.init(src, "=string")
307 lparser.init(llex)
308 local fs = lparser.parser()
309 -- grab logged messages and write
310 local log = fs.log
311 local indent = 0
312 for i = 1, #log do
313 local ln = log[i]
314 -- handle indentation
315 local tag = string.sub(ln, 1, 2)
316 if tag == ">>" or tag == "<<" then
317 ln = string.sub(ln, 4)
318 end
319 if tag == ">>" then
320 indent = indent + 1
321 end
322 OUTF:write(string.rep(" ", indent)..ln.."\n")
323 if tag == "<<" then
324 indent = indent - 1
325 end
326 end
327 -- we're done
328 OUTF:close()
329end