mirror of
https://github.com/leafo/moonscript.git
synced 2024-11-22 02:44:23 +00:00
parse/compile errors have better error messages
This commit is contained in:
parent
c3fd7812ce
commit
c344b8ca3a
11
bin/moon
11
bin/moon
@ -41,7 +41,16 @@ local new_arg = {
|
||||
select(ind + 1, unpack(arg))
|
||||
}
|
||||
|
||||
local chunk = moonscript.loadfile(script_fname)
|
||||
local chunk
|
||||
local passed, err = pcall(function()
|
||||
chunk = moonscript.loadfile(script_fname)
|
||||
end)
|
||||
|
||||
if not passed then
|
||||
print(err)
|
||||
os.exit()
|
||||
end
|
||||
|
||||
getfenv(chunk).arg = new_arg
|
||||
|
||||
local runner = coroutine.create(chunk)
|
||||
|
@ -27,7 +27,7 @@ to_lua = function(text)
|
||||
end
|
||||
local tree, err = parse.string(text)
|
||||
if not tree then
|
||||
error("Parse error: " .. err, 2)
|
||||
error(err, 2)
|
||||
end
|
||||
local code, ltable, pos = compile.tree(tree)
|
||||
if not code then
|
||||
@ -65,7 +65,12 @@ if not _G.moon_no_loader then
|
||||
init_loader()
|
||||
end
|
||||
loadstring = function(str, chunk_name)
|
||||
local code, ltable = to_lua(str)
|
||||
local passed, code, ltable = pcall(function()
|
||||
return to_lua(str)
|
||||
end)
|
||||
if not passed then
|
||||
error(chunk_name .. ": " .. code, 2)
|
||||
end
|
||||
if chunk_name then
|
||||
line_tables[chunk_name] = ltable
|
||||
end
|
||||
|
@ -31,7 +31,7 @@ to_lua = (text) ->
|
||||
|
||||
tree, err = parse.string text
|
||||
if not tree
|
||||
error "Parse error: " .. err, 2
|
||||
error err, 2
|
||||
|
||||
code, ltable, pos = compile.tree tree
|
||||
if not code
|
||||
@ -63,7 +63,10 @@ init_loader = ->
|
||||
init_loader! if not _G.moon_no_loader
|
||||
|
||||
loadstring = (str, chunk_name) ->
|
||||
code, ltable = to_lua str
|
||||
passed, code, ltable = pcall -> to_lua str
|
||||
if not passed
|
||||
error chunk_name .. ": " .. code, 2
|
||||
|
||||
line_tables[chunk_name] = ltable if chunk_name
|
||||
lua.loadstring code, chunk_name or "=(moonscript.loadstring)"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user