From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Holger Schurig Newsgroups: gmane.emacs.devel Subject: tree-sitter: conceptional problem solvable at Emacs' level? Date: Thu, 9 Feb 2023 00:09:10 -0800 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="6719"; 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 Thu Feb 09 09:09: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 1pQ20A-0001Vt-Rx for ged-emacs-devel@m.gmane-mx.org; Thu, 09 Feb 2023 09:09:54 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pQ1zZ-0004TX-2N; Thu, 09 Feb 2023 03:09:17 -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 1pQ1zX-0004Sz-5R for Emacs-devel@gnu.org; Thu, 09 Feb 2023 03:09:15 -0500 Original-Received: from mail-ej1-x630.google.com ([2a00:1450:4864:20::630]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pQ1zV-00006b-H5 for Emacs-devel@gnu.org; Thu, 09 Feb 2023 03:09:14 -0500 Original-Received: by mail-ej1-x630.google.com with SMTP id hx15so3877975ejc.11 for ; Thu, 09 Feb 2023 00:09:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:subject:message-id:date:mime-version:from:from:to:cc:subject :date:message-id:reply-to; bh=Jf3nUOI8d9296ItuBiPBcFT0x98OEf1nTjNS2Il83CE=; b=PSM4FToO3cIPx3srxWTrjORtZxoasRV5thfhqJxH7rG6rXTaWxCwe+8OY6oJHWrBKG ffvQhSTl9HEfvZIVt3RpPK7SUe6YESVGI+1T4emB9N1uiNbmYMuIMl/LcGOKQ70nzkl0 3aM0uR8t/T42CrhqNkoa20QcGPMNS0ZAFL8CmuLyut2NnEhwNIXK1ALS6WHkMATxs/68 SNVblm1HY1pM+elNtqKscVpRnbVxf5h4xIXquMqS8AG0H0YLXaie1YAo0v5gBOrHt0Vf SRXWutweHr98ll/9EwpWIuI41aAVcEKNmzlzW4zVSUW1RjIzuYzcu3GI/Ci1vEc9W6yL 5Qmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:mime-version:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=Jf3nUOI8d9296ItuBiPBcFT0x98OEf1nTjNS2Il83CE=; b=G3WjjpusrJtA+WS82DRwyANb0jVpV3fU+MBOMQY9bKMOSaGCHOKuWu80VkTPUOCFG7 ZL8GgISqu/gZljA0pXImXuEAV81fz8ORqfFM0jlAnJZqDGU6VpRU48keXtmL5Mq1oqqV J64y07ZN7W7sP9g5ChL0dSDs2WFHOlhGe8SPFG99uUdfPMoaXneK74hSZVSvq/8y5OMP FnjrDLmPxpHoYErGY8inRG7m2VlWH5q0RniL0hqdLDslWgDBNRkiWN2n5nHaIbLYY3vc sLwUwMqhWyY8eOdrOepIxHsbG7dI7mqB8IqFafD9584FGW6fgcfniNxo1MP06dY4iltU eD5A== X-Gm-Message-State: AO0yUKWWjo8PyFyriVAGiYDL6zcbJFO12PEIdfCxaHYV83NIN4TP+35H N5qbYoT3E0oLnXZnauaSpbB+cQUqlhybcieICYURNI91 X-Google-Smtp-Source: AK7set9oVEWtmj9mJuX/e4dNRo3Rf4LKHgGUP7rLl+5St2KiNwIWoJeN6GispsiXMaPzsKuylzM/1gqB3Gx9nsrKfzc= X-Received: by 2002:a17:906:4b05:b0:8af:38c9:d52d with SMTP id y5-20020a1709064b0500b008af38c9d52dmr239010eju.2.1675930151520; Thu, 09 Feb 2023 00:09:11 -0800 (PST) Original-Received: from 753933720722 named unknown by gmailapi.google.com with HTTPREST; Thu, 9 Feb 2023 00:09:10 -0800 Received-SPF: pass client-ip=2a00:1450:4864:20::630; envelope-from=holgerschurig@gmail.com; helo=mail-ej1-x630.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:303065 Archived-At: 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.