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: tree-sitter: conceptional problem solvable at Emacs' level? Date: Thu, 9 Feb 2023 23:33:10 -0800 Message-ID: <0DDF6978-D75A-4137-9D93-6200908675B6@gmail.com> References: <87zg9n45ig.fsf@yahoo.com> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.300.101.1.3\)) 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="32159"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Holger Schurig , Emacs-devel@gnu.org To: Po Lu Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Feb 10 08:33:43 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 1pQNuh-0008Ey-Pu for ged-emacs-devel@m.gmane-mx.org; Fri, 10 Feb 2023 08:33:43 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pQNuU-00048n-4w; Fri, 10 Feb 2023 02:33:30 -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 1pQNuP-00048Q-FM for Emacs-devel@gnu.org; Fri, 10 Feb 2023 02:33:28 -0500 Original-Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pQNuN-0001eM-I2 for Emacs-devel@gnu.org; Fri, 10 Feb 2023 02:33:24 -0500 Original-Received: by mail-pj1-x1036.google.com with SMTP id bx22so4401377pjb.3 for ; Thu, 09 Feb 2023 23:33:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=Odhp1NH8RYGfuIPDr9FAM19fb27LSeRYiD+ugISNBjs=; b=Q3KIGjcCDowsLH7QFDoqYitATqchohIi9YOIRKzGLFQ4f1EKO0LWarmuZPsg69vrcA sAJZ+oaWT0hbyuT5VcLQfxcLEOe55rM3v+apgwLHACv+BLePbgTnJhHqjNCa5HJv1OuP EgBWXTcGHmIlPfjHhVzYNgHKYptWmqRV+48gAfNw+ZBCyvawTPODifgy1AXmV4buuKR2 FhodH/pG4cBKUOF2SiupK8yytgmUrsVZfUjoVHBPQcGbQl7fEvNLyz0ELuXr25PepFEG BFHyAlROK8L2GMXIdkkLrq4ArsZh3Nys5EfUCvPYtK2AVYdodhkhaWk8b74yFednuYft Ex9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=Odhp1NH8RYGfuIPDr9FAM19fb27LSeRYiD+ugISNBjs=; b=mAFfD5DS4Zdgs4a/J9FYTsDJUzfvq6kYxoLRa9xvBT0QVs+QSoJDJ38fqp+s/Dj2UT gOKSYWHV/zl2fugXi/0y2ZzxGNbx5UYeeMEGAODsLd5/Fd5X5HW9mF1e87UVsNHG/EZf BcbFiQDKQAOKEcUrjjgk9atDjtQguWRSBIIuvFA/HvsGi0op8HyQB8VYZCHp/uP76rgd so2mQbIi++zpY8Zp+yz4h74a9NLTM3+3k/6aWEN029wv1DnUPgryZkD2kgGfccWTNCAl n9JRa4cE1e8l2VqUK5Fo/RmBvJBnh2I9so1gjrk+KwNM2Qt4ke/ye02duGsTjGv3h9Q7 pkZw== X-Gm-Message-State: AO0yUKUe5ouJvEATtW6EvHWHbrSwcsabWPRTHM+o//4Ohp2cik+6kWQX lOkDFSfRaGP7EHf4qBP+JgSIGI1Mwvx+cw== X-Google-Smtp-Source: AK7set9qX/FPc1eWWJdUFpfVV9ntOetNFtg/2qyMFM/JYG7DgTeRnEVIMns3IgYb59VdfiZ8maxtqw== X-Received: by 2002:a17:902:e88e:b0:196:7c6d:2aee with SMTP id w14-20020a170902e88e00b001967c6d2aeemr17261420plg.11.1676014401922; Thu, 09 Feb 2023 23:33:21 -0800 (PST) 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 jc12-20020a17090325cc00b001931c37da2dsm2711963plb.20.2023.02.09.23.33.21 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Feb 2023 23:33:21 -0800 (PST) In-Reply-To: <87zg9n45ig.fsf@yahoo.com> X-Mailer: Apple Mail (2.3731.300.101.1.3) Received-SPF: pass client-ip=2607:f8b0:4864:20::1036; envelope-from=casouri@gmail.com; helo=mail-pj1-x1036.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:303094 Archived-At: > On Feb 9, 2023, at 12:17 AM, Po Lu wrote: >=20 > Holger Schurig writes: >=20 >> 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. >>=20 >> The issue is: tree-sitter doesn't work well with C macros. >>=20 >> I program a lot in C++/Qt. So let's look at this (valid) C++ program: >>=20 >> = --------------------------------------------------------------------------= --- >> #include >>=20 >> class Test : public QObject >> { >> Q_OBJECT >> public: >> Test() : QObject() {}; >> public slots: >> void someSlot() {}; >> }; >> = --------------------------------------------------------------------------= --- >>=20 >> If have the libraries installed (e.g. qtbase5-dev on Debian), you can >> compile this perfectly. >>=20 >> However, tree-sitter produces a garbage syntax tree: >>=20 >> - contain some bitfield node (which isn't really there) >> - contains an error node (despite the code being compilable) >>=20 >> And as a result, BOTH the indentation and the font-locking is wrong. >>=20 >>=20 >> 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? >>=20 >>=20 >> In comparison, I could teach the old cc-mode about this = macro-enriched >> C++ just with >>=20 >> (c-add-style "qt-gnu" >> '("gnu" (c-access-key . >> = "\\<\\(signals\\|public\\|protected\\|private\\|public >> slots\\|protected slots\\|private slots\\):"))) >>=20 >>=20 >> 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. >=20 > My suggestion is simply to stay with CC Mode. >=20 > Parsers (without a full C preprocessor inside) can only work for > languages like Python, which cannot be enhanced with syntax-modifying > macros. >=20 Right. Our best hope is for someone to try extend the current = tree-sitter-c grammar, but I don=E2=80=99t know how feasible it is. = Emacs can also do some limited workaround, but the potential in that = department is slim. Yuan=