From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Yuan Fu Newsgroups: gmane.emacs.devel Subject: Re: Question on getting tree-sitter matches Date: Tue, 14 Mar 2023 16:31:19 -0700 Message-ID: References: <87cz5ekpl9.fsf@meain.io> <877cvle3c3.fsf@meain.io> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.400.51.1.1\)) 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="6869"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Abin Simon Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Mar 15 00:32:41 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 1pcE8F-0001bR-6d for ged-emacs-devel@m.gmane-mx.org; Wed, 15 Mar 2023 00:32:39 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pcE7Q-0001oY-NW; Tue, 14 Mar 2023 19:31:48 -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 1pcE7J-0001kk-Qz for emacs-devel@gnu.org; Tue, 14 Mar 2023 19:31:41 -0400 Original-Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pcE7F-0001aN-Ry for emacs-devel@gnu.org; Tue, 14 Mar 2023 19:31:39 -0400 Original-Received: by mail-pj1-x102d.google.com with SMTP id f6-20020a17090ac28600b0023b9bf9eb63so73488pjt.5 for ; Tue, 14 Mar 2023 16:31:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678836692; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=UBhS7OtcG7RoUSSCtv63rakn0Z5en7oPztKi0UaL1nE=; b=fROYY5D/5uj1ck0G3QzdQM5ScMwSMShuUgZdCiAbKduhfxwoRk6OA55ylLgwl5YLdl 21POfdp1UWfkAO3jAAg5HlyKSRfAlnZ+zn8d7oxZXfUNiI7cHxwjvFBW+WRxfrfMRnKe qCXoPWZjrrPEIWy5DF3nCAonN6jfbGNdyu7QDYBesWFweq9AlXEtqXjOqVYqkwF8uvJ+ Mln0W5s3h7mf8g6/cS3KChRqRSQP2cvWIEgSArerl5dK3PJvJJ87wF9hEoSp1fK+wxiq rP1mH1kZ8LODAnYAY4fIoqpY3tmqgHxKTWdFe6m8jyxH8AMYnOFDpNQpoD/DdwhdDJqs /CNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678836692; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UBhS7OtcG7RoUSSCtv63rakn0Z5en7oPztKi0UaL1nE=; b=QwXKegr28HAQtp3c2KokkdOP8lmForZOTLVnJZ+hhZHghqFnHh4N14VZcxtAoR2MXv QhEUGWxVq+98xYAkXcDzYcvhML9y2s4I/lMxNPRS87wwrQVla3Rf5QDBBsZPJ7xNiSFe AztLd38gmum1CwyiI3eSV112+OYp1fhS7rlWqx8DQEuhxLkuHt4w4eTavBXqSUBXd/yV oJFgUL/53A3tnluWncWhx57NB6/XRyiizuu0DZktGpE7qBMvx1D6l8kpvPIVvlm5GCq9 LsfbygXzntOmT4m/ysdX/Nidis5KmeV8JzT2bcqwDCSTRTh/GAZWLtwuuoYUQSMUfIVg 4Ugg== X-Gm-Message-State: AO0yUKU1KMHhDqHOGi5QIn4LzUd6im+xQpM9s7fDkuy6S/z5L4r8t4/W L3KkmU9oLnelzV9sZhgf7Og= X-Google-Smtp-Source: AK7set/xdAk92mgojaqgkqfkjDzwGB4GZzPtJgtE6KpoapwCPUKwPqC7b2DnSJkgjZX1vFdHvjZtkQ== X-Received: by 2002:a17:90a:19d0:b0:23e:f856:147b with SMTP id 16-20020a17090a19d000b0023ef856147bmr129969pjj.11.1678836691520; Tue, 14 Mar 2023 16:31:31 -0700 (PDT) Original-Received: from smtpclient.apple (cpe-172-117-161-177.socal.res.rr.com. [172.117.161.177]) by smtp.gmail.com with ESMTPSA id lg11-20020a170902fb8b00b0019f1205bdcbsm2264671plb.147.2023.03.14.16.31.30 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 Mar 2023 16:31:31 -0700 (PDT) In-Reply-To: <877cvle3c3.fsf@meain.io> X-Mailer: Apple Mail (2.3731.400.51.1.1) Received-SPF: pass client-ip=2607:f8b0:4864:20::102d; envelope-from=casouri@gmail.com; helo=mail-pj1-x102d.google.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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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:304464 Archived-At: > On Mar 12, 2023, at 8:29 PM, Abin Simon wrote: >=20 >> Unfortunately, that=E2=80=99s currently not possible. Could you = elaborate on why you need such feature? >=20 > This came up when working with = https://github.com/meain/evil-textobj-tree-sitter. >=20 > 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. >=20 > You can find an example at > = https://github.com/nvim-treesitter/nvim-treesitter-textobjects/blob/5b2bcb= 9ca8315879181f468b37a897100d631005/queries/perl/textobjects.scm#L5 >=20 > ((patter_matcher_m > (start_delimiter) @_start > (end_delimiter) @_end) @regex.outer > (#make-range! "regex.inner" @_start @_end)) >=20 > 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: >=20 > = https://github.com/meain/evil-textobj-tree-sitter/blob/66819ee8547e439f003= fcb0e1647acade194bd1a/queries/perl/textobjects.scm#LL5-L8C3 >=20 > ((patter_matcher_m > (start_delimiter) @regex.inner._start > (end_delimiter) @regex.inner._end) @regex.outer > ) >=20 > 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). >=20 > You can find the relevant part of the code from the plugin here: >=20 > = https://github.com/meain/evil-textobj-tree-sitter/blob/66819ee8547e439f003= fcb0e1647acade194bd1a/evil-textobj-tree-sitter-core.el#L157 I see. We can add an optional argument to treesit-query-capture to = toggle the =E2=80=9Cgrouping=E2=80=9D of matches, WDYT? Yuan=