Match C's preprocessor semantics for token pasting with '##'.
authorDale Weiler <weilercdale@gmail.com>
Mon, 7 Apr 2014 10:00:04 +0000 (06:00 -0400)
committerDale Weiler <weilercdale@gmail.com>
Mon, 7 Apr 2014 10:00:04 +0000 (06:00 -0400)
ftepp.c
tests/pmacros.qc
tests/ppcat.qc

diff --git a/ftepp.c b/ftepp.c
index 44c1ebb1b5392bde5f5842a0a1d23ff8955d23f4..c574f03bb99d518191a243a8155e60f41a9e7c76 100644 (file)
--- a/ftepp.c
+++ b/ftepp.c
@@ -763,6 +763,7 @@ static bool ftepp_macro_expand(ftepp_t *ftepp, ppmacro *macro, macroparam *param
     lex_file *inlex;
 
     bool      old_inmacro;
+    bool      strip = false;
 
     int nextok;
 
@@ -827,6 +828,7 @@ static bool ftepp_macro_expand(ftepp_t *ftepp, ppmacro *macro, macroparam *param
                     if (nextok == '#') {
                         /* raw concatenation */
                         ++o;
+                        strip = true;
                         break;
                     }
                     if ( (nextok == TOKEN_IDENT    ||
@@ -835,6 +837,7 @@ static bool ftepp_macro_expand(ftepp_t *ftepp, ppmacro *macro, macroparam *param
                         macro_params_find(macro, macro->output[o+1]->value, &pi))
                     {
                         ++o;
+                        
                         ftepp_stringify(ftepp, &params[pi]);
                         break;
                     }
@@ -845,7 +848,14 @@ static bool ftepp_macro_expand(ftepp_t *ftepp, ppmacro *macro, macroparam *param
                 ftepp_out(ftepp, "\n", false);
                 break;
             default:
-                ftepp_out(ftepp, out->value, false);
+                buffer = out->value;
+                if (vec_size(macro->output) > o + 1 && macro->output[o+1]->token == '#')
+                    buffer++;
+                if (strip) {
+                    while (util_isspace(*buffer)) buffer++;
+                    strip = false;
+                }
+                ftepp_out(ftepp, buffer, false);
                 break;
         }
     }
index 1ec0780ae24443cac920cddd0d190618e93bd1d9..9bac53983cfd94803270d63b36f1ead0e5d9990c 100644 (file)
@@ -26,7 +26,7 @@
 
 #   define ALPHA(SEL) ALPHA_##SEL
 
-#   define ABC ALPHA(a)##ALPHA(b)##ALPHA(c)
+#   define ABC ALPHA(a)ALPHA(b)ALPHA(c)
 
     void() main = {
         if (ABC == "abc")
index ca92060d2005d71570aac8827eab4713296a9e68..dc2826925701d5bdafb9cc4bf136a464239fa594 100644 (file)
@@ -8,6 +8,6 @@ REDIR(CAT(hello, world), CAT(world, hello))
 SCONS(hello, world)
 
 #define FOO(X) X##X
-#define BAR(X) FOO(X)##FOO(X)
+#define BAR(X) FOO(X)FOO(X)
 
-REDIR(BAR(hello), BAR(world))
+REDIR(BAR(hello),BAR(world))