all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#72691: Recursive descent in treesiter parse tree
@ 2024-08-18  4:57 Pranshu Sharma
  2024-08-18  9:24 ` Eli Zaretskii
  0 siblings, 1 reply; 5+ messages in thread
From: Pranshu Sharma @ 2024-08-18  4:57 UTC (permalink / raw)
  To: 72691

[-- Attachment #1: Type: text/plain, Size: 719 bytes --]

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

[-- Attachment #2: Type: text/html, Size: 932 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#72691: Recursive descent in treesiter parse tree
  2024-08-18  4:57 bug#72691: Recursive descent in treesiter parse tree Pranshu Sharma
@ 2024-08-18  9:24 ` Eli Zaretskii
  2024-08-18 14:57   ` Pranshu Sharma
  0 siblings, 1 reply; 5+ messages in thread
From: Eli Zaretskii @ 2024-08-18  9:24 UTC (permalink / raw)
  To: Pranshu Sharma, Yuan Fu; +Cc: 72691

> 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
>         @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.





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#72691: Recursive descent in treesiter parse tree
  2024-08-18  9:24 ` Eli Zaretskii
@ 2024-08-18 14:57   ` Pranshu Sharma
  2024-08-20  3:38     ` Yuan Fu
  0 siblings, 1 reply; 5+ messages in thread
From: Pranshu Sharma @ 2024-08-18 14:57 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Yuan Fu, 72691

[-- Attachment #1: Type: text/plain, Size: 1085 bytes --]

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@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
> >         @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.
>

[-- Attachment #2: Type: text/html, Size: 1551 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#72691: Recursive descent in treesiter parse tree
  2024-08-18 14:57   ` Pranshu Sharma
@ 2024-08-20  3:38     ` Yuan Fu
  2024-08-31  8:12       ` Eli Zaretskii
  0 siblings, 1 reply; 5+ messages in thread
From: Yuan Fu @ 2024-08-20  3:38 UTC (permalink / raw)
  To: Pranshu Sharma; +Cc: Eli Zaretskii, 72691



> On Aug 18, 2024, at 7:57 AM, Pranshu Sharma <pranshusharma198@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@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
> >         @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.






^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#72691: Recursive descent in treesiter parse tree
  2024-08-20  3:38     ` Yuan Fu
@ 2024-08-31  8:12       ` Eli Zaretskii
  0 siblings, 0 replies; 5+ messages in thread
From: Eli Zaretskii @ 2024-08-31  8:12 UTC (permalink / raw)
  To: Yuan Fu; +Cc: pranshusharma198, 72691-done

> From: Yuan Fu <casouri@gmail.com>
> Date: Mon, 19 Aug 2024 20:38:16 -0700
> Cc: Eli Zaretskii <eliz@gnu.org>,
>  72691@debbugs.gnu.org
> 
> 
> 
> > On Aug 18, 2024, at 7:57 AM, Pranshu Sharma <pranshusharma198@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.





^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-08-31  8:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-18  4:57 bug#72691: Recursive descent in treesiter parse tree Pranshu Sharma
2024-08-18  9:24 ` Eli Zaretskii
2024-08-18 14:57   ` Pranshu Sharma
2024-08-20  3:38     ` Yuan Fu
2024-08-31  8:12       ` Eli Zaretskii

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.