diff options
author | David Walter Seikel | 2012-01-23 21:58:02 +1000 |
---|---|---|
committer | David Walter Seikel | 2012-01-23 21:58:02 +1000 |
commit | 2d1df4714e2736dbde7855ddcd76b4c1de822fa5 (patch) | |
tree | c80e4622631c92dbe8dd6375d187702d084c2f2b /LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/test_lparser_mk3.lua | |
parent | Remove the conflict, and the comment. lol (diff) | |
download | SledjHamr-2d1df4714e2736dbde7855ddcd76b4c1de822fa5.zip SledjHamr-2d1df4714e2736dbde7855ddcd76b4c1de822fa5.tar.gz SledjHamr-2d1df4714e2736dbde7855ddcd76b4c1de822fa5.tar.bz2 SledjHamr-2d1df4714e2736dbde7855ddcd76b4c1de822fa5.tar.xz |
Added a big bunch of example lua scripts for testing the speed of lua compiling.
Diffstat (limited to '')
-rw-r--r-- | LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/test_lparser_mk3.lua | 218 |
1 files changed, 218 insertions, 0 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 new file mode 100644 index 0000000..662c826 --- /dev/null +++ b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/test_lparser_mk3.lua | |||
@@ -0,0 +1,218 @@ | |||
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 | |||
19 | local lex_init = require("../llex_mk3") | ||
20 | local parser_init = require("../lparser_mk3") | ||
21 | |||
22 | ------------------------------------------------------------------------ | ||
23 | -- dump contents of log table | ||
24 | ------------------------------------------------------------------------ | ||
25 | |||
26 | local function dump_log(fs) | ||
27 | local log = fs.log | ||
28 | for i = 1, table.getn(log) do | ||
29 | print(log[i]) | ||
30 | end | ||
31 | end | ||
32 | |||
33 | ------------------------------------------------------------------------ | ||
34 | -- try 1 | ||
35 | ------------------------------------------------------------------------ | ||
36 | |||
37 | local luaX = lex_init("local a = 1", "=string") | ||
38 | local luaY = parser_init(luaX) | ||
39 | |||
40 | -- nothing is returned, so hope there is an error if problem occurs | ||
41 | local fs = luaY:parser() | ||
42 | --dump_log(fs) | ||
43 | |||
44 | ------------------------------------------------------------------------ | ||
45 | -- try 2 | ||
46 | ------------------------------------------------------------------------ | ||
47 | |||
48 | -- llex_mk3.lua cannot load files by itself | ||
49 | local INF = io.open("sample.lua", "rb") | ||
50 | if not INF then error("failed to load test file") end | ||
51 | local sample = INF:read("*a") | ||
52 | INF:close() | ||
53 | |||
54 | luaX = lex_init(sample, "@sample.lua") | ||
55 | luaY = parser_init(luaX) | ||
56 | |||
57 | -- nothing is returned, so hope there is an error if problem occurs | ||
58 | local fs = luaY:parser() | ||
59 | --dump_log(fs) | ||
60 | |||
61 | ------------------------------------------------------------------------ | ||
62 | -- automatic dumper of output log data | ||
63 | ------------------------------------------------------------------------ | ||
64 | |||
65 | local test_case = { | ||
66 | -- 1 | ||
67 | [[ | ||
68 | ]], | ||
69 | -- 2 | ||
70 | [[ | ||
71 | -- foobar | ||
72 | ]], | ||
73 | -- 3 | ||
74 | [[ | ||
75 | do | ||
76 | end | ||
77 | ]], | ||
78 | -- 4 | ||
79 | [[ | ||
80 | do end | ||
81 | do end | ||
82 | ]], | ||
83 | -- 5 | ||
84 | [[ | ||
85 | foo() | ||
86 | foo{} | ||
87 | foo"" | ||
88 | foo:bar() | ||
89 | foo=false | ||
90 | foo.bar=true | ||
91 | foo[true]=nil | ||
92 | foo,bar=1,"a" | ||
93 | ]], | ||
94 | -- 6 | ||
95 | [[ | ||
96 | foo=true | ||
97 | foo=false | ||
98 | foo=nil | ||
99 | foo=1.23e45 | ||
100 | foo=-1 | ||
101 | foo=(0) | ||
102 | foo=1+2 | ||
103 | foo=1+2*3-4/5 | ||
104 | ]], | ||
105 | -- 7 | ||
106 | [[ | ||
107 | if foo then foo=1 end | ||
108 | if foo then foo=1 else foo=0 end | ||
109 | if foo then foo=1 elseif not foo then foo=0 end | ||
110 | ]], | ||
111 | -- 8 | ||
112 | [[ | ||
113 | do return end | ||
114 | do return 123 end | ||
115 | do return "foo","bar" end | ||
116 | ]], | ||
117 | -- 9 | ||
118 | [[ | ||
119 | while true do foo=not foo end | ||
120 | while foo~=42 do foo=foo-1 end | ||
121 | while true do break end | ||
122 | ]], | ||
123 | -- 10 | ||
124 | [[ | ||
125 | repeat foo=foo.."bar" until false | ||
126 | repeat foo=foo/2 until foo<1 | ||
127 | repeat break until false | ||
128 | ]], | ||
129 | -- 11 | ||
130 | [[ | ||
131 | for i=1,10 do foo=i end | ||
132 | for i=1,10,2 do break end | ||
133 | for i in foo do bar=0 end | ||
134 | for i,j in foo,bar do baz=0 end | ||
135 | ]], | ||
136 | -- 12 | ||
137 | [[ | ||
138 | local foo | ||
139 | local foo,bar,baz | ||
140 | local foo,bar="foo","bar" | ||
141 | ]], | ||
142 | -- 13 | ||
143 | [[ | ||
144 | local function foo() return end | ||
145 | local function foo(a) return end | ||
146 | local function foo(x,y,z) return end | ||
147 | local function foo(x,...) return end | ||
148 | ]], | ||
149 | -- 14 | ||
150 | [[ | ||
151 | function foo() return end | ||
152 | function foo(a) return end | ||
153 | function foo(x,y,z) return end | ||
154 | function foo(x,...) return end | ||
155 | ]], | ||
156 | -- 15 | ||
157 | [[ | ||
158 | function foo.bar(p) return end | ||
159 | function foo.bar.baz(p) return end | ||
160 | function foo:bar(p) return end | ||
161 | function foo.bar.baz(p) return end | ||
162 | ]], | ||
163 | -- 16 | ||
164 | [[ | ||
165 | foo = function() return end | ||
166 | foo = function(x,y) return end | ||
167 | foo = function(...) return end | ||
168 | ]], | ||
169 | -- 17 | ||
170 | [[ | ||
171 | foo = {} | ||
172 | foo = { 1,2,3; "foo"; } | ||
173 | foo = { bar=77, baz=88, } | ||
174 | foo = { ["bar"]=77, ["baz"]=88, } | ||
175 | ]], | ||
176 | } | ||
177 | |||
178 | -- helps to skip old stuff during development of snippets | ||
179 | local do_beg, do_end = 1, table.getn(test_case) | ||
180 | |||
181 | -- loop for all example snippets | ||
182 | for 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() | ||
218 | end | ||