#!/usr/bin/env lua -- Copyright (C) 2008-2009 Matthew Wild -- -- This project is MIT/X11 licensed. Please see the -- COPYING file in the source package for more information. local keywords = { "function", "for", "if", "elseif", "then", "else", "do", "repeat", "until", "end", "return", "true", "false", "and", "not", "or", "local", "nil", "break" } for _, keyword in ipairs(keywords) do keywords[keyword] = true; end local ops = {}; local bytelisting, err = io.popen("luac -l -p "..arg[1]); if not bytelisting then print(err); return 1; end for line in bytelisting:lines() do local opnum, linenum, opname, comments = line:match("^\t(%d+)%s*%[(%d+)%]%s*(%u+)[^;]*;? ?(.*)$"); if opnum then linenum = tonumber(linenum); -- print(string.format("opnum: %d line: %d op: %s ; %s", opnum, linenum, opname, comments)); if not ops[linenum] then ops[linenum] = { }; if ops[linenum-1] then table.sort(ops[linenum-1], function (a,b) return a.comment and b.comment and #a.comment > #b.comment; end); end end table.insert(ops[linenum], { name = opname, comment = comments }); end end local test_coverage = {}; local test_report, test_report_err = io.open("tests/reports/coverage_"..arg[1]:gsub("^%W", ""):gsub("%W+", "_")..".report"); if test_report then for line in test_report:lines() do local f, linenum, test, success = line:match("^(.-)|(.-)|(.-)|(.-)$"); if linenum and success then test_coverage[tonumber(linenum)] = success; else io.stderr:write("Warning: Can't parse this: [[", line, "]] in test report\n"); end end else test_coverage = nil; end local linenum = 1; local html_spaces = { ["\t"] = " ", [" "] = " " }; function escape_html(s) return (s and s:gsub("[^%w]", { ["<"] = "<", [">"] = ">", ["&"] = "&", ["\""] = """, ["'"] = "'" })) or ""; end function escape_pattern(s) return s:gsub("(%p)", "%%%1"); end local sub; print("
"..linenum.." | ", line, " |
"..linenum.." | ", line, " |