aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/treesitter/query.lua
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/lua/vim/treesitter/query.lua')
-rw-r--r--runtime/lua/vim/treesitter/query.lua22
1 files changed, 20 insertions, 2 deletions
diff --git a/runtime/lua/vim/treesitter/query.lua b/runtime/lua/vim/treesitter/query.lua
index 9b4d28e09a..b81eb18945 100644
--- a/runtime/lua/vim/treesitter/query.lua
+++ b/runtime/lua/vim/treesitter/query.lua
@@ -231,7 +231,7 @@ local predicate_handlers = {
local compiled_vim_regexes = setmetatable({}, {
__index = function(t, pattern)
- local res = vim.regex(check_magic(vim.fn.escape(pattern, '\\')))
+ local res = vim.regex(check_magic(pattern))
rawset(t, pattern, res)
return res
end
@@ -260,7 +260,25 @@ local predicate_handlers = {
end
return false
- end
+ end,
+
+ ["any-of?"] = function(match, _, source, predicate)
+ local node = match[predicate[2]]
+ local node_text = M.get_node_text(node, source)
+
+ -- Since 'predicate' will not be used by callers of this function, use it
+ -- to store a string set built from the list of words to check against.
+ local string_set = predicate["string_set"]
+ if not string_set then
+ string_set = {}
+ for i=3,#predicate do
+ string_set[predicate[i]] = true
+ end
+ predicate["string_set"] = string_set
+ end
+
+ return string_set[node_text]
+ end,
}
-- As we provide lua-match? also expose vim-match?