From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stephen Leake Newsgroups: gmane.emacs.devel Subject: Re: [SPAM UNSURE] Tree-sitter api Date: Mon, 30 Aug 2021 17:48:35 -0700 Message-ID: <864kb630d8.fsf@stephe-leake.org> References: <83r1f7hydn.fsf@gnu.org> <95F37923-5BF9-4D81-B361-267CF119FBCA@gmail.com> <735AF34C-FD18-4A6A-A99D-E5D8EB4DE4F3@gmail.com> <86im02bobr.fsf@stephe-leake.org> <8B9072FF-02F5-48CC-844A-1E0C2FC42CE9@gmail.com> <86bl5m51oi.fsf@stephe-leake.org> <3A182DFA-0CCA-4F2A-AE55-E829E76D717F@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="1309"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (windows-nt) Cc: Eli Zaretskii , Theodor Thornhill , Stefan Monnier , =?utf-8?Q?Cl?= =?utf-8?Q?=C3=A9ment?= Pit-Claudel , emacs-devel To: Yuan Fu Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Aug 31 02:51:09 2021 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 1mKrzY-0000BN-9S for ged-emacs-devel@m.gmane-mx.org; Tue, 31 Aug 2021 02:51:08 +0200 Original-Received: from localhost ([::1]:58616 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mKrzW-000522-Mk for ged-emacs-devel@m.gmane-mx.org; Mon, 30 Aug 2021 20:51:06 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:58532) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mKrxI-0003UW-Fy for emacs-devel@gnu.org; Mon, 30 Aug 2021 20:48:51 -0400 Original-Received: from gateway24.websitewelcome.com ([192.185.51.122]:40375) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mKrxE-0006zF-KH for emacs-devel@gnu.org; Mon, 30 Aug 2021 20:48:47 -0400 Original-Received: from cm14.websitewelcome.com (cm14.websitewelcome.com [100.42.49.7]) by gateway24.websitewelcome.com (Postfix) with ESMTP id 4CE957FB7 for ; Mon, 30 Aug 2021 19:48:39 -0500 (CDT) Original-Received: from host2007.hostmonster.com ([67.20.76.71]) by cmsmtp with SMTP id Krx8mDIVO7sOiKrx9mjcUo; Mon, 30 Aug 2021 19:48:39 -0500 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=stephe-leake.org; s=default; h=Content-Transfer-Encoding:Content-Type: MIME-Version:Message-ID:In-Reply-To:Date:References:Subject:Cc:To:From:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=25RGIxf6abtGyV1EU14YvGq1sDYM81okWTmBjeu5NJA=; b=G4bWjrKA19lusqJ4aK0GcASZGW OohJyOljhGJjv10FCwvS0yIiY5wJPy5VYp3D11QBHBQuMEzX0YqSRKmW6LhqDzSV4C0aKLHm5AsX3 VR75vAHtcbokk1HWrUNlss1u4F2FT38WHqfv3cA7SosIJCA3fyVEzq84PAx7InkDQMaoxhIFqVpbg Ew3ciPzQk810wjpUHcZDtufD772vL9hJnHUweDIcSgP6SkDJ+KAO0jjX9wgGEV/xh+n28S++XuCeW y15RU8PhSPl3sUdVUvQAyqjKLLoBMNo8Zi7uETK/xxmB5Lqt1kK5jZpNzhQXQ9KpZThnoqe7B8dJw YnMTdQTg==; Original-Received: from [76.77.182.20] (port=62662 helo=Takver4) by host2007.hostmonster.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1mKrx8-002BT9-ER; Mon, 30 Aug 2021 18:48:38 -0600 In-Reply-To: <3A182DFA-0CCA-4F2A-AE55-E829E76D717F@gmail.com> (Yuan Fu's message of "Thu, 26 Aug 2021 22:18:08 -0700") X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - host2007.hostmonster.com X-AntiAbuse: Original Domain - gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - stephe-leake.org X-BWhitelist: no X-Source-IP: 76.77.182.20 X-Source-L: No X-Exim-ID: 1mKrx8-002BT9-ER X-Source-Sender: (Takver4) [76.77.182.20]:62662 X-Source-Auth: stephen_leake@stephe-leake.org X-Email-Count: 7 X-Source-Cap: c3RlcGhlbGU7c3RlcGhlbGU7aG9zdDIwMDcuaG9zdG1vbnN0ZXIuY29t X-Local-Domain: yes Received-SPF: permerror client-ip=192.185.51.122; envelope-from=stephen_leake@stephe-leake.org; helo=gateway24.websitewelcome.com X-Spam_score_int: -8 X-Spam_score: -0.9 X-Spam_bar: / X-Spam_report: (-0.9 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_NEUTRAL=0.779 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 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" Xref: news.gmane.io gmane.emacs.devel:273561 Archived-At: Yuan Fu writes: > Thank you very much for spending time on this :-) And thank you for the same; always helpful to have different points of view. >> The indent of every new-line must be specified; low level productions >> can contain new-lines. > > Ah, I see, what I did is to find the =E2=80=9Clargest=E2=80=9D node that = starts at > BOL, and try to match that. IIUC, wisi starts from the =E2=80=9Csmallest= =E2=80=9D > entity, and goes up (by getting its parent repeatedly) until there is > a non-nil indent rule for it? That's almost right. The indent rule for each production is applied while walking the entire syntax tree in depth-first order. >> To be fair, we'd have to look at the other types of rules, to see if >> this pattern holds up. > > I tried and all rules can be translated into wisi=E2=80=99s style.=20 Ok. > However, it ends up as verbose as the previous one. My idea is to > write out match patterns (similar to that in wisi) and give names to > the interesting ones (so we use names as opposed to position). Then, > if any matched node happens to be the node at point, use that node=E2=80= =99s > corresponding indent rule to indent. And in the indent rule, we can > refer to other matched nodes. For example, in the indent rule of > list_rest, the anchor is list_first. > > Maybe there are better ways to implement this, but at its current > stage I don=E2=80=99t think this is better than tree-sitter-simple-indent. Ok. > I think part of the reason why wisi=E2=80=99s indent rule can be succinct= is > that it is written along the grammar definition. It is hard to make > tree-sitter=E2=80=99s indent rule as succinct while being easy to underst= and. Right. > IIUC, this tree-traversal method that you mentioned is like going > bottom-up, and (in tree-sitter terms) match on each level, and > accumulate indent delta for each matched indent rule, is that right? Yes. > Does wisi go all the way up to top-level? Yes; the top-level rule says the indent of every line defaults to 0; that covers any remaining 'nil' values. I have not tried to make this part of ada-mode incremental yet (ie, only visit changed nodes). I'm not sure that's possible. --=20 -- Stephe