[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Tree sitter support for C-like languages

From: Yuan Fu
Subject: Re: Tree sitter support for C-like languages
Date: Tue, 15 Nov 2022 10:18:21 -0800

> On Nov 15, 2022, at 8:59 AM, Eli Zaretskii <eliz@gnu.org> wrote:
>> From: Stefan Monnier <monnier@iro.umontreal.ca>
>> Cc: Yuan Fu <casouri@gmail.com>,  theo@thornhill.no,  emacs-devel@gnu.org
>> Date: Tue, 15 Nov 2022 11:01:24 -0500
>>> 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?
>> 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.
> 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. 

>> So my guess is that this is going to be a "wont fix".
> 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’t know how could you improve this in tree-sitter since macros are 
literally “define you own syntax”. 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’s should look normal now.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]