GNU bug report logs - #72691
Recursive descent in treesiter parse tree

Previous Next

Package: emacs;

Reported by: Pranshu Sharma <pranshusharma198 <at> gmail.com>

Date: Sun, 18 Aug 2024 07:36:02 UTC

Severity: normal

Done: Eli Zaretskii <eliz <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 72691 in the body.
You can then email your comments to 72691 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#72691; Package emacs. (Sun, 18 Aug 2024 07:36:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Pranshu Sharma <pranshusharma198 <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sun, 18 Aug 2024 07:36:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Pranshu Sharma <pranshusharma198 <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: Recursive descent in treesiter parse tree
Date: Sun, 18 Aug 2024 14:57:10 +1000
[Message part 1 (text/plain, inline)]
Hello all,

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
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#72691; Package emacs. (Sun, 18 Aug 2024 09:26:02 GMT) Full text and rfc822 format available.

Message #8 received at 72691 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Pranshu Sharma <pranshusharma198 <at> gmail.com>,
 Yuan Fu <casouri <at> gmail.com>
Cc: 72691 <at> debbugs.gnu.org
Subject: Re: bug#72691: Recursive descent in treesiter parse tree
Date: Sun, 18 Aug 2024 12:24:26 +0300
> From: Pranshu Sharma <pranshusharma198 <at> 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
>         @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.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#72691; Package emacs. (Sun, 18 Aug 2024 15:34:02 GMT) Full text and rfc822 format available.

Message #11 received at 72691 <at> debbugs.gnu.org (full text, mbox):

From: Pranshu Sharma <pranshusharma198 <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: Yuan Fu <casouri <at> gmail.com>, 72691 <at> debbugs.gnu.org
Subject: Re: bug#72691: Recursive descent in treesiter parse tree
Date: Mon, 19 Aug 2024 00:57:54 +1000
[Message part 1 (text/plain, inline)]
Ok, I found the solution: you have to capture  witha function and traverse
the whole tree recursively

On Sun, 18 Aug 2024, 7:24 pm Eli Zaretskii, <eliz <at> gnu.org> wrote:

> > From: Pranshu Sharma <pranshusharma198 <at> 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
> >         @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.
>
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#72691; Package emacs. (Tue, 20 Aug 2024 03:41:02 GMT) Full text and rfc822 format available.

Message #14 received at 72691 <at> debbugs.gnu.org (full text, mbox):

From: Yuan Fu <casouri <at> gmail.com>
To: Pranshu Sharma <pranshusharma198 <at> gmail.com>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 72691 <at> debbugs.gnu.org
Subject: Re: bug#72691: Recursive descent in treesiter parse tree
Date: Mon, 19 Aug 2024 20:38:16 -0700

> On Aug 18, 2024, at 7:57 AM, Pranshu Sharma <pranshusharma198 <at> gmail.com> wrote:
> 
> Ok, I found the solution: you have to capture  witha function and traverse the whole tree recursively

As you’ve found out, tree-sitter’s query system doesn’t support the feature you want (it’ll be quite expensive to implement, I think). Even if you’ve found a solution, if you want, maybe you can describe your actual use-case and I can check if your solution is the most optimal.

Yuan

> 
> On Sun, 18 Aug 2024, 7:24 pm Eli Zaretskii, <eliz <at> gnu.org> wrote:
> > From: Pranshu Sharma <pranshusharma198 <at> 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
> >         @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.





Reply sent to Eli Zaretskii <eliz <at> gnu.org>:
You have taken responsibility. (Sat, 31 Aug 2024 08:14:01 GMT) Full text and rfc822 format available.

Notification sent to Pranshu Sharma <pranshusharma198 <at> gmail.com>:
bug acknowledged by developer. (Sat, 31 Aug 2024 08:14:02 GMT) Full text and rfc822 format available.

Message #19 received at 72691-done <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Yuan Fu <casouri <at> gmail.com>
Cc: pranshusharma198 <at> gmail.com, 72691-done <at> debbugs.gnu.org
Subject: Re: bug#72691: Recursive descent in treesiter parse tree
Date: Sat, 31 Aug 2024 11:12:23 +0300
> From: Yuan Fu <casouri <at> gmail.com>
> Date: Mon, 19 Aug 2024 20:38:16 -0700
> Cc: Eli Zaretskii <eliz <at> gnu.org>,
>  72691 <at> debbugs.gnu.org
> 
> 
> 
> > On Aug 18, 2024, at 7:57 AM, Pranshu Sharma <pranshusharma198 <at> gmail.com> wrote:
> > 
> > Ok, I found the solution: you have to capture  witha function and traverse the whole tree recursively
> 
> As you’ve found out, tree-sitter’s query system doesn’t support the feature you want (it’ll be quite expensive to implement, I think). Even if you’ve found a solution, if you want, maybe you can describe your actual use-case and I can check if your solution is the most optimal.

No further comments, so I'm now closing this bug.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sat, 28 Sep 2024 11:24:10 GMT) Full text and rfc822 format available.

This bug report was last modified 265 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.