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: tree-sitter: conceptional problem solvable at Emacs' level? Date: Thu, 9 Feb 2023 17:25:59 +0100 Message-ID: <20230209162559.dclnxg7j5bckx6db@Ergus> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="20416"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Emacs-devel@gnu.org To: Holger Schurig Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Feb 09 17:26:55 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 1pQ9l9-0005CA-2t for ged-emacs-devel@m.gmane-mx.org; Thu, 09 Feb 2023 17:26:55 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pQ9kW-00050m-VI; Thu, 09 Feb 2023 11:26:16 -0500 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 1pQ9kT-00050N-DG for Emacs-devel@gnu.org; Thu, 09 Feb 2023 11:26:14 -0500 Original-Received: from sonic314-13.consmr.mail.bf2.yahoo.com ([74.6.132.123]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pQ9kN-0004Iz-4N for Emacs-devel@gnu.org; Thu, 09 Feb 2023 11:26:10 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aol.com; s=a2048; t=1675959965; bh=Eur3Bajd2OVkvLnVjhuXE2HHIAZc57oDljWBb1T+2Cs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From:Subject:Reply-To; b=Kv5KhXNlZyTx99BHa9K5W4ssWPcrjzd/8bKsd3uqairhGDY7JwJCbNJOYf+cZluzGq/JRT6ahXTxSuGkBcfMBp0N/OUh77Gxznpi/9DkstXhxLkNHqhYZnCVudALQgYuzzolwcCWPiexH/j2wdDMDEQgzViuDl4iG2rsDrGCTQfNmPUkf/S1jRi9L6b4HOVtSq+u5iIYgrap50hAVV/OiA5CBkcCWZ6YpRDusY9Ng0iFAmok/dJaqjWATvE3VotPpA0PuTZ7RAg+gPw7q8RyMErKZfViqp24IL49PUBoY2Dgo4LBUxO15aGQD9605EF8lMWq3EMLcnUCjaVyY0biaw== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1675959965; bh=u7dEr7hGjN6EbQuNx1iV95comUTITwG7Bvj6eAHAQjB=; h=X-Sonic-MF:Date:From:To:Subject:From:Subject; b=kdQhyuqBA9trFuhQzYI8pNBNAzCpe9J0ornA5oZXhtkoKM0QzMeNEGZVzuNnImgQu8lQZ5hPro/L6OqZoKkYpvVXicR1INwzT1cowbUV9ffhcppwI9UhjKGSt5alRPjzAj9jKksOORlUMm98rIdoOMrjGI7Wihd1mkFRIE5H01xI1MfLsyK8FCkbddiCwZWI0Nbx0Y8ze4nj7RrGAakwxoHmYUnh6fUqnDfrAuRhImZy5UTGuB5TNegL4hIXd7pixbFL1TCgl0Xsc4pxFLM30l4QnuAH5q2be/7yLDuwx5JEV33VcYCRfgyMA3bIMsmCGTyXQ4MMnGxoqITDEnUogQ== X-YMail-OSG: p98k3d0VM1nDD4gvZtwxBtyrSDd8Y_SozUpfHSxGzlkvIp6_r.t0_s5gjKVIR3K 4V8lNdagDTrUR.8MOkCmcGQsLMYIgqVntqnCzENymhvM5.T.VH9ltAC506Vc92771B0XaqhQPlpL YsfrP2iUXJ1786I_tZakyIspWzGlYW3hjhrbt0Foak3yMPadNKwl61ibKDV8VE3V9iU3VHfRB8sj sul3fMnnFxoMqLWPWQfOIaNYqs2FhAHxZrsk3kbd4qCDVijpDBoTnhvRXQsdCSmPu1CiTQZNs5nG ZOd34aVsPNvPDVFnfXWFdpJ2PdSJVa_UIN.IUKscuihR_jYlzPwaSq8Dd8UlLxjP__WT0QMPZ4f2 aG2TGPackeR8xZZiAxTNa08a1GtP8dPplMD7phD1DxTW_KOgER9aZHK6esTiMcmRDENqo9gJBHe8 MBA6RDGAujOW_oh.6o7Ep0vDVnVgKq40l3oJVfbwH_6CFn2USEIyu2wDzpFqPWw3_gYu3qU.5xIz gWIRBI.yftBHiS_YWfvhTCMXnIJSbmzwgSUYucf4E1yVJHHusZbImV5DRNEKbroOuTcyAn0TVBwn qSigLIfSek0zYO1dT9iAXFEY9MBgnMuRPhXkQp2VrRuDsmvTIxXMntRAd3iZI7Kmy.oVHL1sRP.H FYvqH4rpuA_f5fj0iydV4uQtpF_9WDTMjeyxPRCRirYibwQCM.MbyEWPYlMl4Qd1lox8AfFnJqVZ oCfJTxdNfyd78B3hJltbO3betXY5ChXKDFEVWTum_ajiCCeWNU0jVXNKmJ0fki_Xa_HiusePXtqR utF21uG3zU_BO7aZH98fUVuavSY6GvrntRU97kYNJB X-Sonic-MF: Original-Received: from sonic.gate.mail.ne1.yahoo.com by sonic314.consmr.mail.bf2.yahoo.com with HTTP; Thu, 9 Feb 2023 16:26:05 +0000 Original-Received: by hermes--production-ir2-65c64dfd66-hwhd6 (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID d1a57db2828f937b155f9ce8132b7cb7; Thu, 09 Feb 2023 16:26:02 +0000 (UTC) Content-Disposition: inline In-Reply-To: X-Mailer: WebService/1.1.21161 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.aol Received-SPF: pass client-ip=74.6.132.123; envelope-from=spacibba@aol.com; helo=sonic314-13.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, 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:303085 Archived-At: Hi: Probably I a saying the obvious, but, did you tried to share this in the treesit syntax repository issues? https://github.com/tree-sitter/tree-sitter-cpp/issues Maybe they could give a native better solution... and fix it there, so we won't need to reinvennt the wheel. Best, Ergus On Thu, Feb 09, 2023 at 12:09:10AM -0800, Holger Schurig wrote: >Hi, I run branch emacs-29 since some time with great success. And now I >wanted to test out tree-sitter and c++-test-mode. Unfortunately, I >stumbled into some conceptional problems and wonder if this is actually >solvable by Emacs, or if some would need a completely new grammar. > >The issue is: tree-sitter doesn't work well with C macros. > >I program a lot in C++/Qt. So let's look at this (valid) C++ program: > >----------------------------------------------------------------------------- >#include > >class Test : public QObject >{ > Q_OBJECT >public: > Test() : QObject() {}; >public slots: > void someSlot() {}; >}; >----------------------------------------------------------------------------- > >If have the libraries installed (e.g. qtbase5-dev on Debian), you can >compile this perfectly. > >However, tree-sitter produces a garbage syntax tree: > >- contain some bitfield node (which isn't really there) >- contains an error node (despite the code being compilable) > >And as a result, BOTH the indentation and the font-locking is wrong. > > >Would I need to create a tree-sitter grammar in JavaScript that >understands this macro-enhanced C++? That would be quite difficult. >Or will there be a method to add some kind of tiny-preprocessor to >c++-ts-mode, so that it can substitute "Q_OBJECT", "signals" and "slots" >with nothing before handing things over to tree-sitter? > > >In comparison, I could teach the old cc-mode about this macro-enriched >C++ just with > > (c-add-style "qt-gnu" > '("gnu" (c-access-key . > "\\<\\(signals\\|public\\|protected\\|private\\|public > slots\\|protected slots\\|private slots\\):"))) > > >I guess that a lot of C and C++ programs use macros. And if there is no >simple way to aid tree-sitter in understanding this, then I fear >tree-sitter enhanced modes will often be unusable on them. >