From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?Q?Augustin_Ch=C3=A9neau_=28BTuin=29?= Newsgroups: gmane.emacs.devel Subject: Re: Questions about tree-sitter Date: Wed, 30 Aug 2023 13:28:38 +0200 Message-ID: <52f09345-85c8-4049-b12d-bf8b84b08f75@mailo.com> References: <12fe5895-7d34-4f3e-b1cf-aa133b718c24@mailo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="6363"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla Thunderbird Cc: emacs-devel@gnu.org To: Yuan Fu Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Aug 30 13:29:16 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 1qbJNs-0001QL-5N for ged-emacs-devel@m.gmane-mx.org; Wed, 30 Aug 2023 13:29:16 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qbJNP-0000n4-AC; Wed, 30 Aug 2023 07:28:47 -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 1qbJNN-0000lG-Hy for emacs-devel@gnu.org; Wed, 30 Aug 2023 07:28:45 -0400 Original-Received: from msg-2.mailo.com ([213.182.54.12]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qbJNK-0007lI-DV for emacs-devel@gnu.org; Wed, 30 Aug 2023 07:28:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailo.com; s=mailo; t=1693394919; bh=QKwaLWkcJOK583aQN9ucqCqGe1mYFbH80mreEy+EZss=; h=X-EA-Auth:Message-ID:Date:MIME-Version:Subject:To:Cc:References: From:In-Reply-To:Content-Type:Content-Transfer-Encoding; b=GzHuVdTsxsrg6bpVPiQfuvRPCiveHQNyarm4cb+Wc8psVf4Qo2gUpRCL6Fkx1Yi30 T66kquRIGK5+4cyjuJ3EHUIKtMQlC4LAfhjuV7bKuRvHBHZheHWVpONI+JZGRyKeDF YPwFAHIWJRoewblPY1sHV/M2/s9U6hEJmiHYuu9U= Original-Received: by b221-5.in.mailobj.net [192.168.90.25] with ESMTP via ip-20.mailobj.net [213.182.54.20] Wed, 30 Aug 2023 13:28:39 +0200 (CEST) X-EA-Auth: HxRBYJYuNwoUAnfWhKocEUNg+OZrLHkQRo1nzA6+YMJ2huLBc46p5KW+Q3o9dj378tFqdd4gUguzxUuY6bG3CWBDspaUJ0RZ Content-Language: fr, en-US In-Reply-To: Received-SPF: pass client-ip=213.182.54.12; envelope-from=btuin@mailo.com; helo=msg-2.mailo.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, 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:309542 Archived-At: Le 30/08/2023 à 09:03, Yuan Fu a écrit : > > >> On Aug 29, 2023, at 2:26 PM, Augustin Chéneau (BTuin) wrote: >> >> Hello, >> >> I have a few questions about tree-sitter. >> >> I'm currently developing a grammar for GNU Bison alongside a tree-sitter >> major mode, it's a work in progress. The grammar is here: >> , still incomplete but so >> far able to parse simple files, and the major mode prototype is >> attached to this message. >> >> So, the questions: >> >> 1. Is there a way to reload a grammar? >> >> Emacs is pretty nice as a playground for testing grammars, but once a >> grammar is loaded, it won't be loaded again until Emacs restarts (as far >> as I know). >> Is it possible to reload a grammar after modifying it? > > No, and it’s probably not easy to implement either, since unloading the grammar would require Emacs to purge/invalid all the node/query/parsers using that grammar. > >> 2. How to mix multiple languages? >> >> It would be very useful for Bison since its mixed with C or other languages. >> According to the documentation I need to use the function >> `treesit-range-rules` to set the variable `treesit-range-settings`, but >> it seems to have no effect. The language in the selected nodes doesn't >> change (as attested by `(treesit-language-at (point))`). >> >> I did it that way (extracted from the attachment): >> >> (setq-local treesit-range-settings >> (treesit-range-rules >> :embed 'c >> :host 'bison >> '((undelimited_code_block) @capture))) >> >> Am I missing something? > > The ranges are set correctly, actually. But the C parse sees all those blocks stitched together as a whole, rather than individual blocks, and the code it sees is obviously not syntactically correct. > > We should really work on supporting isolated ranges, there has been multiple requests for it. I’ll try to work on that. > >> 3. Is it possible to trigger a hook when a node is modified? >> >> Since Bison supports multiple languages (C, C++, Java and D), I'd like >> to watch the declaration "%language LANGUAGE" to change the embedded >> language when needed. >> Is there a way to do that? > > treesit-parser-add-notifier might be what you want. > > Yuan > I see. Thank you for your answers and for your great work on tree-sitter!