develooper Front page | perl.perl5.porters | Postings from March 2014

Re: [perl #121501] Empty code block {} causes syntax error (misparsed as anonymous hash constructor?) before 'sub'

Thread Previous
From:
Ed Avis
Date:
March 25, 2014 20:49
Subject:
Re: [perl #121501] Empty code block {} causes syntax error (misparsed as anonymous hash constructor?) before 'sub'
Message ID:
loom.20140325T214639-340@post.gmane.org
Aristotle Pagaltzis <pagaltzis <at> gmx.de> writes:

>>you can start
>>out with a working program, comment out lines of code one at a time,
>>and then arrive at a syntax error when the number of statements in the
>>block reaches 0.
> 
>But similar cases exist for hash construction. As long as the syntax is
>ambiguous you can only trade some surprising cases in the block case for
>some surprising cases in the hash case,

But the syntax is not ambiguous.  In C<{} sub foo {}> there can be no
doubt that the first {} is a code block and not a hash constructor.
If you try taking it as a hash constructor you get a syntax error.
The problem is that Perl's parser jumps one way based on a heuristic and
then isn't smart enough to try the other possibility.

-- 
Ed Avis <eda@waniasset.com>


Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About