diff options
author | Richard Maw <richard.maw@codethink.co.uk> | 2015-11-26 15:29:42 +0000 |
---|---|---|
committer | Richard Maw <richard.maw@codethink.co.uk> | 2015-11-27 17:46:52 +0000 |
commit | fd4450a59d1fb8c8e1c119449ad5e76213cd4ad2 (patch) | |
tree | 627b6a5999c7c42a2831c28e8ed2833c5e9c9bfd | |
parent | de4afd7994fcfa33590e0552815353f54d4a6e97 (diff) | |
download | lace-fd4450a59d1fb8c8e1c119449ad5e76213cd4ad2.tar.gz |
lace.error: Split out subword collection logic
-rw-r--r-- | lib/lace/builtin.lua | 7 | ||||
-rw-r--r-- | lib/lace/error.lua | 10 |
2 files changed, 11 insertions, 6 deletions
diff --git a/lib/lace/builtin.lua b/lib/lace/builtin.lua index 19ad796..7577610 100644 --- a/lib/lace/builtin.lua +++ b/lib/lace/builtin.lua @@ -35,12 +35,7 @@ local function run_conditions(exec_context, cond, anyof) end local res, msg = engine.test(exec_context, name) if res == nil then - local subwords = msg.words - if subwords and #subwords > 0 then - msg.words = {{nr = i, sub = subwords}} - else - msg.words = {i} - end + msg.words = {err.subwords(msg, i)} return nil, msg end if invert then diff --git a/lib/lace/error.lua b/lib/lace/error.lua index 6277233..0ad0df6 100644 --- a/lib/lace/error.lua +++ b/lib/lace/error.lua @@ -76,6 +76,15 @@ local function _augment(err, source, linenr) return err end +local function _subwords(err, word) + local subwords = err.words + if subwords and #subwords > 0 then + return {nr = word, sub = subwords} + else + return word + end +end + --- Render an error down to a string. -- -- Error tables carry a message, an optional set of words which caused the @@ -159,5 +168,6 @@ return { error = _error, offset = _offset, augment = _augment, + subwords = _subwords, render = _render, } |