!EVAL
[pspp] / src / language / lexer / macro.c
index 95d86a6e9643adfec2030db68fc9bfdd15e0de41..e900a5e7d1a542f0ec1faedaa813b0bd9ac883dc 100644 (file)
@@ -142,6 +142,7 @@ macro_tokens_from_string (struct macro_tokens *mts, const struct substring src,
         {
           if (token->type != SCAN_SKIP)
             {
+              printf ("error\n");
               /* XXX report error */
             }
         }
@@ -995,6 +996,19 @@ expand_macro_function (struct parse_macro_function_ctx *ctx,
       free (upper);
       ds_destroy (&tmp);
     }
+  else if (parse_macro_function (ctx, &args, ss_cstr ("!eval"), 1, 1,
+                                 input_consumed))
+    {
+      struct macro_tokens mts = { .n = 0 };
+      macro_tokens_from_string (&mts, ss_cstr (args.strings[0]),
+                                SEG_MODE_INTERACTIVE /* XXX */);
+      struct macro_tokens exp = { .n = 0 };
+      macro_expand (&mts, ctx->nesting_countdown - 1, ctx->macros,
+                    ctx->me, ctx->expand, &exp);
+      macro_tokens_to_representation (&exp, output);
+      macro_tokens_uninit (&exp);
+      macro_tokens_uninit (&mts);
+    }
   else if (ctx->n_input > 0
            && ctx->input[0].token.type == T_MACRO_ID
            && ss_equals_case (ctx->input[0].token.string, ss_cstr ("!null")))
@@ -1015,13 +1029,6 @@ macro_expand (const struct macro_tokens *mts,
               const struct macro_expander *me, bool *expand,
               struct macro_tokens *exp)
 {
-  /* Macro expansion:
-
-     - Macro names in macro bodies are not expanded by default.  !EVAL()
-       expands them.
-
-     - Macro names in arguments to macro invocations (outside of macro bodies)
-       are expanded by default, unless !NOEXPAND. */
   if (nesting_countdown <= 0)
     {
       printf ("maximum nesting level exceeded\n");