aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/test_lparser_mk3.lua
diff options
context:
space:
mode:
Diffstat (limited to 'LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/test_lparser_mk3.lua')
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/test_lparser_mk3.lua218
1 files changed, 0 insertions, 218 deletions
diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/test_lparser_mk3.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/test_lparser_mk3.lua
deleted file mode 100644
index 662c826..0000000
--- a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/test_lparser_mk3.lua
+++ /dev/null
@@ -1,218 +0,0 @@
1--[[--------------------------------------------------------------------
2
3 test_lparser_mk3.lua
4 Test for lparser_mk3.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
19local lex_init = require("../llex_mk3")
20local parser_init = require("../lparser_mk3")
21
22------------------------------------------------------------------------
23-- dump contents of log table
24------------------------------------------------------------------------
25
26local function dump_log(fs)
27 local log = fs.log
28 for i = 1, table.getn(log) do
29 print(log[i])
30 end
31end
32
33------------------------------------------------------------------------
34-- try 1
35------------------------------------------------------------------------
36
37local luaX = lex_init("local a = 1", "=string")
38local luaY = parser_init(luaX)
39
40-- nothing is returned, so hope there is an error if problem occurs
41local fs = luaY:parser()
42--dump_log(fs)
43
44------------------------------------------------------------------------
45-- try 2
46------------------------------------------------------------------------
47
48-- llex_mk3.lua cannot load files by itself
49local INF = io.open("sample.lua", "rb")
50if not INF then error("failed to load test file") end
51local sample = INF:read("*a")
52INF:close()
53
54luaX = lex_init(sample, "@sample.lua")
55luaY = parser_init(luaX)
56
57-- nothing is returned, so hope there is an error if problem occurs
58local fs = luaY:parser()
59--dump_log(fs)
60
61------------------------------------------------------------------------
62-- automatic dumper of output log data
63------------------------------------------------------------------------
64
65local test_case = {
66-- 1
67[[
68]],
69-- 2
70[[
71-- foobar
72]],
73-- 3
74[[
75do
76end
77]],
78-- 4
79[[
80do end
81do end
82]],
83-- 5
84[[
85foo()
86foo{}
87foo""
88foo:bar()
89foo=false
90foo.bar=true
91foo[true]=nil
92foo,bar=1,"a"
93]],
94-- 6
95[[
96foo=true
97foo=false
98foo=nil
99foo=1.23e45
100foo=-1
101foo=(0)
102foo=1+2
103foo=1+2*3-4/5
104]],
105-- 7
106[[
107if foo then foo=1 end
108if foo then foo=1 else foo=0 end
109if foo then foo=1 elseif not foo then foo=0 end
110]],
111-- 8
112[[
113do return end
114do return 123 end
115do return "foo","bar" end
116]],
117-- 9
118[[
119while true do foo=not foo end
120while foo~=42 do foo=foo-1 end
121while true do break end
122]],
123-- 10
124[[
125repeat foo=foo.."bar" until false
126repeat foo=foo/2 until foo<1
127repeat break until false
128]],
129-- 11
130[[
131for i=1,10 do foo=i end
132for i=1,10,2 do break end
133for i in foo do bar=0 end
134for i,j in foo,bar do baz=0 end
135]],
136-- 12
137[[
138local foo
139local foo,bar,baz
140local foo,bar="foo","bar"
141]],
142-- 13
143[[
144local function foo() return end
145local function foo(a) return end
146local function foo(x,y,z) return end
147local function foo(x,...) return end
148]],
149-- 14
150[[
151function foo() return end
152function foo(a) return end
153function foo(x,y,z) return end
154function foo(x,...) return end
155]],
156-- 15
157[[
158function foo.bar(p) return end
159function foo.bar.baz(p) return end
160function foo:bar(p) return end
161function foo.bar.baz(p) return end
162]],
163-- 16
164[[
165foo = function() return end
166foo = function(x,y) return end
167foo = function(...) return end
168]],
169-- 17
170[[
171foo = {}
172foo = { 1,2,3; "foo"; }
173foo = { bar=77, baz=88, }
174foo = { ["bar"]=77, ["baz"]=88, }
175]],
176}
177
178-- helps to skip old stuff during development of snippets
179local do_beg, do_end = 1, table.getn(test_case)
180
181-- loop for all example snippets
182for i = do_beg, do_end do
183 local fname = "parser_log/sample_"..string.format("%02d", i)..".lua"
184 local src = test_case[i]
185 local OUTF = io.open(fname, "wb")
186 if not OUTF then error("failed to write to file '"..fname.."'") end
187 -- write out actual source for comparison
188 OUTF:write(
189 "-- START OF SOURCE --\n"..
190 src..
191 "-- END OF SOURCE --\n"..
192 "\n"
193 )
194 -- attempt to parse
195 local luaX = lex_init(src, "=string")
196 local luaY = parser_init(luaX)
197 local fs = luaY:parser()
198 -- grab logged messages and write
199 local log = fs.log
200 local indent = 0
201 for i = 1, table.getn(log) do
202 local ln = log[i]
203 -- handle indentation
204 local tag = string.sub(ln, 1, 2)
205 if tag == ">>" or tag == "<<" then
206 ln = string.sub(ln, 4)
207 end
208 if tag == ">>" then
209 indent = indent + 1
210 end
211 OUTF:write(string.rep(" ", indent)..ln.."\n")
212 if tag == "<<" then
213 indent = indent - 1
214 end
215 end
216 -- we're done
217 OUTF:close()
218end