On Mon May 14 18:25:51 2012, doy@tozt.net wrote:
> On Mon, May 14, 2012 at 04:44:13PM -0700, Father Chrysostomos via RT
> wrote:
> > On Mon May 14 13:24:02 2012, doy@tozt.net wrote:
> > > The latter. 'if' should try to parse any elsif and else blocks as
> much
> > > as it can in a way that makes sense with its own syntax, and if
> that
> > > fails, then it can fall back to ignoring them and letting the
> parser
> > > treat them as normal keywords. Guessing this based on the
> existence of
> > > the opening brace feels fragile (although I can't come up with a
> way it
> > > would handle it incorrectly off the top of my head).
> >
> > After thinking about this for a while (and even writing tests!), I
> donât
> > think this can work in practice.
> >
> > This is the curse of having a self-modifying parser (which what Perl
> > has, when BEGIN is involved).
> >
> > Letâs take a theoretical, but useless, example. (I could come up
> with
> > better examples, but that would take longer, without proving the
> point
> > any better.) Suppose we have an âelseâ keyword that allows the
> block
> > following it to be terminated with ] instead of }, like this:
> >
> > else { do_this(); do_that(); ]
> >
> > Obviously, âifâ canât parse that. If it tries to, it will be too
> late
> > to backtrack by the time it sees â]â, because we might have this:
> >
> > else { BEGIN { $^X = "bash" }; ]
> >
> > If the special âelseâ keyword gives its own meaning to BEGIN, it
> will be
> > too late, because the default meaning has already kicked in.
> >
> > So I think looking for /(?:CORE::)*else\s*\{/ is our best choice.
>
> Hmmm, good point. Backtracking isn't really a thing we can (easily)
> do.
> A better idea may be to just disallow elsif and else from being
> overridden at all. Why do we need to allow this? (It's not really
> quite
> parallel to continue, as I mentioned earlier.)
We already allow it with PL_keyword_plugin. And that is already
problematic, so I think it ought to be addressed at the same time as
continue.
We could make else and elsif into exceptions, but the whole point of
this proposal was to avoid these types of exceptions.
--
Father Chrysostomos
---
via perlbug: queue: perl5 status: open
https://rt.perl.org:443/rt3/Ticket/Display.html?id=108286
Thread Previous
|
Thread Next