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 | Thread Next
From:
Zefram
Date:
March 25, 2014 17:03
Subject:
Re: [perl #121501] Empty code block {} causes syntax error(misparsed as anonymous hash constructor?) before 'sub'
Message ID:
20140325170333.GG18071@fysh.org
Eric Brine wrote:
>"{" is determined to be a hash constructor by looking ahead and seeing "}".
>It would have to look even ahead further to determine a syntax error
>follows that. I don't know how feasible that is.

Looking ahead more than one token is not feasible.  If I wanted to
make {} DWIM in this manner, I'd parse "{}" as a special production,
and resolve it as block or hash constructor grammatically.  Of course,
that would introduce new ambiguities into the grammar, requiring some
fiddling to keep the really-ambiguous cases (such as sub { {} }) resolved
the way they are now.

Overall I don't think it's worth the trouble.  Just use "{;" or "+{"
when there's doubt.

-zefram

Thread Previous | Thread Next


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