aboutsummaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
authorStephan Seitz <stephan.seitz@fau.de>2020-07-27 10:06:56 +0200
committerThomas Vigouroux <39092278+vigoux@users.noreply.github.com>2020-07-27 11:07:09 +0200
commitfae96b588ddc734455b51a012c8917c5ee676f69 (patch)
tree104180cc806dee12fb6f1a7b1a4bb8f1ba34ad81 /lua
parentAdd predicate: has-ancestor? (diff)
downloadnvim-treesitter-fae96b588ddc734455b51a012c8917c5ee676f69.tar
nvim-treesitter-fae96b588ddc734455b51a012c8917c5ee676f69.tar.gz
nvim-treesitter-fae96b588ddc734455b51a012c8917c5ee676f69.tar.bz2
nvim-treesitter-fae96b588ddc734455b51a012c8917c5ee676f69.tar.lz
nvim-treesitter-fae96b588ddc734455b51a012c8917c5ee676f69.tar.xz
nvim-treesitter-fae96b588ddc734455b51a012c8917c5ee676f69.tar.zst
nvim-treesitter-fae96b588ddc734455b51a012c8917c5ee676f69.zip
Predicates: remove function unlispify and use Lisp names directly
Diffstat (limited to 'lua')
-rw-r--r--lua/nvim-treesitter/query_predicates.lua17
1 files changed, 6 insertions, 11 deletions
diff --git a/lua/nvim-treesitter/query_predicates.lua b/lua/nvim-treesitter/query_predicates.lua
index a7cca81a0..30a27af27 100644
--- a/lua/nvim-treesitter/query_predicates.lua
+++ b/lua/nvim-treesitter/query_predicates.lua
@@ -12,13 +12,8 @@ local function get_node(query, match, pred_item)
return utils.get_at_path(match, query.captures[pred_item]..'.node')
end
-local function unlispify(name)
- if not name then return '' end
- return string.gsub(string.gsub(name, "%?$", '') or '', '-', '_')
-end
-
function M.check_predicate(query, match, pred)
- local check_function = M[unlispify(pred[1])]
+ local check_function = M[pred[1]]
if check_function then
return check_function(query, match, pred)
else
@@ -27,7 +22,7 @@ function M.check_predicate(query, match, pred)
end
function M.check_negated_predicate(query, match, pred)
- local check_function = M[unlispify(string.sub(pred[1], #"not-" + 1))]
+ local check_function = M[string.sub(pred[1], #"not-" + 1)]
if check_function then
return not check_function(query, match, pred)
else
@@ -35,7 +30,7 @@ function M.check_negated_predicate(query, match, pred)
end
end
-function M.first(query, match, pred)
+M['first?'] = function (query, match, pred)
if #pred ~= 2 then error("first? must have exactly one argument!") end
local node = get_node(query, match, pred[2])
if node and node:parent() then
@@ -43,7 +38,7 @@ function M.first(query, match, pred)
end
end
-function M.last(query, match, pred)
+M['last?'] = function (query, match, pred)
if #pred ~= 2 then error("first? must have exactly one argument!") end
local node = get_node(query, match, pred[2])
if node and node:parent() then
@@ -52,7 +47,7 @@ function M.last(query, match, pred)
end
end
-function M.nth(query, match, pred)
+ M['nth?'] = function(query, match, pred)
if #pred ~= 3 then error("nth? must have exactly two arguments!") end
local node = get_node(query, match, pred[2])
if node and node:parent() then
@@ -60,7 +55,7 @@ function M.nth(query, match, pred)
end
end
-function M.has_ancestor(query, match, pred)
+M['has_ancestor?'] = function(query, match, pred)
if #pred ~= 3 then error("has-ancestor? must have exactly two arguments!") end
local node = get_node(query, match, pred[2])
local ancestor_type = pred[3]