The eval parser gives up at the first bad operator, but if that
operator occurs at a place where the parser was expecting a different
operator (')' or ':'), the error message was confusing, especially if
that other operator DOES appear later in the line. Thus, it's better
to reprioritize the errors to match.
* src/eval.c (primary): Favor bad op over missing ")".
(parse_expr): Favor bad op over missing ":".
* doc/m4.texi (Eval): Test it.
* THANKS: Update.
Reported-by: Nikolaos Chatzikonstantinou <[email protected]>
---
THANKS | 1 +
I've trimmed this change out of the email, since Nikolaus' name is
long enough to warrant reindentation of the rest of the file.
If I have a reason to revisit branch-1.4 (instead of focusing on
getting closer to a 1.6 release), remember that 1.4 doesn't have the
?: operator, so only half the patch is necessary.
doc/m4.texi | 6 ++++++
src/eval.c | 6 +++++-
3 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/THANKS b/THANKS
index 6898133e..097226e3 100644
--- a/THANKS
+++ b/THANKS
[...]
diff --git a/doc/m4.texi b/doc/m4.texi
index bdfe9c0c..81476bc8 100644
--- a/doc/m4.texi
+++ b/doc/m4.texi
@@ -7133,6 +7133,9 @@ Eval
eval(`0 |= 1')
@error{}m4:stdin:3: warning: eval: invalid operator: '0 |= 1'
@result{}
+eval(`(1 += 2)')
+@error{}m4:stdin:4: warning: eval: invalid operator: '(1 += 2)'
+@result{}
@end example
Note that some older @code{m4} implementations use @samp{^} as an
@@ -7227,6 +7230,9 @@ Eval
@result{}
eval(`2 ?: 3')
@result{}2
+eval(`1 ? 2-=3 : 4')
+@error{}m4:stdin:14: warning: eval: invalid operator: '1 ? 2-=3 : 4'
+@result{}
@end example
Within @var{expression}, (but not @var{radix} or @var{width}), numbers
diff --git a/src/eval.c b/src/eval.c
index bd10e250..163e2634 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -335,6 +335,8 @@ primary (int32_t *v1)
{
case ERROR:
return UNKNOWN_INPUT;
+ case BADOP:
+ return INVALID_OPERATOR;
case RIGHTP:
return er;
default:
@@ -526,7 +528,9 @@ parse_expr (int32_t *v1, eval_error er, unsigned min_prec)
break;
case QUESTION:
- if (et2 != COLON)
+ if (et2 == BADOP)
+ er = INVALID_OPERATOR;
+ else if (et2 != COLON)
er = MISSING_COLON;
else
{
base-commit: de2ad6ddc904ea07fe9a6f61fa9418b15ffbfc0b
prerequisite-patch-id: bcbc80d445cc1737da3b453d50426c9f944186c9
--
2.49.0
_______________________________________________
M4-patches mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/m4-patches