exit (status);
}
-/* Report a syntax error and exit. */
-static void
-syntax_error (void)
-{
- die (EXPR_INVALID, 0, _("syntax error"));
-}
#if ! HAVE_GMP
/* Report an integer overflow for operation OP and exit. */
v = eval (true);
if (!nomoreargs ())
- syntax_error ();
+ die (EXPR_INVALID, 0, _("syntax error: unexpected argument %s"),
+ quotearg_n_style (0, locale_quoting_style, *args));
+
printv (v);
return null (v);
return *args == 0;
}
+/* Report missing operand.
+ There is an implicit assumption that there was a previous argument,
+ and (args-1) is valid. */
+static void
+require_more_args (void)
+{
+ if (nomoreargs ())
+ die (EXPR_INVALID, 0, _("syntax error: missing argument after %s"),
+ quotearg_n_style (0, locale_quoting_style, *(args-1)));
+}
+
+
#ifdef EVAL_TRACE
/* Print evaluation trace and args remaining. */
#ifdef EVAL_TRACE
trace ("eval7");
#endif
- if (nomoreargs ())
- syntax_error ();
+ require_more_args ();
if (nextarg ("("))
{
v = eval (evaluate);
+ if (nomoreargs ())
+ die (EXPR_INVALID, 0, _("syntax error: expecting ')' after %s"),
+ quotearg_n_style (0, locale_quoting_style, *(args-1)));
if (!nextarg (")"))
- syntax_error ();
+ die (EXPR_INVALID, 0, _("syntax error: expecting ')' instead of %s"),
+ quotearg_n_style (0, locale_quoting_style, *args));
return v;
}
if (nextarg (")"))
- syntax_error ();
+ die (EXPR_INVALID, 0, _("syntax error: unexpected ')'"));
return str_value (*args++);
}
#endif
if (nextarg ("+"))
{
- if (nomoreargs ())
- syntax_error ();
+ require_more_args ();
return str_value (*args++);
}
else if (nextarg ("length"))
['bre61', '"acd" : "a\\(b\\)?c\\1d"', {OUT => ''}, {EXIT => 1}],
['bre62', '-- "-5" : "-\\{0,1\\}[0-9]*\$"', {OUT => '2'}],
- ['fail-b', '9 9', {ERR => "$prog: syntax error\n"},
- {EXIT => 2}],
+ ['fail-b', '9 9',
+ {ERR => "$prog: syntax error: unexpected argument '9'\n"}, {EXIT => 2}],
['fail-c', {ERR => "$prog: missing operand\n"
. "Try '$prog --help' for more information.\n"},
{EXIT => 2}],
['bignum-sub2', "$big_sum - $big", {OUT => $big_p1}],
['bignum-mul', "$big_p1 '*' $big", {OUT => $big_prod}],
['bignum-div', "$big_prod / $big", {OUT => $big_p1}],
+
+
+ # Test syntax error messages
+ ['se1', "2 a", {EXIT=>2},
+ {ERR=>"$prog: syntax error: unexpected argument 'a'\n"}],
+ ['se2', "2 '+'", {EXIT=>2},
+ {ERR=>"$prog: syntax error: missing argument after '+'\n"}],
+ ['se3', "2 :", {EXIT=>2},
+ {ERR=>"$prog: syntax error: missing argument after ':'\n"}],
+ ['se4', "length", {EXIT=>2},
+ {ERR=>"$prog: syntax error: missing argument after 'length'\n"}],
+ ['se5', "'(' 2 ", {EXIT=>2},
+ {ERR=>"$prog: syntax error: expecting ')' after '2'\n"}],
+ ['se6', "'(' 2 a", {EXIT=>2},
+ {ERR=>"$prog: syntax error: expecting ')' instead of 'a'\n"}],
);
# If using big numbers fails, remove all /^bignum-/ tests