Changeset 2509 for code/branches/buildsystem2/src/tolua/lua/clean.lua
- Timestamp:
- Dec 17, 2008, 8:59:48 PM (16 years ago)
- Location:
- code/branches/buildsystem2
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/buildsystem2
- Property svn:ignore deleted
- Property svn:mergeinfo changed
/code/branches/buildsystem (added) merged: 1875,1882-1886,1975-1982,1991,1999,2054,2061,2135,2137-2139,2197-2199,2204,2214-2220,2223-2224,2229,2233-2244,2248-2249,2252-2253,2260,2275
-
code/branches/buildsystem2/src/tolua/lua/clean.lua
r2087 r2509 10 10 11 11 MASK = { -- 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 , "%-%-"}, 19 19 } 20 20 21 21 function mask (s) 22 for i = 1,getn(MASK) do23 s = gsub(s,MASK[i][2],MASK[i][1])24 end25 return s22 for i = 1,getn(MASK) do 23 s = gsub(s,MASK[i][2],MASK[i][1]) 24 end 25 return s 26 26 end 27 27 28 28 function unmask (s) 29 for i = 1,getn(MASK) do30 s = gsub(s,MASK[i][1],MASK[i][2])31 end32 return s29 for i = 1,getn(MASK) do 30 s = gsub(s,MASK[i][1],MASK[i][2]) 31 end 32 return s 33 33 end 34 34 35 35 function clean (s) 36 -- check for compilation error37 local code = "return function ()\n" .. s .. "\n end"38 if not dostring(code) then39 return nil40 end36 -- check for compilation error 37 local code = "return function ()\n" .. s .. "\n end" 38 if not dostring(code) then 39 return nil 40 end 41 41 42 if flags['C'] then43 44 end42 if flags['C'] then 43 return s 44 end 45 45 46 local S = "" -- saved string46 local S = "" -- saved string 47 47 48 s = mask(s)48 s = mask(s) 49 49 50 -- remove blanks and comments51 while 1 do52 local b,e,d = strfind(s,ANY)53 if b then54 S = S..strsub(s,1,b-1)55 s = strsub(s,b+1)56 if d==STR1 or d==STR2 then57 e = strfind(s,d)58 S = S ..d..strsub(s,1,e)59 s = strsub(s,e+1)60 elseif d==STR3 then61 e = strfind(s,STR4)62 S = S..d..strsub(s,1,e)63 s = strsub(s,e+1)64 elseif d==REM then65 s = gsub(s,"[^\n]*(\n?)","%1",1)66 end67 else68 S = S..s69 break70 end71 end72 -- eliminate unecessary spaces73 S = gsub(S,"[ \t]+"," ")74 S = gsub(S,"[ \t]*\n[ \t]*","\n")75 76 S = unmask(S)77 return S50 -- 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 78 78 end 79 79
Note: See TracChangeset
for help on using the changeset viewer.