eliben / pycparser

:snake: Complete C99 parser in pure Python
Other
3.21k stars 612 forks source link

Allow abstract declarator "static" (GH issue #539) #545

Closed gperciva closed 2 months ago

gperciva commented 2 months ago

This is similar to:

allow "static" in array parameters (GH issue #21) aac7b27d7378cf45424b1f5f1b2b450c62636dde

which was revised shortly after in:

Fuller support for qualifiers in array dimensions. 8aad3186f39127ec9544f2b8c412de2bb7300fd4

The grammar is as defined in C99 6.7.6 Type names, or A.2.2 Declarations (6.7.6).

gperciva commented 2 months ago

I debated between adding p_direct_abstract_declarator_8(), vs. stuffing it in p_direct_abstract_declarator_3().

Putting it in _3 would keep the grammar in the same order as 6.7.6 -- namely, the static functions going between direct-abstract-declarator_opt [ type-qualifier-list_opt assignment-expression_opt ] and direct-abstract-declarator_opt [ * ]. However, when parsing the static as well, the _3() we get len(p) == 6, which is slightly awkward to handle in a function with currently has separate paths for len(p) > 4 or not.

In the end I put it in a new p_direct_abstract_declarator_8(), but I'm happy to revise that if requested.