eliben / pycparser

:snake: Complete C99 parser in pure Python
Other
3.24k stars 609 forks source link

Can't parse function declaration with unnamed static array #539

Closed gperciva closed 4 months ago

gperciva commented 6 months ago

Thanks for this library! I'm having great fun using it to nitpick some code.

Attempting to parse a function declaration with an unnamed static array:

from pycparser.c_parser import CParser
CParser().parse('void f(int [static 10]);')

fails with:

  File "/usr/local/lib/python3.9/site-packages/pycparser/plyparser.py", line 67, in _parse_error
    raise ParseError("%s: %s" % (coord, msg))
pycparser.plyparser.ParseError: :1:13: before: static

If we name the argument -- i.e. (int x[static 10]) -- then it works fine (since the example would be exactly the same as #21, the issue which prompted support for static arrays in the first place). Omitting the argument name is valid in C99.

I'm using pycparser 2.22. Thanks again for this library!

eliben commented 5 months ago

PRs to add support are welcome :)