From 8ca7749b5509a40256195563fa52d3ede4bd1a34 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Wed, 16 Jan 2019 16:31:49 -0800 Subject: Better error messaging (using pretty_error in more places) --- nomsu_compiler.moon | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'nomsu_compiler.moon') diff --git a/nomsu_compiler.moon b/nomsu_compiler.moon index f3530e9..0bb020c 100644 --- a/nomsu_compiler.moon +++ b/nomsu_compiler.moon @@ -8,9 +8,8 @@ unpack or= table.unpack SyntaxTree = require "syntax_tree" Files = require "files" --- TODO: de-duplicate this pretty_error = require("pretty_errors") -compile_error = (source, err_msg, hint=nil)-> +fail_at = (source, msg)-> local file if SyntaxTree\is_instance(source) file = source\get_source_file! @@ -20,10 +19,20 @@ compile_error = (source, err_msg, hint=nil)-> if source and not file file = Files.read(source.filename) + title, err_msg, hint = msg\match("([^:]*):[ \n]+(.*)[ \n]+Hint: (.*)") + if not err_msg + err_msg, hint = msg\match("*(.*)[ \n]+Hint:[ \n]+(.*)") + title = "Error" + if not err_msg + title, err_msg = msg\match("([^:]*):[ \n]+(.*)") + if not err_msg + err_msg = msg + title = "Error" + err_str = pretty_error{ - title: "Compile error" - error:err_msg, hint:hint, source:file - start:source.start, stop:source.stop, filename:source.filename + title: title, + error: err_msg, hint: hint, source: file, + start:source.start, stop:source.stop, filename:source.filename, } error(err_str, 0) @@ -60,9 +69,9 @@ compile = (tree)=> if ret == nil info = debug.getinfo(compile_action, "S") filename = Source\from_string(info.source).filename - compile_error tree, - "The compile-time action here (#{stub}) failed to return any value.", - "Look at the implementation of (#{stub}) in #{filename}:#{info.linedefined} and make sure it's returning something." + fail_at tree, + ("Compile error: The compile-time action here (#{stub}) failed to return any value. ".. + "Hint: Look at the implementation of (#{stub}) in #{filename}:#{info.linedefined} and make sure it's returning something.") unless SyntaxTree\is_instance(ret) ret.source or= tree.source return ret @@ -282,4 +291,4 @@ compile = (tree)=> else error("Unknown type: #{tree.type}") -return {:compile, :compile_error} +return {:compile, :fail_at} -- cgit v1.2.3