Skip to content

Getting matched Node (without captures) from queries #898

Answered by maxbrunsfeld
osa1 asked this question in Q&A
Discussion options

You must be logged in to vote

There isn't always one root node to a pattern; you can write a pattern like this:

(
  (comment)+
  (function_definition)
)

One idea is to add some dummy capture for every query string

I think that in most cases this will work. Even if the user writes a top-level capture, it is still valid to have multiple captures like

(return_statement) @foo @bar

There will just be two named captures for the same node.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by osa1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants