From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Po Lu Newsgroups: gmane.emacs.devel Subject: Re: tree-sitter: conceptional problem solvable at Emacs' level? Date: Thu, 09 Feb 2023 16:17:27 +0800 Message-ID: <87zg9n45ig.fsf@yahoo.com> References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="16805"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) 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 09:20:23 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 1pQ2AI-00046q-G4 for ged-emacs-devel@m.gmane-mx.org; Thu, 09 Feb 2023 09:20:22 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pQ29l-0007zi-Ft; Thu, 09 Feb 2023 03:19:49 -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 1pQ29c-0007zO-P0 for Emacs-devel@gnu.org; Thu, 09 Feb 2023 03:19:40 -0500 Original-Received: from sonic302-47.consmr.mail.ne1.yahoo.com ([66.163.186.173]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pQ29a-0002IA-Pg for Emacs-devel@gnu.org; Thu, 09 Feb 2023 03:19:40 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1675930775; bh=c0DEwzfl6HrKaY/rl1pvgs9Gj7mqydjFMDm3YlyXKoA=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From:Subject:Reply-To; b=F0ThHfS4u3uCkkvdURE0fBf3t5ghfkG2d6EsEkGwukoU1Nm2EF0UGfpCmfclQoF8X9hWVxfvkeYU/0751ch8mGbKPtPJSSEMfweLw6heFEfkfrVRHspX6TBUbSNvGwQSQumY/cKXv9I0JI4bizM0ZHW6tUFoB4lvncNuuyZg/QbOY58KCSYecqFPfp4ZnRdY91MitQvPLTIrHjmUjXacYUoSTvk5qmNxa3Q29oUQcXCHx3aLEb+6GnllSy7up/LyP2/+LW2hJrxGX5r8vKUqp7Db+Z20l0zNUedHSVgz6aQc6mLVccSrMUq6o5Iz7CfTdE2dzwP5Hmi2EIhnLcLg7g== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1675930775; bh=ZbNdTVRx7tX+BW+jdEhIRwpzOP6Ukx+f3pYCfv5pD6g=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=n1OBW9vmCGJjpiKE1Mpq7aYkZetBT7svxcSos4eZ83y/uFs5IuyjjGw2yx6bkeDOR6N00y/nh1gzbit1TGzmQPOCDEb2u1o92pe0OEB8qVLF7flzvGYgmEXN99dyArFhQ2X95WAuohwJDJeIAR9YIrpU8OYKUN6kEtIBKlCQ32KZt5VTE/r/NyQXboLn2htiGy9qSnMMXM+iI8o0t25FffMOCSTKiAtdHk/JwIdypO/hilCGTxaA+b6qNk29dTrR4TQuXzVr+X4BBcXSbD6SZEVJBgOI8DeP/Yo0kTc0dhWJiDK+gF/GuzH20PSQn7RM4ROTyjbh7wLR6Tm2MtnFiw== X-YMail-OSG: wYJzQeYVM1mMZr3qc_4KWU4B936fD6mCOS5b2_3WXXCW3SlrHn4gnsJ2tT2H2OM 7oRag703J6RR3tOJpHV_0LlnjQev0FfZjtdifSzdGE0CI4_S1LjYjJxj8NeExlyAbx6iXq7ConHm qlJCKWONor3ZWs_mSc6Naf7Y.IZXl.sgRCyaHaFvst9_PUxpcW57y6UY9MCysrMRocuz6T_q9z5R i4_jqlM83wP2OsvPiHX1FEDn1R2gx86CewX1naPY33ZpAx.E9awWO20O70f8OqwGcJoOhog_ybE4 bN3PzqM6tI6Z1ijPr34xfN_RiUjftPIH0aVVUam880NH0qc81fE4VjCtv2jsW89ZOcJ9ho1DWulS gLK5Sdw9cP6rK1QxyQK5NV.QvaKf3TXdOouInL_kTdumuIA.M_gpDyszt3ZqRaCNrbdJ2rhoIb.z EvrWEk7O1lAo_YkEGU1Uk56USrWdw8j9WAAaB7PFHcQhCKO5VyqF4AgycCP4k5ZrsPhPqEbm86IT H2J5_4omI05fe1w3HI9swT5Ih.k0k3_5F6YI_70xKMulwOUgzmMFstl1LNIh7wNMtkCXRbyd_ffB H1vDaSC50zyD5J0syM6soiub3GLC.9eTpkUpxI1lPm1bggZNvU0JCsvEnpJWioagBMSj1YO5CG8F s06NRXAJeS.ZpzhQquYt6IxrE_KvX0Ka3dl12tVntB12s.iuJw3Gtth.PTSJXnoLC0S8xTCFsLC6 aKAusmKBzSDGr01Poj190HjkY5bRDl0qKWPlzK.J_R4s0x53mQa6DpKtjwLbP2UsYWpmwrQxi7E5 444uRrmLnH6fNekSfcTrMn_MoFHaCv3mMBzniASyD4 X-Sonic-MF: Original-Received: from sonic.gate.mail.ne1.yahoo.com by sonic302.consmr.mail.ne1.yahoo.com with HTTP; Thu, 9 Feb 2023 08:19:35 +0000 Original-Received: by hermes--production-sg3-9fc5746c8-8hlql (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 6c42742351c0120a6f0bf39989801e5d; Thu, 09 Feb 2023 08:17:32 +0000 (UTC) In-Reply-To: (Holger Schurig's message of "Thu, 9 Feb 2023 00:09:10 -0800") X-Mailer: WebService/1.1.21161 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.yahoo Received-SPF: pass client-ip=66.163.186.173; envelope-from=luangruo@yahoo.com; helo=sonic302-47.consmr.mail.ne1.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:303066 Archived-At: Holger Schurig writes: > 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. My suggestion is simply to stay with CC Mode. Parsers (without a full C preprocessor inside) can only work for languages like Python, which cannot be enhanced with syntax-modifying macros.