Re: m4p: an implementation of GNU m4 in Python

Nikolaos Chatzikonstantinou <[email protected]> Mon, 12 May 2025 22:57:07 -0400
Newsgroups gmane.comp.gnu.m4.general
Message-ID <CAAQmekfO6yg8Bp1AARuRZmhTVpo_e5PxvctTCaCWzhCAqEB5Bw@mail.gmail.com>
On Mon, May 12, 2025 at 11:36=E2=80=AFAM Eric Blake <[email protected]> wro=
te:
>
> 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 w=
rote:
> > > > $ 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/resou=
rces/eval_bugs.txt
> >
> > Useful.  The '1 || (0 / 0)' bug was indeed fixed in 1.4.20.  '1 || 2
> > &=3D 3' still complains about invalid operator, but that's intentional:
> > &=3D is not a supported operator.  But the complaint about '1 || (2 &=
=3D
> > 3)') complaining about a missing right parenthesis (instead of a bad
> > operator) is something I hadn't noticed before today, and something sti=
ll
> > 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 '&=3D', 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 =3D """
>           | "++" 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