in reply to BUG when parsing defined-or ?
case '/': /* may be division, defined-or, or pattern */ if ((PL_expect == XOPERATOR || PL_expect == XTERMORDORDOR) && + s[1] == '/') { ... AOPERATOR(DORDOR); } else if (PL_expect == XOPERATOR) { ... Mop(OP_DIVIDE); } else { ... s = scan_pat(s,OP_MATCH); }
I'm no expert in how the lexer works but implementing parsing on such heuristics is a fragile thing.Oh yes, Perl's lexer is fascinating :) I'm not an expert either, life is too short...
For example, you said that the concat op works...
So, if the lexer doesn't expect an operator, it decides based on whether the next character is a digit... Let's see:case '.': ... if (PL_expect == XOPERATOR || !isDIGIT(s[1])) { ... Aop(OP_CONCAT)
but:$ perl -MO=Deparse -e 'sub foo(&) {}; foo { "foo" } . 5' sub foo (&) { } foo(sub { 'foo'; } ) . 5; -e syntax OK $ perl -MO=Deparse -e 'sub foo(&) {}; foo { "foo" } .5' Too many arguments for main::foo at -e line 1, at EOF -e had compilation errors. sub foo (&) { } &foo(sub { 'foo'; } , 0.5);
because here it does expect an operator.$ perl -E 'say 1 .5' 15
So, yeah... Just don't think too much about it :)
Hopefully this can be fixed in the future.That would require fixing the grammar of the Perl 5 programming language; the major version surely should be incremented then and the backwards-incompatible result should be called Perl 6... oh wait...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: BUG when parsing defined-or ?
by LanX (Saint) on Jan 25, 2016 at 03:09 UTC |