From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Ergus Newsgroups: gmane.emacs.devel Subject: Re: Implementing cuda-ts-mode Date: Wed, 31 Jul 2024 23:06:57 +0200 Message-ID: References: <77366B28-8FDF-44AB-819B-B683C7FF5DD0@gmail.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=----5QIL5SCHCIC4D82N0NNW09QXC9X43G Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="26844"; mail-complaints-to="usenet@ciao.gmane.io" To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Jul 31 23:07:54 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 1sZGY2-0006lt-Va for ged-emacs-devel@m.gmane-mx.org; Wed, 31 Jul 2024 23:07:51 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sZGXQ-0004a5-W4; Wed, 31 Jul 2024 17:07:13 -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 1sZGXO-0004Zt-99 for emacs-devel@gnu.org; Wed, 31 Jul 2024 17:07:10 -0400 Original-Received: from sonic310-14.consmr.mail.bf2.yahoo.com ([74.6.135.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sZGXL-0000i3-An for emacs-devel@gnu.org; Wed, 31 Jul 2024 17:07:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aol.com; s=a2048; t=1722460022; bh=WW23WpxL29fe+nHBXocVOpfTFHOIxLDSD42R/HKi+oM=; h=Date:From:To:Subject:In-Reply-To:References:From:Subject:Reply-To; b=uJMXnCzrChlIhdY9j+I3loA9MAZbsAruCz2xtPcFbsvKWrBmGVSjTS735RMbOgZL4sj42fGA5zRcM4iz4cXEjkqUUJT868x8imiDvF+Z0pDzN5qf1u4ZbB0Kb/NX5gXGfVhMW3jA+DTs7knqdSSH3gk4X5B7hSaA1/bHeHUAlwx+zWQsGW3FqFDSLHs1M6vifQ3Q3fuOuKgG6Hk4rxOjWFrQIm2Sm30abXvU9mzA/85AoQtIEbNWGnqd0Zl2LcY8lFhZ3U+JowtbV16r4K9AnjAjYOHqMyhtgzv4iu+VZd8IA68PNnu4Wd18+bU2eRtfmNKcxy4dVbekFCqqpi8SbA== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1722460022; bh=tJbYKh6J3p5O13XDa2PqVVsp0Irjv5hJflKq/NCJ7D1=; h=X-Sonic-MF:Date:From:To:Subject:From:Subject; b=WTlej92WKZzt+m3Tdmt52iqoP+heCONU6+WyWYAQQhVZyu6o4VrriZXDUo+IWCcIAm2LODbUCbMr1His4C1blsfZOxwlahjOFicqZfTlzaFszZMl5nQ6b9JcCE3Q6tYp9WTNm4sAePDHmaLkP5B8mirJKT6srzT70hSJhGfP0e+cq20QBr59dmpcwedH+Wdh5q7qElpRpwG2B2XtVbI8G4cG2ic67wBy0qCG8FqRvg+9QyK05iLQAmXeQL8gW8LWp/+eFS5E1Xu5ILybWQ+ScgqZGnbsUwaKggrzBbYG9mYNZDPrAMenfy4CXvuJcDpvctj/cZvRndiKSSfhZ0w6Yg== X-YMail-OSG: CUhMN.wVM1kRW4FNsbW9LbZo.En7Cn.LxANxo3TR1PTWc6Bt56CFT1yy.5NCuD7 Imi_pYtqSbFdVEUwrLfRq5ZWRP5aDhTI.2_u9fWWDM3iZOvvyXKbFOJHaG5a2jY.ZdKMpY8fII5Q 1WdxetuESgPlHCgZwdHbqtKo.1_AmWmwQXxw0oAKznFOY5VFnOZCBv3cbEvgs4IuMBYirDptkaGh mhcInbt3zIn.8ThIxAUHUtN5DBJaCQzRcYsLMkqvR9hGlKayTdJzjYtUE6GnHtqy4ul9r9dNMXy. AXsK8Fb0zc0i0cXe2o1nW1shbG5CNfwKQRIs_r.RxsVDgL9QrgIWZqQdrGGWvjsKl75ZJnzSQjSZ lhk36xIFWvYnln_PYApn8bju9Vk5VAjftMlYEi9src8K0kBgrES6N.5O7R6aQJdc0sace3zi0idl RQKo7MRE0SczfiROhh19EHlJN8GKU4oCGTb0qVoF_Vp_RPWLSFLOIrdk7g93tY.0ET8UFyBzzGva VmQJni6oy8R8hEEyKDX5iFx2puATMTLT3pN5m.7MepxhNP0QAA8npEsNtViaGtD5KWRAvs43Kpyt vPsAE9idd1OuW0vgAc0iwsbcbA390ZmzUXBFmIyApmV__0EiFJYHdtnXkAwi.hh7eMnz23RbUe0s n.DiU8hcyh862iqRVpNXELmJe.ABNTzXSOv09vR24aUmPpC7_4pdUMuBIC0GuUQDHQWgSEPEXd1M 4.11EAFLZzEGaGMm.qNwkcg8BjxYzUA5GJlz4bEvg0LmyVwWek.VxuSQkY8Ia9eyRKSSbEJLsY9e TFj.SzDHYL.1.nK5ByNpptGtaCSXgy9HLb8k1tNF1c X-Sonic-MF: X-Sonic-ID: f1c43b4f-5138-4b8f-81a8-b8e5ffb5e93a Original-Received: from sonic.gate.mail.ne1.yahoo.com by sonic310.consmr.mail.bf2.yahoo.com with HTTP; Wed, 31 Jul 2024 21:07:02 +0000 Original-Received: by hermes--production-ir2-6664f499fc-fs9vv (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 1c06cc3092955b52f1edd8233b03cae1; Wed, 31 Jul 2024 21:06:59 +0000 (UTC) In-Reply-To: X-Mailer: WebService/1.1.22544 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.aol Received-SPF: pass client-ip=74.6.135.124; envelope-from=spacibba@aol.com; helo=sonic310-14.consmr.mail.bf2.yahoo.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, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-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:322233 Archived-At: ------5QIL5SCHCIC4D82N0NNW09QXC9X43G Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi Yuan: Very thanks for taking care of this so quickly=2E I actually tried to open the bug as you suggested a few days ago (and add = a new message to 72263) but now just found that both messages failed to del= iver=2E Next week I will give it a first try to the cuda-ts-mode=2E Let's continue= in the bug report then=2E Thanks again, Ergus On July 31, 2024 2:15:00 AM GMT+02:00, Yuan Fu wrote= : > > >> On Jul 27, 2024, at 4:22=E2=80=AFPM, Yuan Fu wrot= e: >>=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 w= rote: >>>>=20 >>>>=20 >>>>> On Jul 23, 2024, at 5:38=E2=80=AFAM, Ergus wrot= e: >>>>>=20 >>>>> Hi: >>>>>=20 >>>>> After a while and looking that the ts modules are getting mature I w= as >>>>> planing to develop a `cuda-ts-mode'=2E >>>>>=20 >>>>> However after reading the documentation it is not totally clear to m= e >>>>> 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=2E >>>>>=20 >>>>> My initial idea was to replicate how I was expecting that c++-ts-mod= e >>>>> should inherit from c-ts-mode, but it looks like this doesn't happen= in >>>>> a clear way=2E The modes are threated as independent and there is a = sort >>>>> of "mode" variable that is dynamically checked everywhere=2E >>>>>=20 >>>>> So the simple question is: >>>>>=20 >>>>> 1=2E 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 tr= ee-sitter-cpp, right? Then inheriting c++-ts-mode won=E2=80=99t work since = it=E2=80=99ll setup everything using the cpp grammar=2E You=E2=80=99d need = to delete the cpp parser and add your cuda parser (doable), and change ever= ything that refers to =E2=80=98cpp to =E2=80=98cuda (very hacky)=2E >>>>=20 >>>> I guess we can add some map which tells Emacs to use the cuda grammar= in place of cpp=2E Kind of like treesit-load-name-override-list but more d= ynamic=2E >>>>=20 >>>> Once we=E2=80=99re able to do that, you can define a new mode that de= rives from c++-ts-mode and expect all the setup in c++-ts-mode to work=2E >>>>=20 >>>> Yuan >>>=20 >>> Hi Yuan: >>>=20 >>> Now I understand why c++-ts-mode does not inherit from c-ts-mode=2E Th= is sort of inheritance is natural considering how tree sitter works=2E So I= am a bit surprised that nobody faced this before=2E I saw some derived mod= es changes a while ago and I thought that it was related to this=2E >>>=20 >>> The extra features that the Cuda grammar adds to c++ are actually not = many, but some are important to not break the indentation=2E=20 >>>=20 >>> >>>=20 >>> That's why, reimplementing the c++-ts-mode code substituting the entri= es seems as unnecessary and overkill to me=2E So I will wait for the new fe= ature to be out before, then it will be more scalable and simple to do a Cu= da-ts-mode=2E >>>=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=2E Thanks! I=E2=80=99ve implemented the = feature; once you create a bug report I=E2=80=99ll push to master for you a= nd others to try it out=2E > >I have some other stuff that I want to push=2E So I went ahead and create= d bug#72388 and pushed the new feature to master=2E Now there=E2=80=99s a t= reesit-language-remap-alist=2E > >See if that works for you, and we can continue discussion in the bug repo= rt :-) > >Yuan --=20 Sent from my Android device with K-9 Mail=2E Please excuse my brevity=2E ------5QIL5SCHCIC4D82N0NNW09QXC9X43G Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
Hi Yuan:

Very thanks for = taking care of this so quickly=2E

I actually tried to open the bug a= s you suggested a few days ago (and add a new message to 72263) but now jus= t found that both messages failed to deliver=2E

Next week I will giv= e it a first try to the cuda-ts-mode=2E Let's continue in the bug report th= en=2E

Thanks again,
Ergus


On July 31, 2024 2:15:00 AM GMT+02:00, Yuan Fu <c= asouri@gmail=2Ecom> wrote:


On Jul 27, 2024, at 4:22=E2= =80=AFPM, Yuan Fu <casouri@gmail=2Ecom> wrote:



<= blockquote class=3D"gmail_quote" style=3D"margin: 0pt 0pt 1ex 0=2E8ex; bord= er-left: 1px solid #ad7fa8; padding-left: 1ex;">
On Jul 25= , 2024, at 7:05=E2=80=AFAM, Ergus <spacibba@aol=2Ecom> wrote:

=

On July 25, 2024 9:42:10 AM GMT+02:00, Yuan Fu <casouri@gmail=2E= com> wrote:


On Jul 23, 2024, at 5:38=E2=80=AFAM, Ergus <spacib= ba@aol=2Ecom> wrote:

Hi:

After a while and looking that th= e ts modules are getting mature I was
planing to develop a `cuda-ts-mode= '=2E

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
"inheri= ts" from c++-ts-mode=2E

My initial idea was to replicate how I was e= xpecting that c++-ts-mode
should inherit from c-ts-mode, but it looks li= ke this doesn't happen in
a clear way=2E The modes are threated as indep= endent and there is a sort
of "mode" variable that is dynamically checke= d everywhere=2E

So the simple question is:

1=2E The approach = of trying to inherit from c++-ts-mode is correct? (I mean,
is c++-ts-mod= e intended to be used like a "base" to inherit from?)

Some advise on= this?

IIUC, tree-sitter-cuda i= s a separate grammar that is extended from tree-sitter-cpp, right? Then inh= eriting c++-ts-mode won=E2=80=99t work since it=E2=80=99ll setup everything= using the cpp grammar=2E You=E2=80=99d need to delete the cpp parser and a= dd your cuda parser (doable), and change everything that refers to =E2=80= =98cpp to =E2=80=98cuda (very hacky)=2E

I guess we can add some map = which tells Emacs to use the cuda grammar in place of cpp=2E Kind of like t= reesit-load-name-override-list but more dynamic=2E

Once we=E2=80=99r= e 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=2E

Yuan

Hi Yuan:

Now I understand why c++-ts= -mode does not inherit from c-ts-mode=2E This sort of inheritance is natura= l considering how tree sitter works=2E So I am a bit surprised that nobody = faced this before=2E I saw some derived modes changes a while ago and I tho= ught that it was related to this=2E

The extra features that the Cuda= grammar adds to c++ are actually not many, but some are important to not b= reak the indentation=2E

<https://github=2Ec= om/tree-sitter-grammars/tree-sitter-cuda/blob/master/grammar=2Ejs>
That's why, reimplementing the c++-ts-mode code substituting the entr= ies seems as unnecessary and overkill to me=2E So I will wait for the new f= eature to be out before, then it will be more scalable and simple to do a C= uda-ts-mode=2E

Best,
Ergus

PD: Do you want me to open a bu= g report to keep track of this?
Yeah, that=E2=80=99ll be great=2E Thanks! I=E2=80=99ve implemented the fea= ture; once you create a bug report I=E2=80=99ll push to master for you and = others to try it out=2E

I have = some other stuff that I want to push=2E So I went ahead and created bug#723= 88 and pushed the new feature to master=2E Now there=E2=80=99s a treesit-la= nguage-remap-alist=2E

See if that works for you, and we can continue= discussion in the bug report :-)

Yuan
<= /div>
--
Sent from my = Android device with K-9 Mail=2E Please excuse my brevity=2E
------5QIL5SCHCIC4D82N0NNW09QXC9X43G--