Skip to content

feature: Support for C23's typeof() #273

@richarno

Description

@richarno

Did you check the tree-sitter docs?

Is your feature request related to a problem? Please describe.

Hello,
I tried to implement support for the "typeof" C23 feature.
The following snippet of code is valid:

typeof(int) a;

However it raises an error when parsed with the tree-sitter-c grammar.

Describe the solution you'd like

I tried to add the following line in the grammar.js file, in type_specifier:

  $.typeof_specifier,

And later in that same file I added:

    typeof_specifier: $ => seq(
      choice('__typeof', '__typeof__'),
      '(',
      choice($.expression, $.type_descriptor),
      ')',
    ),

Unfortunately this is not enough: The grammar still parses the line above as a function declaration, and obviously it fails and produces an ERROR node.
How can I force the parsing of a typeof(x) as a type_specifier instead of a function declaration?

Thanks.

Describe alternatives you've considered

None considered.

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions