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: Implementing cuda-ts-mode Date: Tue, 30 Jul 2024 17:15:00 -0700 Message-ID: References: <77366B28-8FDF-44AB-819B-B683C7FF5DD0@gmail.com> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3774.600.62\)) 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="9308"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Ergus Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Jul 31 02:16:09 2024 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 1sYx0i-0002Hk-Rk for ged-emacs-devel@m.gmane-mx.org; Wed, 31 Jul 2024 02:16:08 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sYwzy-0001iN-VF; Tue, 30 Jul 2024 20:15:23 -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 1sYwzs-0001hx-AI for emacs-devel@gnu.org; Tue, 30 Jul 2024 20:15:16 -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 1sYwzp-00025V-Ux for emacs-devel@gnu.org; Tue, 30 Jul 2024 20:15:15 -0400 Original-Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-70d333d57cdso3597162b3a.3 for ; Tue, 30 Jul 2024 17:15:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722384912; x=1722989712; 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=sEtWBdCCpCZ9lxKoDWxqXLG7fdwW763PtKj5DRXC96g=; b=R79Lavrj3wv4d/ZJOcjAXFEpBjXjS89tOzSrI1L0kV8Q5gSuZvcl3UpRvo1ybIhgXw kbNPDSXjemqCfdiZq5A5LWnMVU6pPjv3gzW9T6m/kQxXo/T6IF8x4I+wc4TSrLwoBzLb U5VW+oUfKFlW6osjXsrqyrRQvX1QgPs+KiCQFnSvkMWUfVvlNO4TZnVuC9aMNsvOBglE Eb0PcAfFv0g92aXl+wpOAQI3tmTdvFUc4pWSpFMbv8tkxkJeC22pLWPF8InNPISbWout X7N35gsefFpAg7kKxY6H/3FtUgemR5UYeOLUCKnfJRkavFT6NpJ+uoYXlP2CFdLdXyZi B99w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722384912; x=1722989712; 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=sEtWBdCCpCZ9lxKoDWxqXLG7fdwW763PtKj5DRXC96g=; b=hx+gH9uiyeS4GxLffOhULFINZl7F4EjI1BI+nC4qP9mNprJrLk7YVFb/+QXHyvq07m nJgaoHfqVmQXqezEEAaTEhsT9dxwRmlcFPCiDBxueU86j4Fz+BG23ANGmgQ39e2Dsii4 Aq7rFfjoVg4AzoiQFxvz/KqjeBJzGR98/CsNZt6/THGT5ljOg7l8u+mWrEgRuRzp8C03 OCUiDIDsGYDTYjE0gSYzmr2QD/hLKzJH5DTy0jct+Z/AmfV6AXFxsg2QtwaDijz/4z88 hYMW4I40ljamXtSvBM/2EA36DL626cNwYck8dIsDEw9rt9X3SkW1aiveICYKq6/sijZ2 YfBg== X-Gm-Message-State: AOJu0YxjAM4xwYo8utV0mfDobo95FsJj8OO8QjZ51dohS5fGgL39t4jQ qWCUTGHn4Ri1ulOC4fEzVSsa9yhsl9XhwroMZiQFUKv+CEqSTni5 X-Google-Smtp-Source: AGHT+IFRTt6sl3E8qkuy/GgIlCCyzOPr5K2ll7CbkgMak5st19soaxiGnIXdhqJ0fa1x4tPRorLxGA== X-Received: by 2002:a05:6a20:841b:b0:1c3:b210:418b with SMTP id adf61e73a8af0-1c4a152992bmr11333462637.52.1722384912178; Tue, 30 Jul 2024 17:15:12 -0700 (PDT) Original-Received: from smtpclient.apple ([2601:646:8f81:6120:4c7a:ac4b:4762:593e]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fed7fbd8d4sm107848635ad.271.2024.07.30.17.15.11 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 30 Jul 2024 17:15:11 -0700 (PDT) In-Reply-To: <77366B28-8FDF-44AB-819B-B683C7FF5DD0@gmail.com> X-Mailer: Apple Mail (2.3774.600.62) 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:322222 Archived-At: > On Jul 27, 2024, at 4:22=E2=80=AFPM, Yuan Fu = wrote: >=20 >=20 >=20 >> On Jul 25, 2024, at 7:05=E2=80=AFAM, Ergus wrote: >>=20 >>=20 >>=20 >> On July 25, 2024 9:42:10 AM GMT+02:00, Yuan Fu = wrote: >>>=20 >>>=20 >>>> On Jul 23, 2024, at 5:38=E2=80=AFAM, Ergus = wrote: >>>>=20 >>>> Hi: >>>>=20 >>>> After a while and looking that the ts modules are getting mature I = was >>>> planing to develop a `cuda-ts-mode'. >>>>=20 >>>> However after reading the documentation it is not totally clear to = me >>>> how to proceed in this specific case because cuda is a sort of >>>> "extension" over C++, so I expect that the cuda-ts-mode somehow >>>> "inherits" from c++-ts-mode. >>>>=20 >>>> My initial idea was to replicate how I was expecting that = c++-ts-mode >>>> should inherit from c-ts-mode, but it looks like this doesn't = happen in >>>> a clear way. The modes are threated as independent and there is a = sort >>>> of "mode" variable that is dynamically checked everywhere. >>>>=20 >>>> So the simple question is: >>>>=20 >>>> 1. The approach of trying to inherit from c++-ts-mode is correct? = (I mean, >>>> is c++-ts-mode intended to be used like a "base" to inherit from?) >>>>=20 >>>> Some advise on this? >>>=20 >>> IIUC, tree-sitter-cuda is a separate grammar that is extended from = tree-sitter-cpp, right? Then inheriting c++-ts-mode won=E2=80=99t work = since it=E2=80=99ll setup everything using the cpp grammar. You=E2=80=99d = need to delete the cpp parser and add your cuda parser (doable), and = change everything that refers to =E2=80=98cpp to =E2=80=98cuda (very = hacky). >>>=20 >>> I guess we can add some map which tells Emacs to use the cuda = grammar in place of cpp. Kind of like treesit-load-name-override-list = but more dynamic. >>>=20 >>> Once we=E2=80=99re able to do that, you can define a new mode that = derives from c++-ts-mode and expect all the setup in c++-ts-mode to = work. >>>=20 >>> Yuan >>=20 >> Hi Yuan: >>=20 >> Now I understand why c++-ts-mode does not inherit from c-ts-mode. = This sort of inheritance is natural considering how tree sitter works. = So I am a bit surprised that nobody faced this before. I saw some = derived modes changes a while ago and I thought that it was related to = this. >>=20 >> The extra features that the Cuda grammar adds to c++ are actually not = many, but some are important to not break the indentation.=20 >>=20 >> = >>=20 >> That's why, reimplementing the c++-ts-mode code substituting the = entries seems as unnecessary and overkill to me. So I will wait for the = new feature to be out before, then it will be more scalable and simple = to do a Cuda-ts-mode. >>=20 >> Best, >> Ergus >>=20 >> PD: Do you want me to open a bug report to keep track of this? >=20 > Yeah, that=E2=80=99ll be great. Thanks! I=E2=80=99ve implemented the = feature; once you create a bug report I=E2=80=99ll push to master for = you and others to try it out. I have some other stuff that I want to push. So I went ahead and created = bug#72388 and pushed the new feature to master. Now there=E2=80=99s a = treesit-language-remap-alist. See if that works for you, and we can continue discussion in the bug = report :-) Yuan=