treesitter: avoid escaping complete query strings

Escape "\\" only for `vim-match?` not for `match?`
Fixes #12595
This commit is contained in:
Stephan Seitz
2020-08-30 21:53:16 +02:00
parent 2bbbb34ce7
commit b058c671d2
2 changed files with 31 additions and 2 deletions

View File

@@ -198,6 +198,35 @@ void ui_refresh(void)
}, res)
end)
it('allow loading query with escaped quotes and capture them with `match?` and `vim-match?`', function()
if not check_parser() then return end
insert('char* astring = "Hello World!";')
local res = exec_lua([[
cquery = vim.treesitter.parse_query("c", '((_) @quote (vim-match? @quote "^\\"$")) ((_) @quote (match? @quote "^\\"$"))')
parser = vim.treesitter.get_parser(0, "c")
tree = parser:parse()
res = {}
for pattern, match in cquery:iter_matches(tree:root(), 0, 0, 1) do
-- can't transmit node over RPC. just check the name and range
local mrepr = {}
for cid,node in pairs(match) do
table.insert(mrepr, {cquery.captures[cid], node:type(), node:range()})
end
table.insert(res, {pattern, mrepr})
end
return res
]])
eq({
{ 1, { { "quote", '"', 0, 16, 0, 17 } } },
{ 2, { { "quote", '"', 0, 16, 0, 17 } } },
{ 1, { { "quote", '"', 0, 29, 0, 30 } } },
{ 2, { { "quote", '"', 0, 29, 0, 30 } } },
}, res)
end)
it('allows to add predicates', function()
insert([[
int main(void) {