Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 19, 2008, 4:40:43 PM (15 years ago)
Author:
rgrieder
Message:

Cleaned up indentation chaos in tolua. There were tabs and 1 space indentations, even mixed in a single block.
It should now be possible to actually pimp these files.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/buildsystem/src/tolua/lua/clean.lua

    r1755 r2229  
    1010
    1111MASK = { -- the substitution order is important
    12  {ESC1, "\\'"},
    13  {ESC2, '\\"'},
    14  {STR1, "'"},
    15  {STR2, '"'},
    16  {STR3, "%[%["},
    17  {STR4, "%]%]"},
    18  {REM , "%-%-"},
     12    {ESC1, "\\'"},
     13    {ESC2, '\\"'},
     14    {STR1, "'"},
     15    {STR2, '"'},
     16    {STR3, "%[%["},
     17    {STR4, "%]%]"},
     18    {REM , "%-%-"},
    1919}
    2020
    2121function mask (s)
    22  for i = 1,getn(MASK)  do
    23   s = gsub(s,MASK[i][2],MASK[i][1])
    24  end
    25  return s
     22    for i = 1,getn(MASK)  do
     23        s = gsub(s,MASK[i][2],MASK[i][1])
     24    end
     25    return s
    2626end
    2727
    2828function unmask (s)
    29  for i = 1,getn(MASK)  do
    30   s = gsub(s,MASK[i][1],MASK[i][2])
    31  end
    32  return s
     29    for i = 1,getn(MASK)  do
     30        s = gsub(s,MASK[i][1],MASK[i][2])
     31    end
     32    return s
    3333end
    3434
    3535function clean (s)
    36  -- check for compilation error
    37  local code = "return function ()\n" .. s .. "\n end"
    38  if not dostring(code) then
    39   return nil
    40  end
     36    -- check for compilation error
     37    local code = "return function ()\n" .. s .. "\n end"
     38    if not dostring(code) then
     39        return nil
     40    end
    4141
    42  if flags['C'] then
    43         return s
    44  end
     42    if flags['C'] then
     43        return s
     44    end
    4545
    46  local S = "" -- saved string
     46    local S = "" -- saved string
    4747
    48  s = mask(s)
     48    s = mask(s)
    4949
    50  -- remove blanks and comments
    51  while 1 do
    52   local b,e,d = strfind(s,ANY)
    53   if b then
    54    S = S..strsub(s,1,b-1)
    55    s = strsub(s,b+1)
    56    if d==STR1 or d==STR2 then
    57     e = strfind(s,d)
    58     S = S ..d..strsub(s,1,e)
    59     s = strsub(s,e+1)
    60    elseif d==STR3 then
    61     e = strfind(s,STR4)
    62     S = S..d..strsub(s,1,e)
    63     s = strsub(s,e+1)
    64    elseif d==REM then
    65     s = gsub(s,"[^\n]*(\n?)","%1",1)
    66    end
    67   else
    68    S = S..s
    69    break
    70   end
    71  end
    72  -- eliminate unecessary spaces
    73  S = gsub(S,"[ \t]+"," ")
    74  S = gsub(S,"[ \t]*\n[ \t]*","\n")
    75         S = gsub(S,"\n+","\n")
    76  S = unmask(S)
    77  return S
     50    -- remove blanks and comments
     51    while 1 do
     52        local b,e,d = strfind(s,ANY)
     53        if b then
     54            S = S..strsub(s,1,b-1)
     55            s = strsub(s,b+1)
     56            if d==STR1 or d==STR2 then
     57                e = strfind(s,d)
     58                S = S ..d..strsub(s,1,e)
     59                s = strsub(s,e+1)
     60            elseif d==STR3 then
     61                e = strfind(s,STR4)
     62                S = S..d..strsub(s,1,e)
     63                s = strsub(s,e+1)
     64            elseif d==REM then
     65                s = gsub(s,"[^\n]*(\n?)","%1",1)
     66            end
     67        else
     68            S = S..s
     69            break
     70        end
     71    end
     72    -- eliminate unecessary spaces
     73    S = gsub(S,"[ \t]+"," ")
     74    S = gsub(S,"[ \t]*\n[ \t]*","\n")
     75    S = gsub(S,"\n+","\n")
     76    S = unmask(S)
     77    return S
    7878end
    7979
Note: See TracChangeset for help on using the changeset viewer.