[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Why duplicate keys in table constructor isn't an error?
 
- From: Luiz Henrique de Figueiredo <lhf@...>
 
- Date: Tue, 13 Mar 2007 11:59:52 -0300
 
Try this tool.
-- find duplicated keys in table constructors
-- typical usage: luac -p -l *.lua | lua keys.lua
local F,K
while true do
 local s=io.read()
 if s==nil then break end
 local ok,_,f=string.find(s,"^[mf].-<(.-):[%d,]+>")
 if ok then F=f end
 local ok,_,l,op=string.find(s,"%[%-?(%d*)%]%s+(%S+)")
 if ok then
  if op=="NEWTABLE" then 
   K={}
  elseif op=="SETTABLE" then 
   local _,_,k=string.find(s,';%s*(".-")')
   if K[k] then 
    io.write(F,":",l,": duplicate key ",k," in table constructor\n")
   else
    K[k]=true
   end
  end
 end
end