emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Question on getting tree-sitter matches


From: Yuan Fu
Subject: Re: Question on getting tree-sitter matches
Date: Tue, 14 Mar 2023 16:31:19 -0700


> On Mar 12, 2023, at 8:29 PM, Abin Simon <mail@meain.io> wrote:
> 
>> 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

I see. We can add an optional argument to treesit-query-capture to toggle the 
“grouping” of matches, WDYT?

Yuan


reply via email to

[Prev in Thread] Current Thread [Next in Thread]