Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

statement of word + block doesn't recognize implicit statement end #44

Closed
moregan opened this issue Mar 1, 2014 · 1 comment
Closed

Comments

@moregan
Copy link
Collaborator

moregan commented Mar 1, 2014

When a statement consists of a word plus a block and is supposed to end implicitly after the block, the statement instead keeps picking up tokens until it encounters an explicit statement end. E.g.:

ppidump 'DESTROY {} sub foo {} 1; sub bar{}'
                    PPI::Document
                      PPI::Statement
[    1,   1,   1 ]     PPI::Token::Word         'DESTROY'
                        PPI::Structure::Block   { ... }
[    1,  12,  12 ]     PPI::Token::Word         'sub'
[    1,  16,  16 ]     PPI::Token::Word         'foo'
                        PPI::Structure::Block   { ... }
[    1,  23,  23 ]     PPI::Token::Number       '1'
[    1,  24,  24 ]     PPI::Token::Structure    ';'
                      PPI::Statement::Sub
[    1,  26,  26 ]     PPI::Token::Word         'sub'
[    1,  30,  30 ]     PPI::Token::Word         'bar'
                        PPI::Structure::Block   { ... }

The DESTROY+block statement is supposed to end when the block ends, but it it doesn't actually end until it sees the ';' after sub foo. If we change the initial statement to be something other than word+block, the DESTROY statement ends properly and foo is recognized as a sub:

ppidump 'sub DESTROY {} sub foo {} 1; sub bar{}'
                    PPI::Document
                      PPI::Statement::Sub
[    1,   1,   1 ]     PPI::Token::Word         'sub'
[    1,   5,   5 ]     PPI::Token::Word         'DESTROY'
                        PPI::Structure::Block   { ... }
                      PPI::Statement::Sub
[    1,  16,  16 ]     PPI::Token::Word         'sub'
[    1,  20,  20 ]     PPI::Token::Word         'foo'
                        PPI::Structure::Block   { ... }
                      PPI::Statement
[    1,  27,  27 ]     PPI::Token::Number       '1'
[    1,  28,  28 ]     PPI::Token::Structure    ';'
                      PPI::Statement::Sub
[    1,  30,  30 ]     PPI::Token::Word         'sub'
[    1,  34,  34 ]     PPI::Token::Word         'bar'
                        PPI::Structure::Block   { ... }

This word+block pattern occurs for the special subs AUTOLOAD and DESTROY if you omit their optional 'sub'. Those two cases will no longer be an issue when #39 is applied for #31 .

do+block doesn't have the problem because it does not end implicitly. It's followed by 'until' or ';' or an expression.

'sub {} sub foo{}' fits the word+block+implicit end pattern, but it doesn't compile.

Are there any other naturally-occurring instances of word+block+implicit statement end?

@moregan
Copy link
Collaborator Author

moregan commented Mar 21, 2014

The perl 5.12 "package name version BLOCK" syntax is an example.

However, all that is going on here is PPI missing an implicit statement end. There is nothing special about the word+BLOCK form.

@moregan moregan closed this as completed Mar 21, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant