On Mon, May 12, 2025 at 11:36 AM Eric Blake <ebl...@redhat.com> wrote: > > On Mon, May 12, 2025 at 10:24:12AM -0500, Eric Blake wrote: > > On Mon, May 12, 2025 at 09:54:54AM -0500, Nikolaos Chatzikonstantinou wrote: > > > > $ echo 'eval(1 || (1/0))' | m4-1.4.20 > > > > 1 > > > > $ echo 'eval(1 || (1/0))' | m4p > > > > m4:stdin:1: divide by zero in eval: 1 || (1/0) > > > > 1 > > > > > > > > > > I have a file where I noted some of these here: > > > https://codeberg.org/annoyingusername/m4p/src/branch/main/tests/resources/eval_bugs.txt > > > > Useful. The '1 || (0 / 0)' bug was indeed fixed in 1.4.20. '1 || 2 > > &= 3' still complains about invalid operator, but that's intentional: > > &= is not a supported operator. But the complaint about '1 || (2 &= > > 3)') complaining about a missing right parenthesis (instead of a bad > > operator) is something I hadn't noticed before today, and something still > > present in 1.4.20. The parser is correctly detecting that the > > expression is not valid at the point it hits the invalid operator; but > > perhaps the error message could be improved (by stating that it > > expects ')' instead of '&=', for example). > > > > Writing a parser that handles only good expressions is easy. Writing > > a parser that provides sane error messages with useful suggestions > > when the parse fails is hard. Yours may be the first (indirect) bug > > report against 1.4.20! > > And here's my first proposed patch for your project: > > diff --git i/m4p/m4_eval.py w/m4p/m4_eval.py > index 91f97e7..6f2e565 100644 > --- i/m4p/m4_eval.py > +++ w/m4p/m4_eval.py > @@ -168,7 +168,7 @@ calc_grammar = """ > | "++" atom -> invalid_unary_operator > | atom "--" -> invalid_unary_operator > | atom "++" -> invalid_unary_operator > - | "(" equation ")" > + | "(" assignment ")" > > %import common.WS_INLINE > > > so that 'echo "eval((1&3))" | m4p' outputs 1 instead of an error.
I applied this and two more fixes (divert fix and -P fix) bumping to v0.3.3! Regards, Nikolaos Chatzikonstantinou