diff options
author | Richard Maw <richard.maw@codethink.co.uk> | 2015-11-27 13:57:29 +0000 |
---|---|---|
committer | Richard Maw <richard.maw@codethink.co.uk> | 2015-11-27 17:46:53 +0000 |
commit | 3f9cb85510277f04e1f2b384aabc79c9bf46d86d (patch) | |
tree | e46e5790a8e8aaa2bda6114c2bec339d84df641a | |
parent | 55364c03d80f6923815498cc053291b746f32f05 (diff) | |
download | lace-3f9cb85510277f04e1f2b384aabc79c9bf46d86d.tar.gz |
lace.error.render: Build wordset before filling in lines
This is entirely cosmetic to make subsequent diffs,
that make it return lines for defines as well, more readable.
-rw-r--r-- | lib/lace/error.lua | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/lib/lace/error.lua b/lib/lace/error.lua index 2dc7cdb..cf21446 100644 --- a/lib/lace/error.lua +++ b/lib/lace/error.lua @@ -101,14 +101,7 @@ local function _render(err) -- A rendered error has four lines -- The first line is the error message local ret = { err.msg } - -- The second is the source filename and line - ret[2] = err.words.source.source .. " :: " .. tostring(err.words.linenr) - -- The third line is the line of the input - local srcline = err.words.source.lines[err.words.linenr] or { - original = "???", content = { {spos = 1, epos = 3, str = "???"} } - } - ret[3] = srcline.original - -- The fourth line is the highlight for each word in question + local wordset = {} local function build_wordset(words, wordset) for _, word in ipairs(words) do @@ -123,6 +116,15 @@ local function _render(err) end build_wordset(err.words, wordset) + -- The second is the source filename and line + ret[2] = err.words.source.source .. " :: " .. tostring(err.words.linenr) + -- The third line is the line of the input + local srcline = err.words.source.lines[err.words.linenr] or { + original = "???", content = { {spos = 1, epos = 3, str = "???"} } + } + ret[3] = srcline.original + + -- The fourth line is the highlight for each word in question local function mark_my_words(line, wordset) local hlstr, cpos = "", 1 for w, info in ipairs(line) do @@ -158,8 +160,8 @@ local function _render(err) return hlstr, cpos end local hlstr, _ = mark_my_words(srcline.content, wordset) - ret[4] = hlstr + -- The rendered error is those four strings joined by newlines return table.concat(ret, "\n") end |