aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/test_lparser_mk3b.lua
diff options
context:
space:
mode:
Diffstat (limited to 'LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/test_lparser_mk3b.lua')
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/test_lparser_mk3b.lua188
1 files changed, 0 insertions, 188 deletions
diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/test_lparser_mk3b.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/test_lparser_mk3b.lua
deleted file mode 100644
index d8dc33d..0000000
--- a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/test_lparser_mk3b.lua
+++ /dev/null
@@ -1,188 +0,0 @@
1--[[--------------------------------------------------------------------
2
3 test_lparser_mk3b.lua
4 Test for lparser_mk3b.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_mk3b")
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-- automatic dumper of output log data
35------------------------------------------------------------------------
36
37local test_case = {
38-- 1
39[[
40 print(a)
41]],
42-- 2
43[[
44 local a
45 print(a)
46]],
47-- 3
48[[
49 do
50 local a
51 print(a)
52 end
53 print(a)
54]],
55-- 4
56[[
57 local a,b,c
58 do
59 local b
60 print(b)
61 end
62 print(b)
63]],
64-- 5
65[[
66 local function foo() end
67 bar = foo
68]],
69-- 6
70[[
71 do
72 local function foo() end
73 bar = foo
74 end
75 baz = foo
76]],
77-- 7
78[[
79 local foo
80 local function bar()
81 baz = nil
82 foo = bar()
83 end
84 foo = bar
85]],
86-- 8
87[[
88 local foo
89 local function bar()
90 local function baz()
91 local foo, bar
92 foo = bar
93 foo = baz
94 end
95 foo = bar
96 foo = baz
97 end
98 foo = bar
99 foo = baz
100]],
101-- 9
102[[
103 function foo:bar()
104 print(self)
105 end
106]],
107-- 10
108[[
109 function foo(...)
110 print(arg)
111 end
112]],
113-- 11
114[[
115 local c,d
116 function foo(a,b,c)
117 print(a,c,d,e)
118 end
119]],
120-- 11
121[[
122 function foo(a,b)
123 local bar = function(c,d)
124 print(a,b,c,d)
125 end
126 end
127]],
128-- 12
129[[
130 for i = 1,10 do
131 print(i)
132 end
133 for i = 1,10,-2 do
134 print(i)
135 end
136]],
137-- 13
138[[
139 for foo in bar() do
140 print(foo)
141 end
142 for foo,bar,baz in spring() do
143 print(foo,bar,baz)
144 end
145]],
146}
147
148-- helps to skip old stuff during development of snippets
149local do_beg, do_end = 1, table.getn(test_case)
150
151-- loop for all example snippets
152for i = do_beg, do_end do
153 local fname = "parser_log/sample_b_"..string.format("%02d", i)..".lua"
154 local src = test_case[i]
155 local OUTF = io.open(fname, "wb")
156 if not OUTF then error("failed to write to file '"..fname.."'") end
157 -- write out actual source for comparison
158 OUTF:write(
159 "-- START OF SOURCE --\n"..
160 src..
161 "-- END OF SOURCE --\n"..
162 "\n"
163 )
164 -- attempt to parse
165 local luaX = lex_init(src, "=string")
166 local luaY = parser_init(luaX)
167 local fs = luaY:parser()
168 -- grab logged messages and write
169 local log = fs.log
170 local indent = 0
171 for i = 1, table.getn(log) do
172 local ln = log[i]
173 -- handle indentation
174 local tag = string.sub(ln, 1, 2)
175 if tag == ">>" or tag == "<<" then
176 ln = string.sub(ln, 4)
177 end
178 if tag == ">>" then
179 indent = indent + 1
180 end
181 OUTF:write(string.rep(" ", indent)..ln.."\n")
182 if tag == "<<" then
183 indent = indent - 1
184 end
185 end
186 -- we're done
187 OUTF:close()
188end