From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Ihor Radchenko Newsgroups: gmane.emacs.devel Subject: Re: Update on tree-sitter structure navigation Date: Fri, 08 Sep 2023 09:09:34 +0000 Message-ID: <878r9h9gkx.fsf@localhost> References: <5E7F2A94-4377-45C0-8541-7F59F3B54BA1@gmail.com> <87h6odhxs6.fsf@localhost> <87msxzsee1.fsf@localhost> <8A2B8A2E-FC24-401B-ACF8-688F2B157FB6@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="9125"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel , Danny Freeman , Theodor Thornhill , Jostein =?utf-8?Q?Kj=C3=B8nigsen?= , Randy Taylor , Wilhelm Kirschbaum , Perry Smith , Dmitry Gutov To: Yuan Fu Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Sep 08 11:09:45 2023 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qeXUm-0002Bf-Uw for ged-emacs-devel@m.gmane-mx.org; Fri, 08 Sep 2023 11:09:45 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qeXTo-0000lF-4x; Fri, 08 Sep 2023 05:08:44 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qeXTn-0000l5-2I for emacs-devel@gnu.org; Fri, 08 Sep 2023 05:08:43 -0400 Original-Received: from mout01.posteo.de ([185.67.36.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qeXTk-00085X-0y for emacs-devel@gnu.org; Fri, 08 Sep 2023 05:08:42 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 4F07B240028 for ; Fri, 8 Sep 2023 11:08:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1694164117; bh=lUIw6zCcNPzaNvXQubbe9Vg1dpeJpGhmqxJZOSu/1Us=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version: Content-Transfer-Encoding:From; b=PdhJh+Zvuu2Be3Xy+wjuOB3MhagvLf1Ic/pdO1WFZocdcTrp6mrBDeEpPF8OtB4bM Y7s4EGNlj7SdZpOi8GqAekMammWSTCv2eEfBbM1VK/YrCjyzhEARkbYOQ5n+xM3a9Z fPVtpc7QpqjnD40rqShndxoHD/NOZHagQsJEo5feki+lNsL5CuiaJJ5z2T9HGWeSrk pdLuRTFnKZal9P7SnbkoFooQl5iYxfbB+q6zPb6AzeepEcnZBIOj6bwAa3MTpSDjr8 RQKyXu49IfusVv2nchpmDiw27/Imnp2xVWldpDWrxYeOxZZWfUKzxDJVPBzUaeVdC5 tWmyigz5anOdQ== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4Rhqz759zzz9rxM; Fri, 8 Sep 2023 11:08:35 +0200 (CEST) In-Reply-To: <8A2B8A2E-FC24-401B-ACF8-688F2B157FB6@gmail.com> Received-SPF: pass client-ip=185.67.36.65; envelope-from=yantar92@posteo.net; helo=mout01.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:310315 Archived-At: Yuan Fu writes: >>> Ideally I=E2=80=99d like to pass a query and a node to treesit-node-mat= ch-p, which returns t if the query matches the node. But queries don=E2=80= =99t work like that. They search the node and returns all the matches withi= n that node, which could be potentially wasteful. >>=20 >> Isn't ts_query_cursor_next_match only searching a single match? > > Seems so, that=E2=80=99s good. But there=E2=80=99s no guarantee that the = first match with be the top node, even thought implementation-wise, I think= that=E2=80=99s probably the case. Maybe we can ask tree-sitter developer t= o add such a promise. I have found several potentially useful things in the ABI https://github.com/tree-sitter/tree-sitter/blob/524bf7e2c664d4a5dbd0c20d4d1= 0f1e58f99e8ce/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 checke= d. * * 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 se= arch * depth for a pattern's root node but other nodes that are parts of the pa= ttern * 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_byt= e, uint32_t end_byte); void ts_query_cursor_set_point_range(TSQueryCursor *self, TSPoint start_poi= nt, 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 choos= e between global and local parsers. Thanks! --=20 Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at