From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Yuan Fu Newsgroups: gmane.emacs.devel Subject: Re: Questions about tree-sitter Date: Wed, 30 Aug 2023 00:03:03 -0700 Message-ID: References: <12fe5895-7d34-4f3e-b1cf-aa133b718c24@mailo.com> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.600.7\)) 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="40342"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: =?utf-8?B?IkF1Z3VzdGluIENow6luZWF1IChCVHVpbiki?= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Aug 30 09:04:18 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 1qbFFS-000AFy-1p for ged-emacs-devel@m.gmane-mx.org; Wed, 30 Aug 2023 09:04:18 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qbFEX-0007mB-KF; Wed, 30 Aug 2023 03:03:21 -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 1qbFEW-0007m2-28 for emacs-devel@gnu.org; Wed, 30 Aug 2023 03:03:20 -0400 Original-Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qbFET-0003k4-D7 for emacs-devel@gnu.org; Wed, 30 Aug 2023 03:03:19 -0400 Original-Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-68a3082c771so418886b3a.0 for ; Wed, 30 Aug 2023 00:03:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1693378995; x=1693983795; darn=gnu.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=j/cHKGegijaUVYgtWou8naOn28MDfkMq47qZojQueVs=; b=MkdrLPlUUOVZFL6l86U2X7cxTFqjZWV7z7fmI6QG75/4peVJnKpGJsoDFFV+n1f20j 2O5Bl6JNyqG2Jb8gAY3RgDFZjqEX0EcEMr0F3XKkgpO+ID/7JdUdL3Y7HHhgu3LKmQXK 6jsFe3mAlqp1MJkzckIOVJKDo4DphqK6i/h+aiQLlmyrryCnx7BYbA4nTm7R9soUKM0H xST1v9LEnCqyERbx3oLYAy5QmgqbSd4XGTi8XncTGychrD4SN1NhdxsV+vrXoyKxtVY2 g2Uh5Ra+lLKR9nQoGx/WI4IxFalv1RwzAec0NR04w4K+kjd+anUN2Z1cb5u0WPComsak mj3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693378995; x=1693983795; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=j/cHKGegijaUVYgtWou8naOn28MDfkMq47qZojQueVs=; b=at5qO7iuH8rlHA/jOOo3VtTuofpln7h9KQW6/TWM9ierV9CyYxw0fAbOc/MEStwLiB SMB8pgdRZnGOFhFSVNNummFSxXMMuEJWRGyDyvCXEUxvq9h/hmhWFVsF/7vZBlsNN7X5 5+JKmYIJ0oUr4RBaqPmkkoKFcMXNQ9ySBTrl/jmpbybrEER3A34UoBqoJ1BrRnEBnfpN gbuWBl299Boq3+JwbdVoVxd8mNbohnpIH+3Lem/xf6iV+rFguO846dk/JSHPuDb0ro2f IKsN+mqUOtcYpN2uPCwpoVLvIEd18ammcLUb4m0xD8Uc2wg90TzF88mwlUbX+TVBrj3c MEDg== X-Gm-Message-State: AOJu0Yy75knMh215mfIGluFyXlEGvM+BRRu/GAGWszke+qSORllnXqwc +uwgJOoCMBhsDsjuH9iT6iM2eta+lF4= X-Google-Smtp-Source: AGHT+IEG/N3eX9Tc6GivquyHbb3X96J+JfOB9evY/XjqTDwdxCct54EkJ33qMztLDF1Ui/a6lIFPog== X-Received: by 2002:a05:6a20:8f22:b0:13f:13cb:bc50 with SMTP id b34-20020a056a208f2200b0013f13cbbc50mr2306267pzk.25.1693378995302; Wed, 30 Aug 2023 00:03:15 -0700 (PDT) Original-Received: from smtpclient.apple (cpe-172-117-161-177.socal.res.rr.com. [172.117.161.177]) by smtp.gmail.com with ESMTPSA id f12-20020aa782cc000000b0064f76992905sm9349939pfn.202.2023.08.30.00.03.14 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 30 Aug 2023 00:03:14 -0700 (PDT) In-Reply-To: <12fe5895-7d34-4f3e-b1cf-aa133b718c24@mailo.com> X-Mailer: Apple Mail (2.3731.600.7) Received-SPF: pass client-ip=2607:f8b0:4864:20::433; envelope-from=casouri@gmail.com; helo=mail-pf1-x433.google.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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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:309530 Archived-At: > On Aug 29, 2023, at 2:26 PM, Augustin Ch=C3=A9neau (BTuin) = wrote: >=20 > Hello, >=20 > I have a few questions about tree-sitter. >=20 > 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. >=20 > So, the questions: >=20 > 1. Is there a way to reload a grammar? >=20 > 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=E2=80=99s 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? >=20 > 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))`). >=20 > I did it that way (extracted from the attachment): >=20 > (setq-local treesit-range-settings > (treesit-range-rules > :embed 'c > :host 'bison > '((undelimited_code_block) @capture))) >=20 > 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=E2=80=99ll try to work on that. > 3. Is it possible to trigger a hook when a node is modified? >=20 > 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