From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Abin Simon Newsgroups: gmane.emacs.devel Subject: Re: Question on getting tree-sitter matches Date: Mon, 13 Mar 2023 08:59:32 +0530 Message-ID: <877cvle3c3.fsf@meain.io> References: <87cz5ekpl9.fsf@meain.io> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="30976"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Yuan Fu Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Mar 13 12:38:03 2023 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pbgV9-0007tM-9y for ged-emacs-devel@m.gmane-mx.org; Mon, 13 Mar 2023 12:38:03 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pbgUb-00008Q-IE; Mon, 13 Mar 2023 07:37:29 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pbYsb-0003I4-8p for emacs-devel@gnu.org; Sun, 12 Mar 2023 23:29:45 -0400 Original-Received: from sender4-op-o12.zoho.com ([136.143.188.12]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pbYsZ-00013x-20 for emacs-devel@gnu.org; Sun, 12 Mar 2023 23:29:44 -0400 ARC-Seal: i=1; a=rsa-sha256; t=1678678179; cv=none; d=zohomail.com; s=zohoarc; b=gvmxDgtsTOrcySofmkM7Qt4kSnrfurSKVNN0RrtzlK3Q/xCRbQ7OlMpKj3z48ABGttyM99pbcxPvFBhrUrdNmdIaO/vCkVur5kee6KIMxvTok0Pf87c7neVG+DMSOxU3/BLMbGM9bc3CviAxgs4JcxdiMRvplj8Z1OjV6k/ACa0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1678678179; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=4CGPfgYyD850FW+GTVvqX5pDDbcISrqlKdViMml99Hs=; b=bmSMIaKRHY/Mf30hltnZPA6lJWode49vjf0esiclAm0Dn1KCm0ZgmoU6VVoTZsoP7Zw6C/bcbx/h15mVDorpN3iXu6Rs4OuFmGh4BXu8+9lykgx6VSB4bw17NaYgbkE1vHTq/gPLfrkcS13qR67mSIZ6KwCQMsL3vTxOjRRa3P4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=meain.io; spf=pass smtp.mailfrom=mail@meain.io; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1678678179; s=zmail; d=meain.io; i=mail@meain.io; h=From:From:To:To:Cc:Cc:Subject:Subject:In-Reply-To:References:Date:Date:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Reply-To; bh=4CGPfgYyD850FW+GTVvqX5pDDbcISrqlKdViMml99Hs=; b=WqbRfjWmmv2iHH/rzpTSaNagFPIDAw6WC3AwChOMNZOlMATN8RUnr9n/9GjXvpVO qGVoZ2u9/ids5exSAvhUegGoDPCRkTyEYSeh33g3zULsMKKKwmqP+h5PlgMixqNWPaP J9dWmEMUR49LPMYPvLDWq1LESt++jHrdRRxFomIk= Original-Received: from localhost (103.85.206.21 [103.85.206.21]) by mx.zohomail.com with SMTPS id 1678678178170250.32392601280208; Sun, 12 Mar 2023 20:29:38 -0700 (PDT) In-Reply-To: X-ZohoMailClient: External Received-SPF: pass client-ip=136.143.188.12; envelope-from=mail@meain.io; helo=sender4-op-o12.zoho.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Mon, 13 Mar 2023 07:37:26 -0400 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:304389 Archived-At: > Unfortunately, that=E2=80=99s 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-s= itter. 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/5b2bcb9= ca8315879181f468b37a897100d631005/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/66819ee8547e439f003f= cb0e1647acade194bd1a/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/66819ee8547e439f003f= cb0e1647acade194bd1a/evil-textobj-tree-sitter-core.el#L157