ned14 / pcpp

A C99 preprocessor written in pure Python
Other
220 stars 41 forks source link

Copy tokens before concatenating #7

Closed nathanrw closed 6 years ago

nathanrw commented 6 years ago

Consider the following snippet:

#define FOO(A, B) \
  A ## B a; \
  A ## B b; \
  A ## B c;
FOO(x, y)

The output from pcpp is

x_y_y_y a; x_y_y_y b; x_y_y_y c;

and not

x_y a; x_y b; x_y c;

as you might expect. The problem looks to be that data shared between each 'A' substitution is being modified. Copying the rep[i-1] token before modifying it resolves the problem for me.

I've PR'd my change, if it's not the 'right' way to fix this I'm happy to contribute a different fix :)

ned14 commented 6 years ago

Great minds think alike. Fixed. Thanks!