fox-it / dissect.cstruct

A Dissect module implementing a parser for C-like structures.
Apache License 2.0
36 stars 16 forks source link

Incorrect parsing of multiple declarators in a single declaration #85

Open d3dave opened 4 months ago

d3dave commented 4 months ago

The definition struct X { int x : 16, y : 16; } gets parsed incorrectly into the following tokens:

[<Token.STRUCT value='struct'>,
 <Token.IDENTIFIER value='X'>,
 <Token.BLOCK value='{'>,
 <Token.IDENTIFIER value='int'>,
 <Token.IDENTIFIER value='x'>,
 <Token.NAME value='y : 16'>,
 <Token.EOL value=';'>,
 <Token.BLOCK value='}'>]

As you can see, x : 16 is mistakenly truncated and treated as an identifier instead of a name like y : 16.

Schamper commented 4 months ago

This is unfortunately a known limitation of the current parser. Would love to support this since I also regularly run into this issue. Not sure how feasible it is with the current parser though. Ideally we get a better parser with perhaps a proper AST down the line.