diff options
| author | Bruce Hill <bitbucket@bruce-hill.com> | 2018-05-26 15:58:32 -0700 |
|---|---|---|
| committer | Bruce Hill <bitbucket@bruce-hill.com> | 2018-05-26 15:59:03 -0700 |
| commit | 0c7c06beabc5a2ef4f89923cc8cf59331e2c32cf (patch) | |
| tree | dd7cd63e52dc4d2c3bf33b9adf7eda87997f76aa /nomsu.lua | |
| parent | 8cb2788e0dc514e6d6436a7a03e87e414327ec94 (diff) | |
Moving back to capturing tables in LPEG and everything is a Source, not
string.
Diffstat (limited to 'nomsu.lua')
| -rw-r--r-- | nomsu.lua | 15 |
1 files changed, 5 insertions, 10 deletions
@@ -211,14 +211,14 @@ do return true end local err_pos = start_pos - local text_loc = lpeg.userdata.source_code.source:sub(err_pos, err_pos) + local text_loc = lpeg.userdata.source:sub(err_pos, err_pos) local line_no = text_loc:get_line_number() src = FILE_CACHE[text_loc.filename] local prev_line = line_no == 1 and "" or src:sub(LINE_STARTS[src][line_no - 1] or 1, LINE_STARTS[src][line_no] - 2) local err_line = src:sub(LINE_STARTS[src][line_no], (LINE_STARTS[src][line_no + 1] or 0) - 2) local next_line = src:sub(LINE_STARTS[src][line_no + 1] or -1, (LINE_STARTS[src][line_no + 2] or 0) - 2) local pointer = ("-"):rep(err_pos - LINE_STARTS[src][line_no]) .. "^" - err_msg = (err_msg or "Parse error") .. " at " .. tostring(lpeg.userdata.source_code.source.filename) .. ":" .. tostring(line_no) .. ":\n" + err_msg = (err_msg or "Parse error") .. " at " .. tostring(lpeg.userdata.source.filename) .. ":" .. tostring(line_no) .. ":\n" if #prev_line > 0 then err_msg = err_msg .. ("\n" .. prev_line) end @@ -234,18 +234,13 @@ end setmetatable(NOMSU_DEFS, { __index = function(self, key) local make_node - make_node = function(start, ...) - local args = { - ... - } - local stop = args[#args] + make_node = function(start, value, stop) local source = lpeg.userdata.source:sub(start, stop) - args[#args] = nil local tree if Types[key].is_multi then - tree = Types[key](Tuple(unpack(args)), source) + tree = Types[key](Tuple(unpack(value)), source) else - tree = Types[key](args[1], source) + tree = Types[key](value, source) end return tree end |
