From aafef187ef856a36c3f8e599afea2dee44f08904 Mon Sep 17 00:00:00 2001 From: faketruth Date: Mon, 3 Oct 2011 19:25:04 +0000 Subject: Source for additional projects -jsoncpp -lua -tolua++ -WebServer -zlib -iniFile git-svn-id: http://mc-server.googlecode.com/svn/trunk@4 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- tolua++-1.0.93/src/bin/lua/clean.lua | 79 ++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 tolua++-1.0.93/src/bin/lua/clean.lua (limited to 'tolua++-1.0.93/src/bin/lua/clean.lua') diff --git a/tolua++-1.0.93/src/bin/lua/clean.lua b/tolua++-1.0.93/src/bin/lua/clean.lua new file mode 100644 index 000000000..fd5b7b635 --- /dev/null +++ b/tolua++-1.0.93/src/bin/lua/clean.lua @@ -0,0 +1,79 @@ +-- mark up comments and strings +STR1 = "\001" +STR2 = "\002" +STR3 = "\003" +STR4 = "\004" +REM = "\005" +ANY = "([\001-\005])" +ESC1 = "\006" +ESC2 = "\007" + +MASK = { -- the substitution order is important + {ESC1, "\\'"}, + {ESC2, '\\"'}, + {STR1, "'"}, + {STR2, '"'}, + {STR3, "%[%["}, + {STR4, "%]%]"}, + {REM , "%-%-"}, +} + +function mask (s) + for i = 1,getn(MASK) do + s = gsub(s,MASK[i][2],MASK[i][1]) + end + return s +end + +function unmask (s) + for i = 1,getn(MASK) do + s = gsub(s,MASK[i][1],MASK[i][2]) + end + return s +end + +function clean (s) + -- check for compilation error + local code = "return function ()\n" .. s .. "\n end" + if not dostring(code) then + return nil + end + + if flags['C'] then + return s + end + + local S = "" -- saved string + + s = mask(s) + + -- remove blanks and comments + while 1 do + local b,e,d = strfind(s,ANY) + if b then + S = S..strsub(s,1,b-1) + s = strsub(s,b+1) + if d==STR1 or d==STR2 then + e = strfind(s,d) + S = S ..d..strsub(s,1,e) + s = strsub(s,e+1) + elseif d==STR3 then + e = strfind(s,STR4) + S = S..d..strsub(s,1,e) + s = strsub(s,e+1) + elseif d==REM then + s = gsub(s,"[^\n]*(\n?)","%1",1) + end + else + S = S..s + break + end + end + -- eliminate unecessary spaces + S = gsub(S,"[ \t]+"," ") + S = gsub(S,"[ \t]*\n[ \t]*","\n") + S = gsub(S,"\n+","\n") + S = unmask(S) + return S +end + -- cgit v1.2.3