all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Abin Simon <mail@meain.io>
To: Yuan Fu <casouri@gmail.com>
Cc: emacs-devel@gnu.org
Subject: Re: Question on getting tree-sitter matches
Date: Mon, 13 Mar 2023 08:59:32 +0530	[thread overview]
Message-ID: <877cvle3c3.fsf@meain.io> (raw)
In-Reply-To: <C096BA3A-17DD-4C42-A249-6B7C89B6B8FB@gmail.com>

> 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



  reply	other threads:[~2023-03-13  3:29 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-12 14:32 Question on getting tree-sitter matches Abin Simon
2023-03-13  2:34 ` Yuan Fu
2023-03-13  3:29   ` Abin Simon [this message]
2023-03-14 23:31     ` Yuan Fu
2023-03-15  4:24       ` Abin Simon
2023-03-19 21:59         ` Yuan Fu
2023-03-20  4:09           ` Abin Simon
2023-03-20 20:27           ` Ergus
2023-03-20 23:25             ` Yuan Fu
2023-03-21  3:29               ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=877cvle3c3.fsf@meain.io \
    --to=mail@meain.io \
    --cc=casouri@gmail.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.