Yes, I actually tried to do pos++ recently, and quickly realised why
it didn’t work.
But ‘pos++;’ could only mean one thing, so why shouldn’t perl do that?
Making this work for the unambiguous cases that are currently syntax
errors is not that hard, and I can make it generic enough to work with
custom lvalue subs, too.
The only drawback I can think of is that, while the first line here
will work, the second will not, since it is not sufficiently
pos++ if $necessary;
In case it’s not clear, the reason pos++ fails is that the lexer is expecting an expression after ‘pos’ and treats ++ as a preincrement where an expression is expected.
This is how I would solve it: If ++ is followed by a terminator of some sort (closing bracket, semicolon) or an unambiguous infix operator (e.g., &&), then it can’t possibly be a preincrement, but it *might* be a postincrement. So tell the parser it is a postincrement, resulting in either a syntax error (as before) or something meaningful.
Migrated from rt.perl.org#123184 (status was 'rejected')
Searchable as RT123184$
The text was updated successfully, but these errors were encountered: