all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#63323: c-ts-mode does not know about `restrict'
       [not found] <87r0rtkh2j.fsf.ref@yahoo.com>
@ 2023-05-06  8:19 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2023-05-06 10:31   ` Eli Zaretskii
  0 siblings, 1 reply; 5+ messages in thread
From: Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2023-05-06  8:19 UTC (permalink / raw)
  To: 63323

Standard C accepts a keyword `restrict', which is used to declare
pointers whose referenced object must only be accessed by lvalues based
upon one such pointer within the block where they are declared.

Like so:

  argb *restrict src, *restrict dest;

c-ts-mode does not understand this keyword.  It is not fontified within
such declarations.





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#63323: c-ts-mode does not know about `restrict'
  2023-05-06  8:19 ` bug#63323: c-ts-mode does not know about `restrict' Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2023-05-06 10:31   ` Eli Zaretskii
  2023-05-06 12:19     ` Eli Zaretskii
  0 siblings, 1 reply; 5+ messages in thread
From: Eli Zaretskii @ 2023-05-06 10:31 UTC (permalink / raw)
  To: Po Lu, Yuan Fu; +Cc: 63323

> Date: Sat, 06 May 2023 16:19:32 +0800
> From:  Po Lu via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
> 
> Standard C accepts a keyword `restrict', which is used to declare
> pointers whose referenced object must only be accessed by lvalues based
> upon one such pointer within the block where they are declared.
> 
> Like so:
> 
>   argb *restrict src, *restrict dest;
> 
> c-ts-mode does not understand this keyword.  It is not fontified within
> such declarations.

It looks like c-ts-mode thinks type qualifiers are possible only in
C++?

   :feature 'type
   `((primitive_type) @font-lock-type-face
     (type_identifier) @font-lock-type-face
     (sized_type_specifier) @font-lock-type-face
     ,@(when (eq mode 'cpp) <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
         '((type_qualifier) @font-lock-type-face

           (qualified_identifier
            scope: (namespace_identifier) @font-lock-type-face)

           (operator_cast) type: (type_identifier) @font-lock-type-face))
     [,@c-ts-mode--type-keywords] @font-lock-type-face)

The tree-sitter library returns a type_qualifier node for 'restrict':

       (parameter_declaration type: (type_identifier)
	declarator: 
	 (pointer_declarator *
	  (type_qualifier restrict)
	  declarator: (identifier)))

Yuan, can you look into fixing this, please?





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#63323: c-ts-mode does not know about `restrict'
  2023-05-06 10:31   ` Eli Zaretskii
@ 2023-05-06 12:19     ` Eli Zaretskii
  2023-05-06 22:54       ` Yuan Fu
  0 siblings, 1 reply; 5+ messages in thread
From: Eli Zaretskii @ 2023-05-06 12:19 UTC (permalink / raw)
  To: casouri; +Cc: luangruo, 63323

> Cc: 63323@debbugs.gnu.org
> Date: Sat, 06 May 2023 13:31:03 +0300
> From: Eli Zaretskii <eliz@gnu.org>
> 
> It looks like c-ts-mode thinks type qualifiers are possible only in
> C++?
> 
>    :feature 'type
>    `((primitive_type) @font-lock-type-face
>      (type_identifier) @font-lock-type-face
>      (sized_type_specifier) @font-lock-type-face
>      ,@(when (eq mode 'cpp) <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
>          '((type_qualifier) @font-lock-type-face
> 
>            (qualified_identifier
>             scope: (namespace_identifier) @font-lock-type-face)
> 
>            (operator_cast) type: (type_identifier) @font-lock-type-face))
>      [,@c-ts-mode--type-keywords] @font-lock-type-face)
> 
> The tree-sitter library returns a type_qualifier node for 'restrict':
> 
>        (parameter_declaration type: (type_identifier)
> 	declarator: 
> 	 (pointer_declarator *
> 	  (type_qualifier restrict)
> 	  declarator: (identifier)))
> 
> Yuan, can you look into fixing this, please?

Actually, it looks like we recognize the type qualifiers in C as
keywords, via a separate list.  So I've just added to that list the
two missing qualifiers: 'restrict' and '_Atomic', and that fixes this
bug for me.

Yuan, is that the right fix?  I've installed it on the emacs-29
branch.





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#63323: c-ts-mode does not know about `restrict'
  2023-05-06 12:19     ` Eli Zaretskii
@ 2023-05-06 22:54       ` Yuan Fu
  2023-05-07  5:14         ` Eli Zaretskii
  0 siblings, 1 reply; 5+ messages in thread
From: Yuan Fu @ 2023-05-06 22:54 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: luangruo, 63323



> On May 6, 2023, at 5:19 AM, Eli Zaretskii <eliz@gnu.org> wrote:
> 
>> Cc: 63323@debbugs.gnu.org
>> Date: Sat, 06 May 2023 13:31:03 +0300
>> From: Eli Zaretskii <eliz@gnu.org>
>> 
>> It looks like c-ts-mode thinks type qualifiers are possible only in
>> C++?
>> 
>>   :feature 'type
>>   `((primitive_type) @font-lock-type-face
>>     (type_identifier) @font-lock-type-face
>>     (sized_type_specifier) @font-lock-type-face
>>     ,@(when (eq mode 'cpp) <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
>>         '((type_qualifier) @font-lock-type-face
>> 
>>           (qualified_identifier
>>            scope: (namespace_identifier) @font-lock-type-face)
>> 
>>           (operator_cast) type: (type_identifier) @font-lock-type-face))
>>     [,@c-ts-mode--type-keywords] @font-lock-type-face)
>> 
>> The tree-sitter library returns a type_qualifier node for 'restrict':
>> 
>>       (parameter_declaration type: (type_identifier)
>> declarator: 
>>  (pointer_declarator *
>>   (type_qualifier restrict)
>>   declarator: (identifier)))
>> 
>> Yuan, can you look into fixing this, please?
> 
> Actually, it looks like we recognize the type qualifiers in C as
> keywords, via a separate list.  So I've just added to that list the
> two missing qualifiers: 'restrict' and '_Atomic', and that fixes this
> bug for me.
> 
> Yuan, is that the right fix?  I've installed it on the emacs-29
> branch.

I check tree-sitter-c’s grammar and it defines type_qualifier [1], so if you move (type_qualifier) @font-lock-type-face out of the check for cpp, if would work. Recognizing them as keywords also works. So both are technically correct. C-mode uses keyword face, so I think your fix is a-ok.

[1] you probably know this, but for completeness:

    type_qualifier: $ => choice(
      'const',
      'volatile',
      'restrict',
      '_Atomic'
    ),


Yuan




^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#63323: c-ts-mode does not know about `restrict'
  2023-05-06 22:54       ` Yuan Fu
@ 2023-05-07  5:14         ` Eli Zaretskii
  0 siblings, 0 replies; 5+ messages in thread
From: Eli Zaretskii @ 2023-05-07  5:14 UTC (permalink / raw)
  To: Yuan Fu; +Cc: luangruo, 63323-done

> From: Yuan Fu <casouri@gmail.com>
> Date: Sat, 6 May 2023 15:54:32 -0700
> Cc: luangruo@yahoo.com,
>  63323@debbugs.gnu.org
> 
> 
> 
> > Actually, it looks like we recognize the type qualifiers in C as
> > keywords, via a separate list.  So I've just added to that list the
> > two missing qualifiers: 'restrict' and '_Atomic', and that fixes this
> > bug for me.
> > 
> > Yuan, is that the right fix?  I've installed it on the emacs-29
> > branch.
> 
> I check tree-sitter-c’s grammar and it defines type_qualifier [1], so if you move (type_qualifier) @font-lock-type-face out of the check for cpp, if would work. Recognizing them as keywords also works. So both are technically correct. C-mode uses keyword face, so I think your fix is a-ok.
> 
> [1] you probably know this, but for completeness:
> 
>     type_qualifier: $ => choice(
>       'const',
>       'volatile',
>       'restrict',
>       '_Atomic'
>     ),

Right, they just copied from the C Standard.

Whether we want to stay with qualifiers in keywords or not depends on
whether we thing type qualifiers could or should be fontified
differently from keywords.  (What do other IDEs do with C type
qualifiers?)  Something to think for the future, I guess.

For now, I'm closing this bug.





^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-05-07  5:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <87r0rtkh2j.fsf.ref@yahoo.com>
2023-05-06  8:19 ` bug#63323: c-ts-mode does not know about `restrict' Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-05-06 10:31   ` Eli Zaretskii
2023-05-06 12:19     ` Eli Zaretskii
2023-05-06 22:54       ` Yuan Fu
2023-05-07  5:14         ` Eli Zaretskii

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.