diff options
author | Richard Maw <richard.maw@codethink.co.uk> | 2015-11-24 14:59:11 +0000 |
---|---|---|
committer | Richard Maw <richard.maw@codethink.co.uk> | 2015-11-24 14:59:11 +0000 |
commit | 21bc46875a0a25bef9c3700442e5189aa9be3f2a (patch) | |
tree | 5fa46daa0e95d599bccb2cb043871feaf9cf98a5 | |
parent | 9cd911814b6cdc961a50894ed95bb440efb8eda4 (diff) | |
download | lace-21bc46875a0a25bef9c3700442e5189aa9be3f2a.tar.gz |
lace: Collect subwords when collecting errors
-rw-r--r-- | lib/lace/builtin.lua | 7 | ||||
-rw-r--r-- | lib/lace/error.lua | 20 |
2 files changed, 23 insertions, 4 deletions
diff --git a/lib/lace/builtin.lua b/lib/lace/builtin.lua index 5f91086..b0c7ad1 100644 --- a/lib/lace/builtin.lua +++ b/lib/lace/builtin.lua @@ -35,7 +35,12 @@ local function run_conditions(exec_context, cond, anyof) end local res, msg = engine.test(exec_context, name) if res == nil then - msg.words = {i} + local subwords = msg.words + if subwords and #subwords > 0 then + msg.words = {{nr = i, sub = subwords}} + else + msg.words = {i} + end return nil, msg end if invert then diff --git a/lib/lace/error.lua b/lib/lace/error.lua index 96998bd..acc8fb2 100644 --- a/lib/lace/error.lua +++ b/lib/lace/error.lua @@ -49,7 +49,12 @@ local function _offset(err, offs) err.words = {} end for k, w in ipairs(err.words) do - err.words[k] = w + offs + if type(w) == "table" then + nr = w.nr + err.words[k] = {nr = nr + offs, sub=w.sub} + else + err.words[k] = w + offs + end end return err end @@ -96,9 +101,18 @@ local function _render(err) ret[3] = srcline.original -- The fourth line is the highlight for each word in question local wordset = {} - for _, word in ipairs(err.words) do - wordset[word] = true + local function build_wordset(words, wordset) + for _, word in ipairs(words) do + if type(word) ~= "table" then + wordset[word] = true + else + local subwordset = {} + build_wordset(word.sub, subwordset) + wordset[word.nr] = subwordset + end + end end + build_wordset(err.words, wordset) local hlstr = "" local cpos = 1 for w, info in ipairs(srcline.content) do |