mirror of
https://github.com/leafo/moonscript.git
synced 2024-11-22 02:44:23 +00:00
clean up moonc
This commit is contained in:
parent
5904373ab8
commit
6cdfca6ab2
28
bin/moonc
28
bin/moonc
@ -1,16 +1,8 @@
|
|||||||
#!/usr/bin/env lua
|
#!/usr/bin/env lua
|
||||||
|
|
||||||
local parse = require "moonscript.parse"
|
|
||||||
local compile = require "moonscript.compile"
|
|
||||||
local util = require "moonscript.util"
|
|
||||||
|
|
||||||
local dump_tree = require"moonscript.dump".tree
|
|
||||||
|
|
||||||
local alt_getopt = require "alt_getopt"
|
local alt_getopt = require "alt_getopt"
|
||||||
local lfs = require "lfs"
|
local lfs = require "lfs"
|
||||||
|
|
||||||
local dirsep = package.config:sub(1,1)
|
|
||||||
|
|
||||||
local opts, ind = alt_getopt.get_opts(arg, "lvhwt:o:pTXb", {
|
local opts, ind = alt_getopt.get_opts(arg, "lvhwt:o:pTXb", {
|
||||||
print = "p", tree = "T", version = "v", help = "h", lint = "l"
|
print = "p", tree = "T", version = "v", help = "h", lint = "l"
|
||||||
})
|
})
|
||||||
@ -113,15 +105,15 @@ local function get_files(fname, files)
|
|||||||
if lfs.attributes(fname, "mode") == "directory" then
|
if lfs.attributes(fname, "mode") == "directory" then
|
||||||
for _, sub_fname in ipairs(scan_directory(fname)) do
|
for _, sub_fname in ipairs(scan_directory(fname)) do
|
||||||
table.insert(files, {
|
table.insert(files, {
|
||||||
sub_fname,
|
sub_fname,
|
||||||
path_to_target(sub_fname, opts.t, fname)
|
path_to_target(sub_fname, opts.t, fname)
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
table.insert(files, {
|
table.insert(files, {
|
||||||
fname,
|
fname,
|
||||||
path_to_target(fname, opts.t)
|
path_to_target(fname, opts.t)
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
return files
|
return files
|
||||||
@ -130,8 +122,12 @@ end
|
|||||||
if opts.h then print_help() end
|
if opts.h then print_help() end
|
||||||
|
|
||||||
if read_stdin then
|
if read_stdin then
|
||||||
|
local parse = require "moonscript.parse"
|
||||||
|
local compile = require "moonscript.compile"
|
||||||
|
|
||||||
local text = io.stdin:read("*a")
|
local text = io.stdin:read("*a")
|
||||||
local tree, err = parse.string(text)
|
local tree, err = parse.string(text)
|
||||||
|
|
||||||
if not tree then error(err) end
|
if not tree then error(err) end
|
||||||
local code, err, pos = compile.tree(tree)
|
local code, err, pos = compile.tree(tree)
|
||||||
|
|
||||||
@ -158,7 +154,7 @@ for _, input in ipairs(inputs) do
|
|||||||
end
|
end
|
||||||
|
|
||||||
files = remove_dups(files, function(f)
|
files = remove_dups(files, function(f)
|
||||||
return f[2]
|
return f[2]
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local function get_sleep_func()
|
local function get_sleep_func()
|
||||||
@ -293,7 +289,7 @@ if opts.w then
|
|||||||
elseif opts.l then
|
elseif opts.l then
|
||||||
for _, tuple in pairs(files) do
|
for _, tuple in pairs(files) do
|
||||||
local fname = tuple[1]
|
local fname = tuple[1]
|
||||||
lint = require "moonscript.cmd.lint"
|
local lint = require "moonscript.cmd.lint"
|
||||||
local res, err = lint.lint_file(fname)
|
local res, err = lint.lint_file(fname)
|
||||||
if res then
|
if res then
|
||||||
io.stderr:write(res .. "\n\n")
|
io.stderr:write(res .. "\n\n")
|
||||||
|
Loading…
Reference in New Issue
Block a user