Perl-Critic / PPI

53 stars 44 forks source link

"a".1234 parsed as a string and a float #165

Open finnperl opened 9 years ago

finnperl commented 9 years ago

I wanted to report this since I find this module very useful Example code:

use PPI; use Data::Dumper; print Dumper(PPI::Document->new(\'"a".1'));

The output is:

$VAR1 = bless( { 'readonly' => '', 'children' => [ bless( { 'children' => [ bless( { 'separator' => '"', 'content' => '"a"' }, 'PPI::Token::Quote::Double' ), bless( { 'content' => '.1' }, 'PPI::Token::Number::Float' ) ] }, 'PPI::Statement' ) ], 'tab_width' => 1 }, 'PPI::Document' );

However, for example

perl -e 'print "a".1'

outputs a1, which implies that perl is able to detect . as the concat operator. Looking at the tokenizer, it seems that PPI does not look backwards when it is checking whether . is an operator or part of a float.

moregan commented 9 years ago

Confirmed in PPI 1.220 and on my development branches.

ppidump '"a".1'
                    PPI::Document
                      PPI::Statement
[    1,   1,   1 ]     PPI::Token::Quote::Double    '"a"'
[    1,   4,   4 ]     PPI::Token::Number::Float    '.1'

Thank you for your report