Open happy-barney opened 1 hour ago
Can you provide the example code as valid perl? I get this error trying to compile it:
$ perl -e 'ref // 1'
Warning: Use of "ref" without parentheses is ambiguous at -e line 1.
Number found where operator expected at -e line 1, near "// 1"
(Missing operator before 1?)
syntax error at -e line 1, near "// 1"
Execution of -e aborted due to compilation errors.
valid perl will be:
ref () // 1
sub foo :prototype() {}; foo // 1
In those examples Perl seems to treat // as the undef-or operator.
$ cat marp.pl
sub foo :prototype() {}; print(foo // 1)
$ perl marp.pl
1
$ cat marp.pl
sub foo :prototype() {2}; print(foo // 1)
$ perl marp.pl
2
Ah hm, it doesn't seem to for the first example. Impressively odd behavior.
Nevermind that, in the ref example it also treats it as the undef-or operator, because ref returns the empty string ""
.
$ perl -e 'print(length(ref () ))'
0
$ perl -e 'print(defined(ref () ))'
1
So, in conclusion: Right now i need an example of working Perl code where // is treated by Perl as a regex match, and evidence for this being the case. :)
OK, probably some clarification: ref // 1
type of expressions will always be invalid.
This issues is only about treating objects like Perl does.
IMHO it is fine when PPI
creates broken expressions from invalid code.
It should not create valid expression from invalid code. (using current behaviour creates valid expression of potential interpreter using PPI
to parse code similar to Perl.
Note that you wrote:
Perl treats // as: [...] regexp-match otherwise
Can you clarify what your evidence for this is? (I find it hard to understand, given that Perl just crashes when presented with such code, instead of actually running it.)
Note that you wrote:
Perl treats // as: [...] regexp-match otherwise
Can you clarify what your evidence for this is?
In expression
identifier //
(when identifier is not method call), Perl treats//
as:()
prototypeFor example, parsing
ref // 1
:But current result should be preserved for parsing eg:
my sub ref (); ref // 1