ned14 / pcpp

A C99 preprocessor written in pure Python
Other
215 stars 39 forks source link

## next to whitespace concatentes with the whitespace. #93

Open mrolle45 opened 8 months ago

mrolle45 commented 8 months ago

pcpp tends to keep whitespace tokens around when they are found in the source file. Normally, this is benign because they wind up getting passed to the output. In fact, sometimes (like whitespace between two identifiers) you want to see some space between them in an output file. However, when there's a ## operator, it's supposed to ignore any adjacent whitespace and stitch together the next tokens before and after it. pcpp doesn't do that. Take the example from C99 6.10.3.3.

#define hash_hash # ## #
#define mkstr(a) # a
#define in_between(a) mkstr(a)
#define join(c, d) in_between(c hash_hash d)
char p[] = join(x, y); // equivalent to
                       // char p[] = "x ## y";

Running pcpp on this example produces

char p[] = "x # # y";

The ## operator produces a single token with a " " value (two space characters). Incidentally, when this is later stringized by the mkstr() macro, it is replaced with a single space, correctly following C99 6.10.3.2. That is why you see "x # # y" rather than "x # # y".

ned14 commented 8 months ago

Thanks for the BR