-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit fd933e7
Showing
16,524 changed files
with
2,725,177 additions
and
0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
-- | ||
-- beautify | ||
-- | ||
-- A command line utility for beautifying lua source code using the beautifier. | ||
-- | ||
|
||
local util = require'Util' | ||
local Parser = require'ParseLua' | ||
local Format_Beautify = require'FormatBeautiful' | ||
local ParseLua = Parser.ParseLua | ||
local PrintTable = util.PrintTable | ||
|
||
local function splitFilename(name) | ||
--table.foreach(arg, print) | ||
if name:find(".") then | ||
local p, ext = name:match("()%.([^%.]*)$") | ||
if p and ext then | ||
if #ext == 0 then | ||
return name, nil | ||
else | ||
local filename = name:sub(1,p-1) | ||
return filename, ext | ||
end | ||
else | ||
return name, nil | ||
end | ||
else | ||
return name, nil | ||
end | ||
end | ||
|
||
if #arg == 1 then | ||
local name, ext = splitFilename(arg[1]) | ||
local outname = name.."_formatted" | ||
if ext then outname = outname.."."..ext end | ||
-- | ||
local inf = io.open(arg[1], 'r') | ||
if not inf then | ||
print("Failed to open '"..arg[1].."' for reading") | ||
return | ||
end | ||
-- | ||
local sourceText = inf:read('*all') | ||
inf:close() | ||
-- | ||
local st, ast = ParseLua(sourceText) | ||
if not st then | ||
--we failed to parse the file, show why | ||
print(ast) | ||
return | ||
end | ||
-- | ||
local outf = io.open(outname, 'w') | ||
if not outf then | ||
print("Failed to open '"..outname.."' for writing") | ||
return | ||
end | ||
-- | ||
outf:write(Format_Beautify(ast)) | ||
outf:close() | ||
-- | ||
print("Beautification complete") | ||
|
||
elseif #arg == 2 then | ||
--keep the user from accidentally overwriting their non-minified file with | ||
if arg[1]:find("_formatted") then | ||
print("Did you mix up the argument order?\n".. | ||
"Current command will beautify '"..arg[1].."' and overwrite '"..arg[2].."' with the results") | ||
while true do | ||
io.write("Confirm (yes/no): ") | ||
local msg = io.read('*line') | ||
if msg == 'yes' then | ||
break | ||
elseif msg == 'no' then | ||
return | ||
end | ||
end | ||
end | ||
local inf = io.open(arg[1], 'r') | ||
if not inf then | ||
print("Failed to open '"..arg[1].."' for reading") | ||
return | ||
end | ||
-- | ||
local sourceText = inf:read('*all') | ||
inf:close() | ||
-- | ||
local st, ast = ParseLua(sourceText) | ||
if not st then | ||
--we failed to parse the file, show why | ||
print(ast) | ||
return | ||
end | ||
-- | ||
if arg[1] == arg[2] then | ||
print("Are you SURE you want to overwrite the source file with a beautified version?\n".. | ||
"You will be UNABLE to get the original source back!") | ||
while true do | ||
io.write("Confirm (yes/no): ") | ||
local msg = io.read('*line') | ||
if msg == 'yes' then | ||
break | ||
elseif msg == 'no' then | ||
return | ||
end | ||
end | ||
end | ||
local outf = io.open(arg[2], 'w') | ||
if not outf then | ||
print("Failed to open '"..arg[2].."' for writing") | ||
return | ||
end | ||
-- | ||
outf:write(Format_Beautify(ast)) | ||
outf:close() | ||
-- | ||
print("Beautification complete") | ||
|
||
else | ||
print("Invalid arguments!\nUsage: lua CommandLineLuaBeautify.lua source_file [destination_file]") | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
|
||
-- | ||
-- beautify.interactive | ||
-- | ||
-- For testing: Lets you enter lines of text to be beautified to verify the | ||
-- correctness of their implementation. | ||
-- | ||
|
||
local util = require'Util' | ||
local Parser = require'ParseLua' | ||
local Format_Beautify = require'FormatBeautiful' | ||
local ParseLua = Parser.ParseLua | ||
local PrintTable = util.PrintTable | ||
|
||
while true do | ||
io.write('> ') | ||
local line = io.read('*line') | ||
local fileFrom, fileTo = line:match("^file (.*) (.*)") | ||
if fileFrom and fileTo then | ||
local file = io.open(fileFrom, 'r') | ||
local fileTo = io.open(fileTo, 'w') | ||
if file and fileTo then | ||
local st, ast = ParseLua(file:read('*all')) | ||
if st then | ||
fileTo:write(Format_Beautify(ast)..'\n') | ||
io.write("Beautification Complete\n") | ||
else | ||
io.write(""..tostring(ast).."\n") | ||
end | ||
file:close() | ||
fileTo:close() | ||
else | ||
io.write("File does not exist\n") | ||
end | ||
else | ||
local st, ast = ParseLua(line) | ||
if st then | ||
io.write("====== AST =======\n") | ||
io.write(PrintTable(ast)..'\n') | ||
io.write("==== BEAUTIFIED ====\n") | ||
io.write(Format_Beautify(ast)) | ||
io.write("==================\n") | ||
else | ||
io.write(""..tostring(ast).."\n") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
|
||
-- | ||
-- CommandLineLiveMinify.lua | ||
-- | ||
-- For testing: Lets you enter lines of text to be minified to verify the | ||
-- correctness of their implementation. | ||
-- | ||
|
||
local util = require'Util' | ||
local Parser = require'ParseLua' | ||
local Format_Mini = require'FormatMini' | ||
local ParseLua = Parser.ParseLua | ||
local PrintTable = util.PrintTable | ||
|
||
while true do | ||
io.write('> ') | ||
local line = io.read('*line') | ||
local fileFrom, fileTo = line:match("^file (.*) (.*)") | ||
if fileFrom and fileTo then | ||
local file = io.open(fileFrom, 'r') | ||
local fileTo = io.open(fileTo, 'w') | ||
if file and fileTo then | ||
local st, ast = ParseLua(file:read('*all')) | ||
if st then | ||
fileTo:write(Format_Mini(ast)..'\n') | ||
io.write("Minification Complete\n") | ||
else | ||
io.write(""..tostring(ast).."\n") | ||
end | ||
file:close() | ||
fileTo:close() | ||
else | ||
io.write("File does not exist\n") | ||
end | ||
else | ||
local st, ast = ParseLua(line) | ||
if st then | ||
io.write("====== AST =======\n") | ||
io.write(PrintTable(ast)..'\n') | ||
io.write("==== MINIFIED ====\n") | ||
io.write(Format_Mini(ast)..'\n') | ||
io.write("==================\n") | ||
else | ||
io.write(""..tostring(ast).."\n") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
|
||
-- | ||
-- CommandlineMinify.lua | ||
-- | ||
-- A command line utility for minifying lua source code using the minifier. | ||
-- | ||
|
||
local util = require'Util' | ||
local Parser = require'ParseLua' | ||
local Format_Mini = require'FormatMini' | ||
local ParseLua = Parser.ParseLua | ||
local PrintTable = util.PrintTable | ||
|
||
local function splitFilename(name) | ||
table.foreach(arg, print) | ||
if name:find(".") then | ||
local p, ext = name:match("()%.([^%.]*)$") | ||
if p and ext then | ||
if #ext == 0 then | ||
return name, nil | ||
else | ||
local filename = name:sub(1,p-1) | ||
return filename, ext | ||
end | ||
else | ||
return name, nil | ||
end | ||
else | ||
return name, nil | ||
end | ||
end | ||
|
||
if #arg == 1 then | ||
local name, ext = splitFilename(arg[1]) | ||
local outname = name.."_min" | ||
if ext then outname = outname.."."..ext end | ||
-- | ||
local inf = io.open(arg[1], 'r') | ||
if not inf then | ||
print("Failed to open `"..arg[1].."` for reading") | ||
return | ||
end | ||
-- | ||
local sourceText = inf:read('*all') | ||
inf:close() | ||
-- | ||
local st, ast = ParseLua(sourceText) | ||
if not st then | ||
--we failed to parse the file, show why | ||
print(ast) | ||
return | ||
end | ||
-- | ||
local outf = io.open(outname, 'w') | ||
if not outf then | ||
print("Failed to open `"..outname.."` for writing") | ||
return | ||
end | ||
-- | ||
outf:write(Format_Mini(ast)) | ||
outf:close() | ||
-- | ||
print("Minification complete") | ||
|
||
elseif #arg == 2 then | ||
--keep the user from accidentally overwriting their non-minified file with | ||
if arg[1]:find("_min") then | ||
print("Did you mix up the argument order?\n".. | ||
"Current command will minify `"..arg[1].."` and OVERWRITE `"..arg[2].."` with the results") | ||
while true do | ||
io.write("Confirm (yes/cancel): ") | ||
local msg = io.read('*line') | ||
if msg == 'yes' then | ||
break | ||
elseif msg == 'cancel' then | ||
return | ||
end | ||
end | ||
end | ||
local inf = io.open(arg[1], 'r') | ||
if not inf then | ||
print("Failed to open `"..arg[1].."` for reading") | ||
return | ||
end | ||
-- | ||
local sourceText = inf:read('*all') | ||
inf:close() | ||
-- | ||
local st, ast = ParseLua(sourceText) | ||
if not st then | ||
--we failed to parse the file, show why | ||
print(ast) | ||
return | ||
end | ||
-- | ||
if arg[1] == arg[2] then | ||
print("Are you SURE you want to overwrite the source file with a minified version?\n".. | ||
"You will be UNABLE to get the original source back!") | ||
while true do | ||
io.write("Confirm (yes/cancel): ") | ||
local msg = io.read('*line') | ||
if msg == 'yes' then | ||
break | ||
elseif msg == 'cancel' then | ||
return | ||
end | ||
end | ||
end | ||
local outf = io.open(arg[2], 'w') | ||
if not outf then | ||
print("Failed to open `"..arg[2].."` for writing") | ||
return | ||
end | ||
-- | ||
outf:write(Format_Mini(ast)) | ||
outf:close() | ||
-- | ||
print("Minification complete") | ||
|
||
else | ||
print("Invalid arguments, Usage:\nLuaMinify source [destination]") | ||
end |
Oops, something went wrong.