Skip to content

Commit 80750e0

Browse files
committed
update compile error format to match the new parser error format
1 parent a21a0b5 commit 80750e0

2 files changed

Lines changed: 13 additions & 26 deletions

File tree

moonscript/compile.lua

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@ do
1515
end
1616
local statement_compilers = require("moonscript.compile.statement")
1717
local value_compilers = require("moonscript.compile.value")
18+
local parse_errors = require("moonscript.parse.errors")
1819
local concat, insert
1920
do
2021
local _obj_0 = table
2122
concat, insert = _obj_0.concat, _obj_0.insert
2223
end
23-
local pos_to_line, get_closest_line, trim, unpack, mtype
24-
pos_to_line, get_closest_line, trim, unpack, mtype = util.pos_to_line, util.get_closest_line, util.trim, util.unpack, util.mtype
24+
local unpack, mtype
25+
unpack, mtype = util.unpack, util.mtype
2526
local indent_char = " "
2627
local Line, DelayedLine, Lines, Block, RootBlock
2728
local line_locator
@@ -757,19 +758,11 @@ do
757758
end
758759
local format_error
759760
format_error = function(msg, pos, file_str)
760-
msg = tostring(msg)
761-
local line_message
762-
if pos then
763-
local line = pos_to_line(file_str, pos)
764-
local line_str
765-
line_str, line = get_closest_line(file_str, line)
766-
line_str = line_str or ""
767-
line_message = (" [%d] >> %s"):format(line, trim(line_str))
761+
msg = "failed to compile: " .. tostring(msg)
762+
if not (pos) then
763+
return msg
768764
end
769-
return concat({
770-
"Compile error: " .. msg,
771-
line_message
772-
}, "\n")
765+
return parse_errors.format(file_str, pos, msg)
773766
end
774767
local value
775768
value = function(value)

moonscript/compile.moon

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ import ntype, value_can_be_statement from require "moonscript.types"
1010
statement_compilers = require "moonscript.compile.statement"
1111
value_compilers = require "moonscript.compile.value"
1212

13+
parse_errors = require "moonscript.parse.errors"
14+
1315
import concat, insert from table
14-
import pos_to_line, get_closest_line, trim, unpack, mtype from util
16+
import unpack, mtype from util
1517

1618
indent_char = " "
1719

@@ -511,17 +513,9 @@ class RootBlock extends Block
511513
table.concat buffer
512514

513515
format_error = (msg, pos, file_str) ->
514-
msg = tostring msg
515-
line_message = if pos
516-
line = pos_to_line file_str, pos
517-
line_str, line = get_closest_line file_str, line
518-
line_str = line_str or ""
519-
(" [%d] >> %s")\format line, trim line_str
520-
521-
concat {
522-
"Compile error: "..msg
523-
line_message
524-
}, "\n"
516+
msg = "failed to compile: " .. tostring msg
517+
return msg unless pos
518+
parse_errors.format file_str, pos, msg
525519

526520
value = (value) ->
527521
out = nil

0 commit comments

Comments
 (0)