eliben / pycparser

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

#Pragmas in statements raise error #478

Open ldore-ks opened 2 years ago

ldore-ks commented 2 years ago

Pycparser raises a parser error when trying to parse statements that contain #pragma.
A typical example comes from Apple's iPhoneOS.sdk/usr/include/sys/event.h:371 (SDK 13).

The relevant sys/event.h:371 source code is:

struct knote;
SLIST_HEAD(klist, knote);

Once pre-processed, the SLIST_HEAD macro expands to:

struct knote;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wnullability-completeness"
 struct klist { struct knote *slh_first; }
#pragma clang diagnostic pop
 ;

Note the #pragma that comes before the end-of-statement ;.

When parsing, pycparser raises the following error:

pycparser.plyparser.ParseError: Platforms/iphoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/sys/event.h:371:2: before: pragma