diff options
author | Eric Blake <ebb9@byu.net> | 2008-12-24 14:34:06 -0700 |
---|---|---|
committer | Eric Blake <ebb9@byu.net> | 2008-12-24 14:34:06 -0700 |
commit | c557201fd9771b93dd5b3193af322d7d86a4cf45 (patch) | |
tree | 8c21ac989bceb3c1af68d01394b11edb59f1c148 | |
parent | 268aa74a4cd66160d4c589572294e50f455c2069 (diff) | |
download | m4-c557201fd9771b93dd5b3193af322d7d86a4cf45.tar.gz |
Relax eval as allowed by POSIX 2008.
* modules/evalparse.c (m4_evaluate): Warn, not error, on invalid
operator. Quote expression in warning.
* modules/mpeval.c (includes): Add quotearg.h.
* doc/m4.texinfo (Eval, Improved forloop): Update tests.
* NEWS: Update to reflect 1.6 support for `?:'.
Signed-off-by: Eric Blake <ebb9@byu.net>
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | NEWS | 6 | ||||
-rw-r--r-- | doc/m4.texinfo | 19 | ||||
-rw-r--r-- | modules/evalparse.c | 5 | ||||
-rw-r--r-- | modules/mpeval.c | 2 |
5 files changed, 28 insertions, 13 deletions
@@ -1,3 +1,12 @@ +2008-12-24 Eric Blake <ebb9@byu.net> + + Relax eval as allowed by POSIX 2008. + * modules/evalparse.c (m4_evaluate): Warn, not error, on invalid + operator. Quote expression in warning. + * modules/mpeval.c (includes): Add quotearg.h. + * doc/m4.texinfo (Eval, Improved forloop): Update tests. + * NEWS: Update to reflect 1.6 support for `?:'. + 2008-12-23 Eric Blake <ebb9@byu.net> Add debugmode(o) to control dumpdef output location. @@ -158,7 +158,7 @@ promoted to 2.0. first line to show the definition of the macro being expanded. *** The `eval' and `mpeval' builtins now support the following new - operators: `>>>', `\', `?:', and `,'. + operators: `>>>', `\', and `,'. *** The `maketemp' builtin now always warns that it is obsolete, even in GNU mode where it uses the same secure algorithm as `mkstemp', because of @@ -296,6 +296,10 @@ promoted to 2.0. context of a macro name, rather than acting on the empty string. This was already done for `define', `pushdef', `builtin', and `indir'. +** Enhance the `eval' builtin to understand the `?:' operator, and + downgrade a failed parse due to an unknown operator from an error to a + warning. + ** A number of portability improvements inherited from gnulib. * Noteworthy changes in Version 1.4.10b (2008-02-25) [beta] diff --git a/doc/m4.texinfo b/doc/m4.texinfo index 3d039f6d..c5e36dd5 100644 --- a/doc/m4.texinfo +++ b/doc/m4.texinfo @@ -7506,7 +7506,6 @@ precedence rules, but where older versions and some other implementations of @code{m4} require explicit parentheses to get the correct result: -@comment status: 1 @example eval(`1 == 2 > 0') @result{}1 @@ -7523,23 +7522,23 @@ eval(`(1 | 1) ^ 1') eval(`+ + - ~ ! ~ 0') @result{}1 eval(`++0') -@error{}m4:stdin:8: eval: invalid operator: ++0 +@error{}m4:stdin:8: Warning: eval: invalid operator: `++0' @result{} eval(`1 = 1') -@error{}m4:stdin:9: eval: invalid operator: 1 = 1 +@error{}m4:stdin:9: Warning: eval: invalid operator: `1 = 1' @result{} eval(`0 |= 1') -@error{}m4:stdin:10: eval: invalid operator: 0 |= 1 +@error{}m4:stdin:10: Warning: eval: invalid operator: `0 |= 1' @result{} eval(`2 || 1 / 0') @result{}1 eval(`0 || 1 / 0') -@error{}m4:stdin:12: Warning: eval: divide by zero: 0 || 1 / 0 +@error{}m4:stdin:12: Warning: eval: divide by zero: `0 || 1 / 0' @result{} eval(`0 && 1 % 0') @result{}0 eval(`2 && 1 % 0') -@error{}m4:stdin:14: Warning: eval: modulo by zero: 2 && 1 % 0 +@error{}m4:stdin:14: Warning: eval: modulo by zero: `2 && 1 % 0' @result{} @end example @@ -7567,9 +7566,9 @@ eval(`2 ** 0') @result{}1 eval(`0 ** 0') @result{} -@error{}m4:stdin:5: Warning: eval: divide by zero: 0 ** 0 +@error{}m4:stdin:5: Warning: eval: divide by zero: `0 ** 0' eval(`4 ** -2') -@error{}m4:stdin:6: Warning: eval: negative exponent: 4 ** -2 +@error{}m4:stdin:6: Warning: eval: negative exponent: `4 ** -2' @result{} eval(`2 || 4 ** -2') @result{}1 @@ -7632,7 +7631,7 @@ square(square(`5')` + 1') define(`foo', `666') @result{} eval(`foo / 6') -@error{}m4:stdin:11: Warning: eval: bad expression: foo / 6 +@error{}m4:stdin:11: Warning: eval: bad expression: `foo / 6' @result{} eval(foo / 6) @result{}111 @@ -9317,7 +9316,7 @@ forloop(`', `1', `2', ` odd iterator name') forloop(`i', `5 + 5', `0xc', ` 0x`'eval(i, `16')') @result{} 0xa 0xb 0xc forloop(`i', `a', `b', `non-numeric bounds') -@error{}m4:stdin:6: Warning: eval: bad input: (a) <= (b) +@error{}m4:stdin:6: Warning: eval: bad input: `(a) <= (b)' @result{} @end example diff --git a/modules/evalparse.c b/modules/evalparse.c index 9927e13a..ac30cfe9 100644 --- a/modules/evalparse.c +++ b/modules/evalparse.c @@ -940,6 +940,8 @@ m4_evaluate (m4 *context, m4_obstack *obs, size_t argc, m4_macro_args *argv) err = EXCESS_INPUT; } + if (err != NO_ERROR) + str = quotearg_style_mem (locale_quoting_style, str, M4ARGLEN (1)); switch (err) { case NO_ERROR: @@ -967,8 +969,7 @@ m4_evaluate (m4 *context, m4_obstack *obs, size_t argc, m4_macro_args *argv) break; case INVALID_OPERATOR: - /* POSIX requires an error here, unless XCU ERN 137 is approved. */ - m4_error (context, 0, 0, me, _("invalid operator: %s"), str); + m4_warn (context, 0, me, _("invalid operator: %s"), str); break; case DIVIDE_ZERO: diff --git a/modules/mpeval.c b/modules/mpeval.c index 63cd56a4..2d63d6ec 100644 --- a/modules/mpeval.c +++ b/modules/mpeval.c @@ -32,6 +32,8 @@ # include <gmp.h> #endif +#include "quotearg.h" + /* Rename exported symbols for dlpreload()ing. */ #define m4_builtin_table mpeval_LTX_m4_builtin_table #define m4_macro_table mpeval_LTX_m4_macro_table |