macro: Properly parse !ENCLOSE keyword arguments.
authorBen Pfaff <blp@cs.stanford.edu>
Tue, 20 Jul 2021 05:19:41 +0000 (22:19 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Tue, 20 Jul 2021 05:19:41 +0000 (22:19 -0700)
The opening delimiter was being included in the argument.

Thanks to Frans Houweling for reporting this bug.

src/language/lexer/macro.c
tests/language/control/define.at

index 85706ce3a4286b8561f06e80bad5852d2270f1a3..22e92ca05e911c32e289aaedf081a664d4fb2c46 100644 (file)
@@ -510,7 +510,7 @@ macro_set_add (struct macro_set *set, struct macro *m)
   hmap_insert (&set->macros, &m->hmap_node, hash_macro_name (m->name));
 }
 \f
-/* Macro call parsing.. */
+/* Macro call parsing. */
 
 enum mc_state
   {
@@ -752,7 +752,7 @@ mc_equals (struct macro_call *mc, const struct macro_token *mt,
 
   if (token->type == T_EQUALS)
     {
-      mc->state = MC_ARG;
+      mc->state = mc->param->arg_type == ARG_ENCLOSE ? MC_ENCLOSE : MC_ARG;
       return 0;
     }
 
index 255a0dc285c6ad8c8b5b6d555463ddffce0ce0f8..26df856673a189ca3c9cb9f6094b8f9d40191e67 100644 (file)
@@ -340,7 +340,7 @@ note: unexpanded token "="
 ])
 AT_CLEANUP
 
-AT_SETUP([macro expansion - !CHAREND('/') keyword arguments])
+AT_SETUP([macro expansion - !CHAREND keyword arguments])
 AT_KEYWORDS([CHAREND])
 AT_DATA([define.sps], [dnl
 DEFINE !k(arg1 = !CHAREND('/')
@@ -365,7 +365,7 @@ k(, )
 ])
 AT_CLEANUP
 
-AT_SETUP([macro expansion - !CHAREND('/') keyword arguments - negative])
+AT_SETUP([macro expansion - !CHAREND keyword arguments - negative])
 AT_KEYWORDS([CHAREND])
 AT_DATA([define.sps], [dnl
 DEFINE !k(arg1 = !CHAREND('/')
@@ -428,6 +428,172 @@ note: unexpanded token "y"
 ])
 AT_CLEANUP
 
+AT_SETUP([macro expansion - !ENCLOSE keyword arguments])
+AT_KEYWORDS([ENCLOSE])
+AT_DATA([define.sps], [dnl
+DEFINE !k(arg1 = !ENCLOSE('(',')')
+         /arg2 = !ENCLOSE('{','}'))
+k(!arg1, !arg2)
+!ENDDEFINE.
+DEBUG EXPAND.
+!k arg1=(x) arg2={y}.
+!k arg1=(x).
+!k arg2={y}.
+!k.
+])
+AT_CAPTURE_FILE([define.sps])
+AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
+k(x, y)
+
+k(x, )
+
+k(, y)
+
+k(, )
+])
+AT_CLEANUP
+
+AT_SETUP([macro expansion - !ENCLOSE keyword arguments - negative])
+AT_KEYWORDS([ENCLOSE])
+AT_DATA([define.sps], [dnl
+DEFINE !k(arg1 = !ENCLOSE('(',')')
+         /arg2 = !ENCLOSE('{','}'))
+k(!arg1, !arg2)
+!ENDDEFINE.
+DEBUG EXPAND.
+!k arg1.
+!k arg1=.
+!k arg1=x.
+!k arg1=(x.
+!k arg1=(x) arg2.
+!k arg1=(x) arg2=.
+!k arg1=(x) arg2=y.
+!k arg1=(x) arg2=(y.
+])
+AT_CAPTURE_FILE([define.sps])
+AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
+define.sps:6.8: error: DEBUG EXPAND: Found `.' while expecting `=' reading
+argument !arg1 to macro !k.
+
+note: unexpanded token "!k"
+
+note: unexpanded token "arg1"
+
+define.sps:7.9: error: DEBUG EXPAND: Found `.' while expecting `@{:@' reading
+argument !arg1 to macro !k.
+
+note: unexpanded token "!k"
+
+note: unexpanded token "arg1"
+
+note: unexpanded token "="
+
+define.sps:8.9: error: DEBUG EXPAND: Found `x' while expecting `@{:@' reading
+argument !arg1 to macro !k.
+
+note: unexpanded token "!k"
+
+note: unexpanded token "arg1"
+
+note: unexpanded token "="
+
+note: unexpanded token "x"
+
+define.sps:9.11: error: DEBUG EXPAND: Unexpected end of command reading
+argument !arg1 to macro !k.
+
+note: unexpanded token "!k"
+
+note: unexpanded token "arg1"
+
+note: unexpanded token "="
+
+note: unexpanded token "@{:@"
+
+note: unexpanded token "x"
+
+define.sps:10.17: error: DEBUG EXPAND: Found `.' while expecting `=' reading
+argument !arg2 to macro !k.
+
+note: unexpanded token "!k"
+
+note: unexpanded token "arg1"
+
+note: unexpanded token "="
+
+note: unexpanded token "@{:@"
+
+note: unexpanded token "x"
+
+note: unexpanded token "@:}@"
+
+note: unexpanded token "arg2"
+
+define.sps:11.18: error: DEBUG EXPAND: Found `.' while expecting `{' reading
+argument !arg2 to macro !k.
+
+note: unexpanded token "!k"
+
+note: unexpanded token "arg1"
+
+note: unexpanded token "="
+
+note: unexpanded token "@{:@"
+
+note: unexpanded token "x"
+
+note: unexpanded token "@:}@"
+
+note: unexpanded token "arg2"
+
+note: unexpanded token "="
+
+define.sps:12.18: error: DEBUG EXPAND: Found `y' while expecting `{' reading
+argument !arg2 to macro !k.
+
+note: unexpanded token "!k"
+
+note: unexpanded token "arg1"
+
+note: unexpanded token "="
+
+note: unexpanded token "@{:@"
+
+note: unexpanded token "x"
+
+note: unexpanded token "@:}@"
+
+note: unexpanded token "arg2"
+
+note: unexpanded token "="
+
+note: unexpanded token "y"
+
+define.sps:13.18: error: DEBUG EXPAND: Found `@{:@' while expecting `{' reading
+argument !arg2 to macro !k.
+
+note: unexpanded token "!k"
+
+note: unexpanded token "arg1"
+
+note: unexpanded token "="
+
+note: unexpanded token "@{:@"
+
+note: unexpanded token "x"
+
+note: unexpanded token "@:}@"
+
+note: unexpanded token "arg2"
+
+note: unexpanded token "="
+
+note: unexpanded token "@{:@"
+
+note: unexpanded token "y"
+])
+AT_CLEANUP
+
 dnl Keep this test in sync with the examples for !BLANKS in the manual.
 AT_SETUP([macro expansion - !BLANKS])
 AT_KEYWORDS([BLANKS])