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 support for C-like languages Date: Tue, 15 Nov 2022 10:18:21 -0800 Message-ID: References: <87tu36em9t.fsf@thornhill.no> <871qq8hsj1.fsf@thornhill.no> <83iljklzmo.fsf@gnu.org> <87v8nkgcqj.fsf@thornhill.no> <87sfiogcbm.fsf@thornhill.no> <83pmdrkyj7.fsf@gnu.org> <87v8njw5th.fsf@thornhill.no> <83leofkwjm.fsf@gnu.org> <9E9244D3-2EFB-4621-91E0-FC8B8C1C2D52@gmail.com> <186915C1-1C47-43DC-A386-B447A2E7528D@gmail.com> <83h6z1k6z8.fsf@gnu.org> <52D18BA8-C9A8-4E9A-9DDA-76E48744DDC9@gmail.com> <837czxjrxu.fsf@gnu.org> <8BEF109A-A5B3-4CF4-AE07-AEB9388B0A07@gmail.com> <83zgcti9gh.fsf@gnu.org> <83y1scj3s8.fsf@gnu.org> <7082237A-2BD6-4A1C-8BEC-4D470B0D204F@gmail.com> <83a64si7jo.fsf@gnu.org> <835yfgi26h.fsf@gnu.org> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) 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="669"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Stefan Monnier , theo@thornhill.no, emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Nov 15 19:19:12 2022 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 1ov0Wd-000ATS-LL for ged-emacs-devel@m.gmane-mx.org; Tue, 15 Nov 2022 19:19:11 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ov0WJ-00052A-5E; Tue, 15 Nov 2022 13:18:52 -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 1ov0Vv-0004zb-Me for emacs-devel@gnu.org; Tue, 15 Nov 2022 13:18:27 -0500 Original-Received: from mail-pg1-x535.google.com ([2607:f8b0:4864:20::535]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ov0Vu-0002DH-2z; Tue, 15 Nov 2022 13:18:27 -0500 Original-Received: by mail-pg1-x535.google.com with SMTP id 130so14012046pgc.5; Tue, 15 Nov 2022 10:18:25 -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=8zaVVU8R9lhsT7BVUVHITVJ03zMcrCdkA4i8mJd97is=; b=qVBLv7znii1Lfe26RApQlb4nGNp5XY0yYxv8qQkauQcUZyG1qweUXBuaAvhKxKlRme S6Ez+dYi5Vj9VaMAxu+F6vQoFhT6SJ3BRdNqna0i41tXKxn/uvVKofIdPw/8bHIznm0f HRkHP8aiwQIY5h0uhzx8273ouEga+X6OgI0t3tGvMBEQ8UjSAFCK7Xyx2ME9/nGnMa6I qtRSwuqn9pAXUEwIGKHtVxJI2S2udZ3f39uJGBBE+x/th1s9xXFtFK6/LKUnRhSPc4nu wBBsyROxt8yOORwuTKa0Z13TYnkVPWs8X7fNDqR0i3QgobyQdcHud9eQ4Z7aliCaXGof Vnbw== 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=8zaVVU8R9lhsT7BVUVHITVJ03zMcrCdkA4i8mJd97is=; b=Eq1XrbB1UeSouu3Y8dZbf9xQHp7UzDtsZTnct9riInCrv2N31TTPTAlfTxXIBUNCSJ NF/wrcMjd+9SduDZfMQbkhlzOXWHew/CVu19XMPgqF0k3BsOt+DCQjNgWoi/DJGyNHLl c7YRV8OruoaFVJ617rV9mvPkDaMAXiveacElDgW535Nl2DU76XGfI4sd7shsJVytx/S3 S8OdpWGJMtoXCdRlzmfJTEdUWxzy+OBKFbYdkQ5hWXQ307F6QYq81fc6VapJPkue0t3S OMQUeTYp1T7Vf3fHbtC+JW0MKFoqJFgsLAt2JlI4QZm28cg9cBWQXwuRzQ+brMWGSdHM tYrg== X-Gm-Message-State: ANoB5plMkbck5oJMJhVTlMWWtAu1hfy7jApsgUt64mmq/fZg0wfFyemm 8DlgZEfdQuXfvijRXro6sc1FVywbcxg= X-Google-Smtp-Source: AA0mqf7jYXFDQMt8FZo89wls2N7ylnGqQyiVYt6PZz2SXjbBOEannNx5GmqnwwJMqMfzOK7HIqvYNg== X-Received: by 2002:a63:1c5b:0:b0:46f:932:453f with SMTP id c27-20020a631c5b000000b0046f0932453fmr16998619pgm.405.1668536303836; Tue, 15 Nov 2022 10:18:23 -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 d11-20020a170902cecb00b00186b6a04636sm10284409plg.255.2022.11.15.10.18.22 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 15 Nov 2022 10:18:23 -0800 (PST) In-Reply-To: <835yfgi26h.fsf@gnu.org> X-Mailer: Apple Mail (2.3696.120.41.1.1) Received-SPF: pass client-ip=2607:f8b0:4864:20::535; envelope-from=casouri@gmail.com; helo=mail-pg1-x535.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:299866 Archived-At: > On Nov 15, 2022, at 8:59 AM, Eli Zaretskii wrote: >=20 >> From: Stefan Monnier >> Cc: Yuan Fu , theo@thornhill.no, = emacs-devel@gnu.org >> Date: Tue, 15 Nov 2022 11:01:24 -0500 >>=20 >>> I guess we need to report these to the developers of the = Tree-sitter's >>> C parser? Is there anything else we could do until they fix >>> the parser? >>=20 >> AFAIK the tree-sitter parser parses basically already-preprocessed C. >> It's wickedly hard to parse meaningfully notyet-preprocessed C with >> something based on a BNF grammar. >=20 > There are a lot of macros in our code that tree-sitter based C mode > gets right, so I'm not sure this is accurate. My guess is that some heuristics + error recovery.=20 >=20 >> So my guess is that this is going to be a "wont fix". >=20 > Maybe we should grow some augmentations for tree-sitter, at least > given enough time. Or maybe it's possible to identify the parts where > this happens by some tree-sitter indications, and tweak the faces in > those regions in some way. I don=E2=80=99t know how could you improve this in tree-sitter since = macros are literally =E2=80=9Cdefine you own syntax=E2=80=9D. We can = reasonably fix the highlighting for some of our macros like DEFUN. As a = demonstration I added some emacs-devel-specific rules (that are disabled = by default). Run this: (add-hook 'c-ts-mode-hook (lambda () (treesit-font-lock-recompute-features '(emacs-devel)))) And restart c-ts-mode, and DEFUN=E2=80=99s should look normal now. Yuan