Warning: this is an htmlized version!
The original is here, and the conversion rules are here. |
-- This file: -- http://angg.twu.net/LUA/LuaBlocks.lua.html -- http://angg.twu.net/LUA/LuaBlocks.lua -- (find-angg "LUA/LuaBlocks.lua") -- Author: Eduardo Ochs <eduardoochs@gmail.com> -- -- (defun e () (interactive) (find-angg "LUA/LuaBlocks.lua")) LuaBlocks = Class { fromfile0 = function (fname) local lines = splitlines(ee_readfile(fname)) return LuaBlocks {lines = lines, ranges = nil, sranges = nil} end, type = "LuaBlocks", __index = { line = function (lb, i) return lb.lines[i] end, nlines = function (lb) return #lb.lines end, afterend = function (lb, i) return lb:line(i) == nil end, emptyline = function (lb, i) return lb:line(i) == "" end, nonemptyline = function (lb, i) return lb:line(i) and not lb:emptyline(i) end, getranges = function (lb) lb.ranges = {} local i,j = 1,1 while true do while lb:emptyline(i) do i = i + 1 end if lb:afterend(i) then return lb end j = i while lb:nonemptyline(j + 1) do j = j + 1 end table.insert(lb.ranges, {i, j}) i = j + 1 end end, gendefs = function (lb, i, j, step) return cow(function () for k=i,j,(step or 1) do local li = lb:line(k) local name = li:match("^([A-za-z_][A-za-z0-9_]+)%s+=") if name then coy(k, name) end end end) end, genalldefs = function (lb) return cow(function () for _,ij in ipairs(lb.ranges) do local i,j = ij[1], ij[2] for k,name in lb:gendefs(i, j) do coy(i, j, k, name) end end end) end, getsranges = function (lb) lb.sranges = SetL.new() lb.sdefs = SetL.new() for _,ij in ipairs(lb.ranges) do local i,j = ij[1], ij[2] local i_j = i.."-"..j local sr = {i=i, j=j, defs=SetL.new()} for k,name in lb:gendefs(i, j) do sr.defs:add(name, k) lb.sdefs:add(name, i_j) end lb.sranges:add(i_j, sr) end return lb end, }, } --[[ * (eepitch-lua51) * (eepitch-kill) * (eepitch-lua51) dofile "LuaBlocks.lua" lb = LuaBlocks.fromfile0("LuaBlocks.lua"):getranges() PPV(lb.ranges) PPV(lb.lines) for k,name in lb:gendefs(1, 40) do print(name, k) end for i,j,k,name in lb:genalldefs() do print(i, j, k, name) end lb = LuaBlocks.fromfile0("~/LUA/lua50init.lua") lb:getranges() for i,j,k,name in lb:genalldefs() do print(i, j, k, name) end lb:getsranges() -- for name,sr in lb.sranges:gen() do PP(name, sr) end -- for name,sr in lb.sranges:gen() do PP(name, sr.defs) end for name,sr in lb.sranges:gen() do PP(name, sr.defs.list) end somenames = Set.from(split("copy map Class")) for name,i_j in lb.sdefs :gen() do print(i_j, name) end for name,i_j in (lb.sdefs * somenames):gen() do print(i_j, name) end --]]