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: Ihor Radchenko
Subject: Re: Update on tree-sitter structure navigation
Date: Fri, 08 Sep 2023 09:09:34 +0000

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);

>> Then, I can see cases when we do and also when we do _not_ want separate
>> parsers for different blocks. For example, literate programming often
>> uses other language blocks that are intended to be continuous.
>
> Surprise, I added support for local parsers. Major mode authors can choose 
> between global and local parsers.

Thanks!

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>



reply via email to

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