Re: m4p: an implementation of GNU m4 in Python
Nikolaos Chatzikonstantinou <[email protected]> Mon, 12 May 2025 10:44:41 -0500
| Newsgroups | gmane.comp.gnu.m4.general |
|---|---|
| Message-ID | <CAAQmekcvFDHBb-kJWZKiSDUyo9=m2qka3oTjWs7y5tV3vFd6Hw@mail.gmail.com> |
--00000000000063b4c60634f23263 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, May 12, 2025, 10:36=E2=80=AFAM Eric Blake <[email protected]> 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 > > &=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. > Very nice! Thank you. Regards, Nikolaos Chatzikonstantinou > --00000000000063b4c60634f23263 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"auto"><div><div class=3D"gmail_quote gmail_quote_container"><di= v dir=3D"ltr" class=3D"gmail_attr">On Mon, May 12, 2025, 10:36=E2=80=AFAM E= ric Blake <<a href=3D"mailto:[email protected]">[email protected]</a>>= ; wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .= 8ex;border-left:1px #ccc solid;padding-left:1ex">On Mon, May 12, 2025 at 10= :24:12AM -0500, Eric Blake wrote:<br> > On Mon, May 12, 2025 at 09:54:54AM -0500, Nikolaos Chatzikonstantinou = wrote:<br> > > > $ echo 'eval(1 || (1/0))' | m4-1.4.20<br> > > > 1<br> > > > $ echo 'eval(1 || (1/0))' | m4p<br> > > > m4:stdin:1: divide by zero in eval: 1 || (1/0)<br> > > > 1<br> > > ><br> > > <br> > > I have a file where I noted some of these here:<br> > > <a href=3D"https://codeberg.org/annoyingusername/m4p/src/branch/m= ain/tests/resources/eval_bugs.txt" rel=3D"noreferrer noreferrer" target=3D"= _blank">https://codeberg.org/annoyingusername/m4p/src/branch/main/tests/res= ources/eval_bugs.txt</a><br> > <br> > Useful.=C2=A0 The '1 || (0 / 0)' bug was indeed fixed in 1.4.2= 0.=C2=A0 '1 || 2<br> > &=3D 3' still complains about invalid operator, but that's= intentional:<br> > &=3D is not a supported operator.=C2=A0 But the complaint about &#= 39;1 || (2 &=3D<br> > 3)') complaining about a missing right parenthesis (instead of a b= ad<br> > operator) is something I hadn't noticed before today, and somethin= g still<br> > present in 1.4.20.=C2=A0 The parser is correctly detecting that the<br= > > expression is not valid at the point it hits the invalid operator; but= <br> > perhaps the error message could be improved (by stating that it<br> > expects ')' instead of '&=3D', for example).<br> > <br> > Writing a parser that handles only good expressions is easy.=C2=A0 Wri= ting<br> > a parser that provides sane error messages with useful suggestions<br> > when the parse fails is hard.=C2=A0 Yours may be the first (indirect) = bug<br> > report against 1.4.20!<br> <br> And here's my first proposed patch for your project:<br> <br> diff --git i/m4p/m4_eval.py w/m4p/m4_eval.py<br> index 91f97e7..6f2e565 100644<br> --- i/m4p/m4_eval.py<br> +++ w/m4p/m4_eval.py<br> @@ -168,7 +168,7 @@ calc_grammar =3D """<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 | "++" atom=C2=A0 =C2=A0 =C2= =A0 =C2=A0 -> invalid_unary_operator<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 | atom "--"=C2=A0 =C2=A0 =C2= =A0 =C2=A0 -> invalid_unary_operator<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 | atom "++"=C2=A0 =C2=A0 =C2= =A0 =C2=A0 -> invalid_unary_operator<br> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0| "(" equation ")"<b= r> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0| "(" assignment ")"= <br> <br> =C2=A0 =C2=A0 =C2=A0%import common.WS_INLINE<br> <br> <br> so that 'echo "eval((1&3))" | m4p' outputs 1 instead = of an error.<br></blockquote></div></div><div dir=3D"auto"><br></div><div d= ir=3D"auto">Very nice! Thank you.</div><div dir=3D"auto"><br></div><div dir= =3D"auto">Regards,</div><div dir=3D"auto">Nikolaos Chatzikonstantinou</div>= <div dir=3D"auto"><div class=3D"gmail_quote gmail_quote_container"><blockqu= ote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc s= olid;padding-left:1ex"> </blockquote></div></div></div> --00000000000063b4c60634f23263--