fix up macro expansion
authorBen Pfaff <blp@cs.stanford.edu>
Mon, 28 Jun 2021 06:09:00 +0000 (23:09 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Mon, 28 Jun 2021 06:09:00 +0000 (23:09 -0700)
src/language/lexer/lexer.c
src/language/lexer/macro.c
tests/language/control/define.at

index e8a2677986f229c95b9765fa79ce4689494b2416..6e9bba43a789042259132b1ba7a3bde63407c6e8 100644 (file)
@@ -1842,7 +1842,9 @@ lex_source_get (const struct lex_source *src_)
         .representation = ss_buffer (&src->buffer[start - src->tail],
                                      end - start),
       };
+      src->middle += middle_ofs + 1;
       n_call = macro_expander_add (me, &mt);
+      src->middle -= middle_ofs + 1;
     }
   if (n_call < 0)
     {
@@ -1863,7 +1865,7 @@ lex_source_get (const struct lex_source *src_)
   const struct lex_token *call_first
     = &src->tokens[src->middle & (src->capacity - 1)];
   const struct lex_token *call_last
-    = &src->tokens[(src->middle + n_call) & (src->capacity - 1)];
+    = &src->tokens[(src->middle + n_call - 1) & (src->capacity - 1)];
   size_t call_pos = call_first->token_pos;
   size_t call_len = (call_last->token_pos + call_last->token_len) - call_pos;
   size_t line_pos = call_first->line_pos;
index bee23c999cb1be7f6254d69cdf315eea6206319c..786aeea54a3429645dff5094fd644a37348e0bd2 100644 (file)
@@ -1525,7 +1525,7 @@ macro_parse_let (const struct macro_token *tokens, size_t n_tokens,
   if (is_macro_keyword (var_name)
       || macro_find_parameter_by_name (me->macro, var_name))
     {
-      printf ("cannot use argument name or macro keyword as !LET variable\n");
+      printf ("cannot use argument name or macro keyword %.*s as !LET variable\n", (int) var_name.length, var_name.string);
       return 0;
     }
   p++;
@@ -1591,7 +1591,7 @@ macro_expand_do (const struct macro_token *tokens, size_t n_tokens,
   if (is_macro_keyword (var_name)
       || macro_find_parameter_by_name (me->macro, var_name))
     {
-      printf ("cannot use argument name or macro keyword as !DO variable\n");
+      printf ("cannot use argument name or macro keyword %.*s as !DO variable\n", (int) var_name.length, var_name.string);
       return 0;
     }
   p++;
index adfd18c8848e6c4d1399026ffdfddcbaf51b9927..930b9ddf4c4bc3f55452a872dea988cced758c3e 100644 (file)
@@ -853,8 +853,8 @@ DEBUG EXPAND.
 !for2 x=1 y=5.
 ])
 AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
-cannot use argument name or macro keyword as !DO variable
-cannot use argument name or macro keyword as !DO variable
+cannot use argument name or macro keyword !x as !DO variable
+cannot use argument name or macro keyword !noexpand as !DO variable
 !DO 1 = 1 !TO 5 !var !DOEND.
 
 !DO !noexpand = 1 !TO 5 !var !DOEND.
@@ -1061,14 +1061,14 @@ DEFINE !macro2()
 !ENDDEFINE.
 
 DEBUG EXPAND.
-!macro 1.
+!macro x=1.
 !macro2.
 ])
 AT_CHECK([pspp --testing-mode define.sps -O format=csv], [0], [dnl
-cannot use argument name or macro keyword as !LET variable
-cannot use argument name or macro keyword as !LET variable
+cannot use argument name or macro keyword !x as !LET variable
+cannot use argument name or macro keyword !do as !LET variable
 expected macro variable name following !DO
-!LET =
+!LET 1 = 1
 
 !LET !do = x
 ])