[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Question on getting tree-sitter matches
From: |
Abin Simon |
Subject: |
Re: Question on getting tree-sitter matches |
Date: |
Mon, 13 Mar 2023 08:59:32 +0530 |
> Unfortunately, that’s currently not possible. Could you elaborate on why you
> need such feature?
This came up when working with
https://github.com/meain/evil-textobj-tree-sitter.
In this repo, I pull queries from Neovim repo which dos similar things,
https://github.com/nvim-treesitter/nvim-treesitter-textobjects. They
have custom predicates added and one of them is `#make-range!` which is
used to combine two captures together to form a new capture.
You can find an example at
https://github.com/nvim-treesitter/nvim-treesitter-textobjects/blob/5b2bcb9ca8315879181f468b37a897100d631005/queries/perl/textobjects.scm#L5
((patter_matcher_m
(start_delimiter) @_start
(end_delimiter) @_end) @regex.outer
(#make-range! "regex.inner" @_start @_end))
In here, they use `#make-range!` to form a `regex.inner` predicate by
combining `@_start` and `@_end` markers' ranges. Since we do not have
support for this predicate, I was working around this by converting the
query into the following:
https://github.com/meain/evil-textobj-tree-sitter/blob/66819ee8547e439f003fcb0e1647acade194bd1a/queries/perl/textobjects.scm#LL5-L8C3
((patter_matcher_m
(start_delimiter) @regex.inner._start
(end_delimiter) @regex.inner._end) @regex.outer
)
Once we have this, we use `regex.inner._start` and `regex.inner._end` to
do something similar (but we need to be able to restrict the search to a
single match group).
You can find the relevant part of the code from the plugin here:
https://github.com/meain/evil-textobj-tree-sitter/blob/66819ee8547e439f003fcb0e1647acade194bd1a/evil-textobj-tree-sitter-core.el#L157
- Question on getting tree-sitter matches, Abin Simon, 2023/03/12
- Re: Question on getting tree-sitter matches, Yuan Fu, 2023/03/12
- Re: Question on getting tree-sitter matches,
Abin Simon <=
- Re: Question on getting tree-sitter matches, Yuan Fu, 2023/03/14
- Re: Question on getting tree-sitter matches, Abin Simon, 2023/03/15
- Re: Question on getting tree-sitter matches, Yuan Fu, 2023/03/19
- Re: Question on getting tree-sitter matches, Abin Simon, 2023/03/20
- Re: Question on getting tree-sitter matches, Ergus, 2023/03/20
- Re: Question on getting tree-sitter matches, Yuan Fu, 2023/03/20
- Re: Question on getting tree-sitter matches, Eli Zaretskii, 2023/03/20