Perl-Critic / PPI

53 stars 44 forks source link

package blocks are parsed weird. #191

Open bluefeet opened 8 years ago

bluefeet commented 8 years ago

Given this:

package Foo;
package Bar { }
package Baz { }
print 'hello';

I get:

                    PPI::Document
                      PPI::Statement::Package
[    1,   1,   1 ]     PPI::Token::Word     'package'
[    1,   9,   9 ]     PPI::Token::Word     'Foo'
[    1,  12,  12 ]     PPI::Token::Structure    ';'
                      PPI::Statement::Package
[    2,   1,   1 ]     PPI::Token::Word     'package'
[    2,   9,   9 ]     PPI::Token::Word     'Bar'
                        PPI::Structure::Block   { ... }
[    3,   1,   1 ]     PPI::Token::Word     'package'
[    3,   9,   9 ]     PPI::Token::Word     'Baz'
                        PPI::Structure::Block   { ... }
[    4,   1,   1 ]     PPI::Token::Word     'print'
[    4,   7,   7 ]     PPI::Token::Quote::Single    ''hello''
[    4,  14,  14 ]     PPI::Token::Structure    ';'

That seems super wrong! Note how the second Package object actually slurped up both the second and third package declarations as well as the print statement. Ack!

If I add semicolons after the package blocks:

package Foo;
package Bar { };
package Baz { };
print 'hello';

It then looks like this:

                    PPI::Document
                      PPI::Statement::Package
[    1,   1,   1 ]     PPI::Token::Word     'package'
[    1,   9,   9 ]     PPI::Token::Word     'Foo'
[    1,  12,  12 ]     PPI::Token::Structure    ';'
                      PPI::Statement::Package
[    2,   1,   1 ]     PPI::Token::Word     'package'
[    2,   9,   9 ]     PPI::Token::Word     'Bar'
                        PPI::Structure::Block   { ... }
[    2,  16,  16 ]     PPI::Token::Structure    ';'
                      PPI::Statement::Package
[    3,   1,   1 ]     PPI::Token::Word     'package'
[    3,   9,   9 ]     PPI::Token::Word     'Baz'
                        PPI::Structure::Block   { ... }
[    3,  16,  16 ]     PPI::Token::Structure    ';'
                      PPI::Statement
[    4,   1,   1 ]     PPI::Token::Word     'print'
[    4,   7,   7 ]     PPI::Token::Quote::Single    ''hello''
[    4,  14,  14 ]     PPI::Token::Structure    ';'

Which looks perfect. Any chance this can be fixed? Semicolons should not be required after a package block.

bluefeet commented 8 years ago

Looks like this might be resolved by pull request #184.