unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Yuan Fu <casouri@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 63957@debbugs.gnu.org, Theodor Thornhill <theo@thornhill.no>
Subject: bug#63957: 29.0.91; c-ts-mode: incorrect fontification in alloc.c
Date: Mon, 12 Jun 2023 02:16:51 -0700	[thread overview]
Message-ID: <14362329-D74B-42C9-879D-CE61CA6969A6@gmail.com> (raw)
In-Reply-To: <83zg57zqhf.fsf@gnu.org>

>> 
>>>>> emacs -Q
>>>>> C-x C-f src/alloc.c RET
>>>>> M-x c-ts-mode RET
>>>>> C-u 3184 M-g g
>>>>> 
>>>>> Observe that several "else if" clauses in the following fragment are not
>>>>> fontified correctly:
>>>> 
>>>> Adding the relevant folks.
>>>> 
>>>> Could you guys please look into this issue?
>> 
>> Ok, so this is one of such cases where the preproc directives severs the code and the parser can’t recover very well. We can cover it over by just fontifying “else if” with keyword face, but there are a million ways for the preproc directive to mess up the parser, I don’t think we can cover every case.
> 
> Can you explain what is special in this particular case that is
> different from other preprocessor directives?  I'd like to think if
> this case is important enough to try harder.

I wouldn’t say that this case is special, actually the cases we were able to more or less fix are special. The problem with preproc directives is that they can appear anywhere and break whatever construct they appear in. (Because tree-sitter-c parses preproc constructs as top-level constructs, higher than anything else.)

Say there’s a struct:

struct A
{
  int a;
  int b;
}

If we add preproc directives:

struct A
{
#if A
  int a;
#else  
  int b;
}
#endif

Now the parser will parse the "struct A {“ individually; parse “int a;” individually; and parse “int b; }” individually.

So in general, if a preproc directives butchers some construct, the first part is usually fine (eg, the “struct A {“ part), but the rest often have problems. Like a dangling “else if {}” in if-else-if, or a dangling “xxx }” in a function definition, or maybe a “default: xxx }” in a switch-case.

The Emacs-specific macros we were able to “fix” all have a specific pattern, so we can find them and expect them to have a certain shape, but the breakage caused by preproc directives don’t really have a pattern. I can’t think of a good way to handle them.

I’m not against fixing these case-by-case, if the cases becomes too many and not scalable, we can give up.

Yuan




  reply	other threads:[~2023-06-12  9:16 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-08  5:56 bug#63957: 29.0.91; c-ts-mode: incorrect fontification in alloc.c Eli Zaretskii
2023-06-08  6:00 ` Eli Zaretskii
2023-06-08  7:19   ` Yuan Fu
2023-06-10  6:51     ` Yuan Fu
2023-06-10  8:11       ` Eli Zaretskii
2023-06-12  9:16         ` Yuan Fu [this message]
2023-06-12 12:38           ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=14362329-D74B-42C9-879D-CE61CA6969A6@gmail.com \
    --to=casouri@gmail.com \
    --cc=63957@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=theo@thornhill.no \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).