const char *function,
struct string_array *args)
{
- if (n < 2 || mts[1].token.type != T_LPAREN)
- {
- macro_error (me->stack, n > 1 ? &mts[1] : NULL,
- _("`(' expected following %s."), function);
- return 0;
- }
+ assert (n >= 2 && mts[1].token.type == T_LPAREN);
for (size_t i = 2; i < n; )
{
MF_HEAD,
MF_INDEX,
MF_LENGTH,
- MF_NULL,
MF_QUOTE,
MF_SUBSTR,
MF_TAIL,
[MF_HEAD] = { "!HEAD", 1, 1 },
[MF_INDEX] = { "!INDEX", 2, 2 },
[MF_LENGTH] = { "!LENGTH", 1, 1 },
- [MF_NULL] = { "!NULL", 0, 0 },
[MF_QUOTE] = { "!QUOTE", 1, 1 },
[MF_SUBSTR] = { "!SUBSTR", 2, 3 },
[MF_TAIL] = { "!TAIL", 1, 1 },
[MF_UPCASE] = { "!UPCASE", 1, 1 },
};
- /* Is this a macro function? */
+ if (lex_id_match_n (ss_cstr ("!NULL"), input[0].token.string, 4))
+ return 1;
+
+ if (n_input < 2 || input[1].token.type != T_LPAREN)
+ {
+ /* Only consider macro functions when the name is followed by '('. */
+ return 0;
+ }
+
+ /* Is this a macro function name? */
const struct macro_function *mf;
for (mf = mfs; ; mf++)
{
}
enum macro_function_id id = mf - mfs;
- if (id == MF_NULL)
- return 1;
struct string_array args = STRING_ARRAY_INITIALIZER;
size_t n_consumed = parse_function_args (me, input, n_input, mf->name, &args);
])
AT_CLEANUP
+AT_SETUP([macro name overlaps with macro function name])
+dnl !len is short for macro function !LENGTH. PSPP used to
+dnl reject the following with "`(' expected following !LENGTH".
+dnl Now PSPP only consider macro functions when the name is
+dnl followed by '('.
+AT_DATA([define.sps], [dnl
+DEFINE !len() 5 !ENDDEFINE.
+DEFINE !x() !eval(!len) !ENDDEFINE.
+DEBUG EXPAND.
+!x
+])
+AT_CHECK([pspp -O format=csv define.sps --testing-mode], [0], [dnl
+5
+])
+AT_CLEANUP
+
AT_SETUP([generic macro function syntax errors])
AT_DATA([define.sps], [dnl
-DEFINE !a() !SUBSTR !ENDDEFINE.
-DEFINE !b() !SUBSTR x !ENDDEFINE.
+
+
DEFINE !c() !SUBSTR(1x) !ENDDEFINE.
DEFINE !d() !SUBSTR(1 !ENDDEFINE.
DEFINE !narg_blanks() !BLANKS() !ENDDEFINE.
DEFINE !narg_upcase() !UPCASE() !ENDDEFINE.
dnl )
DEBUG EXPAND.
-!a.
-!b.
+
+
!c.
!d.
!narg_blanks.
!narg_upcase.
])
AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
-define.sps:1: In the expansion of `!a',
-define.sps:18.1-18.2: error: DEBUG EXPAND: `@{:@' expected following !SUBSTR.
-
-!SUBSTR
-
-define.sps:2: At `x' in the expansion of `!b',
-define.sps:19.1-19.2: error: DEBUG EXPAND: `@{:@' expected following !SUBSTR.
-
-!SUBSTR x
-
define.sps:3: At `x' in the expansion of `!c',
define.sps:20.1-20.2: error: DEBUG EXPAND: `,' or `@:}@' expected in call to macro
function !SUBSTR.