mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
treesitter: add predicate "any-of?" (#14344)
For the case of Clojure and other Lisp syntax highlighting, it is necessary to create huge regexps consisting of hundreds of symbols with the pipe (|) character. To make things more difficult, these Lisp symbols sometimes consists of special characters that are themselves part of special regexp characters like '*'. In addition to being difficult to maintain, it's performance is suboptimal. This patch introduces a new predicate to perform 'source' matching in amortized constant time. This is accomplished by compiling a hash table on the first use.
This commit is contained in:
@@ -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?
|
||||
|
||||
Reference in New Issue
Block a user