-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestGrammar.lua
More file actions
98 lines (84 loc) · 2.51 KB
/
Copy pathtestGrammar.lua
File metadata and controls
98 lines (84 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
local util = require 'pegparser.util'
local lfs = require "lfs"
local EXCEPTIONS = {
damerau_levenshtein_2_rule = true,
damerau_levenshtein_3_rule = true,
mutation = true,
bfs3 = true,
random = true,
}
function inException(name)
return EXCEPTIONS[name] or false
end
function isDir(path)
-- lfs.attributes will error on a filename ending in '/'
return path:sub(-1) == "/" or lfs.attributes(path, "mode") == "directory"
end
local function recursiveTestYes(root, dir, ext, p, output)
if output[dir:sub(#root)] == nil then
output[dir:sub(#root)] = { util.testYes(dir, ext, p) }
else
table.insert(output[dir:sub(#root)], util.testYes(dir, ext, p))
end
for file in lfs.dir(dir) do
if file ~= "." and file ~= ".." and
isDir(dir .. file) and not inException(file) then
recursiveTestYes(root, dir .. file .. "/", ext, p, output)
end
end
end
local function recursiveTestNo(root, dir, ext, p, output)
if output[dir:sub(#root)] == nil then
output[dir:sub(#root)] = { util.testNo(dir, ext, p) }
else
table.insert(output[dir:sub(#root)], util.testNo(dir, ext, p))
end
for file in lfs.dir(dir) do
if file ~= "." and file ~= ".." and
isDir(dir .. file) and not inException(file) then
recursiveTestNo(root, dir .. file .. "/", ext, p, output)
end
end
end
local function writeLog(times, filename)
if filename ~= nil then
io.output(filename)
end
local space = 0
for dir, list in pairs(times) do
space = math.max(#dir, space)
end
for dir, list in pairs(times) do
io.write(string.format("%-" .. space + 2 .. "s", dir .. ", "))
for i, t in ipairs(list) do
io.write(string.format("%.03f, ", t))
end
io.write("\n")
end
io.output(io.stdout)
end
if arg[3] == nil then
print("Use: " .. arg[0] .. " <exemples_folder> <extension> <grammar_file>")
return
end
local grammar_namefile = arg[3]
if string.sub(grammar_namefile, -4) == ".lua" then
grammar_namefile = string.sub(grammar_namefile, 1, -5)
end
local g = require(grammar_namefile)
local times = {}
local dir = arg[1]
if string.sub(dir, -1) ~= "/" then
dir = dir .. "/"
end
local root = util.getPath(dir)
local ext = arg[2]
for i = 1, 10 do
if arg[4] == "-n" then
recursiveTestNo(root, dir, ext, g.grammar, times)
else
recursiveTestYes(root, dir, ext, g.grammar, times)
end
end
table.sort(times)
writeLog(times)