antlr / grammars-v4

Grammars written for ANTLR v4; expectation that the grammars are free of actions.
MIT License
10.12k stars 3.69k forks source link

CPP14 Grammar; struct/union field initialiation with designators #1869

Open mycroft8 opened 3 years ago

mycroft8 commented 3 years ago

Just documenting this... C (since C99) and C+ (since 2014 (partial) and the upcoming standard) support initializing fields of structs/unions by name. This syntax is used by the glibc pthread.h file, among others. The syntax looks somewhat like a regular initialization block

{ .field1 = value1, .field2 = value2, etc. }

Contextually this looks like a Identifier starting with a .; and I'm getting unrecognized errors thrown by the Antlr CPP14 lexer.
Found while working on my experimental C++ preprocessor using the CPP14 lexer and an overloaded nextToken method.

Dave

Marti2203 commented 3 years ago

Hi, assuming I got this right - I just need to rewrite initializer clause to this, I am going to push this to a PR I am working on.

initializerClause:
    bracedInitList
    | (Dot Identifier Assign)? expression;