From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Pranshu Sharma Newsgroups: gmane.emacs.bugs Subject: bug#72691: Recursive descent in treesiter parse tree Date: Mon, 19 Aug 2024 00:57:54 +1000 Message-ID: References: <86y14uyyid.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="00000000000062841b061ff66ba9" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="8746"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Yuan Fu , 72691@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Aug 18 17:33:42 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1sfhuX-000262-LG for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 18 Aug 2024 17:33:41 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sfhuH-0005Se-1X; Sun, 18 Aug 2024 11:33:25 -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 1sfhuE-0005SL-WB for bug-gnu-emacs@gnu.org; Sun, 18 Aug 2024 11:33:23 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sfhuE-0006Uf-BU for bug-gnu-emacs@gnu.org; Sun, 18 Aug 2024 11:33:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=Date:From:In-Reply-To:References:MIME-Version:To:Subject; bh=iNgg5CyFg7JF+vCdILvo68+eNL6eWTI4PBaAEl2O5YU=; b=L88PvuQscdtw7gqs1rmWIMbIR9odiRoHMVrSywLCKnR1lNVuUhd+NaI+NjNylylnJpIJvs6zA5Qr29gyn+F8FhzeYPHVWi2Ay9ABbpDENue7WLB3gO553bF4GGrW5ayf9BWjg5hmAlbnVwcjbKjx8Xl8j652Sv2l6jewZZfmNklkXYAWvVnw7TxLdPvIw0+efT3RY+eO+L40CIC4WZTZJlSdV1v0IYL55PGgfA/EMeN+wJt2HJbRJdaWiyqMNqr21VFTFiJLu3wJWdO1W5dJagewLnUKhnjwwwF9R0NkUQGXp7+c/X6GfWAMRC+enmfIOvGZ8A1GgsiHZE5jZZt0Kg==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sfhus-0001im-OK for bug-gnu-emacs@gnu.org; Sun, 18 Aug 2024 11:34:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Pranshu Sharma Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 18 Aug 2024 15:34:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 72691 X-GNU-PR-Package: emacs Original-Received: via spool by 72691-submit@debbugs.gnu.org id=B72691.17239952376592 (code B ref 72691); Sun, 18 Aug 2024 15:34:02 +0000 Original-Received: (at 72691) by debbugs.gnu.org; 18 Aug 2024 15:33:57 +0000 Original-Received: from localhost ([127.0.0.1]:56503 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sfhum-0001iE-Iq for submit@debbugs.gnu.org; Sun, 18 Aug 2024 11:33:57 -0400 Original-Received: from mail-oo1-f45.google.com ([209.85.161.45]:54720) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sfhNm-0000bU-OE for 72691@debbugs.gnu.org; Sun, 18 Aug 2024 10:59:51 -0400 Original-Received: by mail-oo1-f45.google.com with SMTP id 006d021491bc7-5d59e491fefso1817946eaf.1 for <72691@debbugs.gnu.org>; Sun, 18 Aug 2024 07:59:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723993084; x=1724597884; darn=debbugs.gnu.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=iNgg5CyFg7JF+vCdILvo68+eNL6eWTI4PBaAEl2O5YU=; b=iRX0HaEtQadTWXV2Uo7iaVDNCTSqsOHjRJ6CMfLAq0SSM6rt8Xm3bbaJLRxok+1AaG Bpt0oFiNTSDI+oZB5zwPfiHLv7wBOIub5cjWJngZNg/LN9b+F0OsKSUheeMc4+4tPkbq aiUgMKvPukN8+I1meRTi+79Alcwjy5l+qf4Z4KJ3wQ8XbiM+JtGZPOfhPspmjs1IQTYC E8MahZ05Pfz2G1vYuaj7G6Mks5IfX0jmdPzhHarqVgQP9WeGIunsPt8paBe4sF9GmvNW /Oprzc2zxRaB+h+0sdbS5hnoyvHvd7qjJBQbjANcpIIv6imCumRKIJLZ7XECVnc7Oi7y vKbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723993084; x=1724597884; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=iNgg5CyFg7JF+vCdILvo68+eNL6eWTI4PBaAEl2O5YU=; b=IbDD39asnSRk6+daTMwy8FXfuioQho1Q9OpTLdlTevfQjbnyXDuj95Mk9peTkbyO/n ot9wYRUtWsSX0o1CbScF+uVurhOZTF96BwmaaWIs7r4NxaP60wrpaoo10VuIz/2eHHu7 Ou/1NdCwArF80oSUKIdmBhhDuTG+iuG535hb3Rspj0xn2yWxflmz5MtIpxjSVfdnq+pV nDAhyEZYGN2FvVMqudtbuCJWgcH+kSDFtMVpyLnD3pMIlzrsATbwBL/3GeEdArWHSLWU v1lOgvfFmQiursFata1/W+HDnS+0Yp7iEp4SuZqUpfK3MtwVToUCeKEmIhixmy4TWWYu zWkw== X-Forwarded-Encrypted: i=1; AJvYcCVNFG4ZpNDdY1/0mtf3Yn0OVZKj5sOMHW7LTBqLrphOTLsKilzDbtqJYGmYxYtc4P6EYavQh6ws3pWJ/egIyyeTJ6S2Fyw= X-Gm-Message-State: AOJu0YwFhZRKxxnX1nv1iksXFTvW121ofMFZAucoMf7/77+CUmOWVQaR MM45rgHfYTZPj8PRDxv+8Yf2JAlS3gF9H2oT3FgdNsmF0NxzncsngiVDBoXOW4zJMBMtLxyWHAd 3xMSnsInnXaT8CyMExt7RE1GIDOo= X-Google-Smtp-Source: AGHT+IHTtdoUb6WiKzNSVjYX5jw7MdYpFDf/pZ+KKZvesvjRtlgWGxlTDLVLPFDYvhG6MubKa1dPGTqjhzFyJ9Oa6bs= X-Received: by 2002:a05:6358:431f:b0:1a2:598a:452e with SMTP id e5c5f4694b2df-1b393103546mr608161955d.1.1723993084295; Sun, 18 Aug 2024 07:58:04 -0700 (PDT) In-Reply-To: <86y14uyyid.fsf@gnu.org> X-Mailman-Approved-At: Sun, 18 Aug 2024 11:33:53 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:290328 Archived-At: --00000000000062841b061ff66ba9 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Ok, I found the solution: you have to capture witha function and traverse the whole tree recursively On Sun, 18 Aug 2024, 7:24=E2=80=AFpm Eli Zaretskii, wrote: > > From: Pranshu Sharma > > Date: Sun, 18 Aug 2024 14:57:10 +1000 > > > > I am trying to write a major mode in which all instances of a node in > another matched node. For this, recursion > > is needed, and for that it is necessary to store a match in a variable: > > Say I want to highlight all instances of (x) that are inside y in the > following parse tree, where bolded means I > > want to match: > > (x) in (q (y (x) (l (x) (l (x) (p))) (x)) > > > > "(y) @test > > @test . (_) @font-lock-variable-name-face" > > "(y) @test > > (@test . (_) @font-lock-variable-name-face)" > > "(y) @test > > (test . (_) @font-lock-variable-name-face)" > > > > All of the above fail, which leads me to think that @test stores the > text instead of the tree. In this case, how > > would I recursively match all instances of > > Adding Yuan. > --00000000000062841b061ff66ba9 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Ok, I found the solution: you have to capture=C2=A0 witha fu= nction and traverse the whole tree recursively


On Sun= , 18 Aug 2024, 7:24=E2=80=AFpm Eli Zaretskii, <eliz@gnu.org> wrote:
= > From: Pranshu Sharma <pranshusharma198@gmail.com> > Date: Sun, 18 Aug 2024 14:57:10 +1000
>
> I am trying to write a major mode in which all instances of a node in = another matched node. For this, recursion
> is needed, and for that it is necessary to store a match in a variable= :
> Say I want to highlight all instances of (x) that are inside y in the = following parse tree, where bolded means I
> want to match:
> (x) in (q (y (x) (l (x) (l (x) (p))) (x))
>
> "(y) @test
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0@test . (_) @font-lock-variable-name-= face"
> "(y) @test
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(@test . (_) @font-lock-variable-name= -face)"
> "(y) @test
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(test . (_) @font-lock-variable-name-= face)"
>
> All of the above fail, which leads me to think that @test stores the t= ext instead of the tree. In this case, how
> would I recursively match all instances of

Adding Yuan.
--00000000000062841b061ff66ba9--