emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Update on tree-sitter structure navigation


From: Yuan Fu
Subject: Re: Update on tree-sitter structure navigation
Date: Fri, 8 Sep 2023 09:46:32 -0700


> On Sep 8, 2023, at 2:09 AM, Ihor Radchenko <yantar92@posteo.net> wrote:
> 
> Yuan Fu <casouri@gmail.com> writes:
> 
>>>> Ideally I’d like to pass a query and a node to treesit-node-match-p, which 
>>>> returns t if the query matches the node. But queries don’t work like that. 
>>>> They search the node and returns all the matches within that node, which 
>>>> could be potentially wasteful.
>>> 
>>> Isn't ts_query_cursor_next_match only searching a single match?
>> 
>> Seems so, that’s good. But there’s no guarantee that the first match with be 
>> the top node, even thought implementation-wise, I think that’s probably the 
>> case. Maybe we can ask tree-sitter developer to add such a promise.
> 
> I have found several potentially useful things in the ABI
> https://github.com/tree-sitter/tree-sitter/blob/524bf7e2c664d4a5dbd0c20d4d10f1e58f99e8ce/lib/include/tree_sitter/api.h
> 
> /**
> * Set the maximum start depth for a query cursor.
> *
> * This prevents cursors from exploring children nodes at a certain depth.
> * Note if a pattern includes many children, then they will still be checked.
> *
> * The zero max start depth value can be used as a special behavior and
> * it helps to destructure a subtree by staying on a node and using captures
> * for interested parts. Note that the zero max start depth only limit a search
> * depth for a pattern's root node but other nodes that are parts of the 
> pattern
> * may be searched at any depth what defined by the pattern structure.
> *
> * Set to `UINT32_MAX` to remove the maximum start depth.
> */
> void ts_query_cursor_set_max_start_depth(TSQueryCursor *self, uint32_t 
> max_start_depth);
> 
> /**
> * Set the range of bytes or (row, column) positions in which the query
> * will be executed.
> */
> void ts_query_cursor_set_byte_range(TSQueryCursor *self, uint32_t start_byte, 
> uint32_t end_byte);
> void ts_query_cursor_set_point_range(TSQueryCursor *self, TSPoint 
> start_point, TSPoint end_point);

That’s great. Seems like a new addition to the API. That solves every problem I 
had!

Yuan


reply via email to

[Prev in Thread] Current Thread [Next in Thread]