aboutsummaryrefslogtreecommitdiff
path: root/nomsu.moon
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2017-10-12 14:39:49 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2017-10-12 14:39:49 -0700
commitc189be29bc7184771b02ce7ca1e0a63728db2ba8 (patch)
tree8e49a76e81c92af67594e606fe2cd82a20d9a69d /nomsu.moon
parent454bb76e2f889f13072445b57204d3e49c42e28c (diff)
Added better output control for stderr.
Diffstat (limited to 'nomsu.moon')
-rwxr-xr-xnomsu.moon27
1 files changed, 16 insertions, 11 deletions
diff --git a/nomsu.moon b/nomsu.moon
index 1695906..7e45d0d 100755
--- a/nomsu.moon
+++ b/nomsu.moon
@@ -184,6 +184,7 @@ nomsu = re.compile(nomsu, defs)
class NomsuCompiler
new:(parent)=>
@write = (...)=> io.write(...)
+ @write_err = (...)=> io.stderr\write(...)
@defs = setmetatable({}, {__index:parent and parent.defs})
@callstack = {}
@debug = false
@@ -197,6 +198,10 @@ class NomsuCompiler
@write(...)
@write("\n")
+ errorln:(...)=>
+ @write_err(...)
+ @write_err("\n")
+
def: (signature, thunk, src, is_macro=false)=>
assert type(thunk) == 'function', "Bad thunk: #{repr thunk}"
canonical_args = nil
@@ -293,7 +298,7 @@ class NomsuCompiler
@print_tree statement
ok,expr,statements = pcall(@tree_to_lua, self, statement)
if not ok
- @writeln "#{colored.red "Error occurred in statement:"}\n#{colored.bright colored.yellow statement.src}"
+ @errorln "#{colored.red "Error occurred in statement:"}\n#{colored.bright colored.yellow statement.src}"
@error(expr)
code_for_statement = ([[
return (function(nomsu, vars)
@@ -314,8 +319,8 @@ class NomsuCompiler
ok,ret = pcall(run_statement, self, vars)
if expr then return_value = ret
if not ok
- @writeln "#{colored.red "Error occurred in statement:"}\n#{colored.yellow statement.src}"
- @writeln debug.traceback!
+ @errorln "#{colored.red "Error occurred in statement:"}\n#{colored.yellow statement.src}"
+ @errorln debug.traceback!
@error(ret)
insert buffer, "#{statements or ''}\n#{expr and "ret = #{expr}" or ''}"
@@ -342,7 +347,7 @@ class NomsuCompiler
-- Return <lua code for value>, <additional lua code>
assert tree, "No tree provided."
if not tree.type
- @writeln debug.traceback()
+ @errorln debug.traceback()
@error "Invalid tree: #{repr(tree)}"
switch tree.type
when "File"
@@ -537,14 +542,14 @@ class NomsuCompiler
(var\gsub "%W", (verboten)->
if verboten == "_" then "__" else ("_%x")\format(verboten\byte!))
- error: (...)=>
- @writeln "ERROR!"
- if select(1, ...)
- @writeln(...)
- @writeln("Callstack:")
+ error: (msg)=>
+ @errorln (colored.red "ERROR!")
+ if msg
+ @errorln(colored.bright colored.yellow colored.onred msg)
+ @errorln("Callstack:")
for i=#@callstack,1,-1
- @writeln " #{@callstack[i]}"
- @writeln " <top level>"
+ @errorln " #{@callstack[i]}"
+ @errorln " <top level>"
@callstack = {}
error!