From 79c3d81f25523a22f7a86b6e405992b195d68741 Mon Sep 17 00:00:00 2001 From: Georgi Kirilov <> Date: Sat, 31 Oct 2020 11:50:52 +0200 Subject: [PATCH] add quasilist_at --- walker.lua | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/walker.lua b/walker.lua index 60bfc26..198e764 100644 --- a/walker.lua +++ b/walker.lua @@ -20,6 +20,13 @@ function M.new(parser, eol_at, bol_at) end end + local function escaped_at(range) + local node = parser.escaped.around(range) + -- TODO: distinguish between doublequoted strings, chars, line comments, and block comments + -- and use approprite offset comparisons for each + return node and range.start > node.start and range.finish <= node.finish and node + end + local function find_before_innermost(t, range, key, pred) if t.is_root or (t.d and t.start < range.start) then if t.d and not t.is_list then @@ -220,13 +227,6 @@ function M.new(parser, eol_at, bol_at) return node and node.finish + 1, node end, - escaped_at = function(range) - local node = parser.escaped.around(range) - -- TODO: distinguish between doublequoted strings, chars, line comments, and block comments - -- and use approprite offset comparisons for each - return node and range.start > node.start and range.finish <= node.finish and node - end, - prev_start_wrapped = function(range) local node, parent = parser.tree.sexp_at(range) if in_quasilist(node, range) then parent = node end @@ -314,7 +314,25 @@ function M.new(parser, eol_at, bol_at) return parent.start, parent.finish + 1 end, + -- opening: nil - bracketed list; false - any quasilist; + quasilist_at = function(range, opening) + if opening and opening:match'[%;%"]' then + local escaped = escaped_at(range) + return escaped and escaped.d:find("^"..opening) and escaped + else + local _, nodes = parser.tree.sexp_path(range) + local parent + local up = #nodes - 1 + repeat + parent = nodes[up] + up = up - 1 + until not parent or (opening == false or not opening or parent.d == opening) + return parent + end + end, + sexp_at = sexp_at, + escaped_at = escaped_at, paragraph_at = parser.tree.around, goto_path = parser.tree.goto_path, sexp_path = parser.tree.sexp_path, -- 2.11.4.GIT