Perl-Critic / PPI

53 stars 44 forks source link

Illegal sub attribute parsed as attribute #118

Closed moregan closed 9 years ago

moregan commented 9 years ago

perl treats a space between an attribute name and its parameters as a syntax error, but PPI 1.220 still creates a PPI::Token::Attribute:

ppidump 'sub foo : Attr1 () {}'
                    PPI::Document
                      PPI::Statement::Sub
[    1,   1,   1 ]     PPI::Token::Word         'sub'
[    1,   5,   5 ]     PPI::Token::Word         'foo'
[    1,   9,   9 ]     PPI::Token::Operator     ':'
[    1,  11,  11 ]     PPI::Token::Attribute    'Attr1'
                        PPI::Structure::List    ( ... )
                        PPI::Structure::Block   { ... }

Wouldn't it be better to omit a PPI::Token::Word instead?

moregan commented 9 years ago

My thoughts for this case are that either we should:

1) accept the parse as above, in the PPI spirit of trying to produce something logical when presented with a mystery, or

2) acknowledge that what we have looks like an attribute gone wrong, and force 'Attr1' to be a Word rather than pretend we have a good attribute.

I am leaning towards (1)

wchristian commented 9 years ago

Closing this until #129 has some kind of decision.