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

parse a format (see perldoc -f format) as a single token. #250

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

reneeb
Copy link
Contributor

@reneeb reneeb commented Aug 27, 2020

Currently PPI parses formats in a wrong way (see also Perl-Critic/Perl-Critic#917)

Without this fix, this code:

format BYDEPTH_TOP =
Top disk utilization in @*, @* level(s) deep
                        $BASEPATH, $DEPTH
================================================================================

subpath                                                         disk utilization
-------                                                         ----------------
.

sub print_anything {
}

is parsed as

PPI::Document
  PPI::Statement
    PPI::Token::Word  	'format'
    PPI::Token::Whitespace  	' '
    PPI::Token::Word  	'BYDEPTH_TOP'
    PPI::Token::Whitespace  	' '
    PPI::Token::Operator  	'='
    PPI::Token::Whitespace  	'\n'
    PPI::Token::Word  	'Top'
    PPI::Token::Whitespace  	' '
    PPI::Token::Word  	'disk'
    PPI::Token::Whitespace  	' '
    PPI::Token::Word  	'utilization'
    PPI::Token::Whitespace  	' '
    PPI::Token::Word  	'in'
    PPI::Token::Whitespace  	' '
    PPI::Token::Magic  	'@*'
    PPI::Token::Operator  	','
    PPI::Token::Whitespace  	' '
    PPI::Token::Magic  	'@*'
    PPI::Token::Whitespace  	' '
    PPI::Token::Word  	'level'
    PPI::Structure::List  	( ... ???
      PPI::Statement::Expression
        PPI::Token::Regexp::Substitute  	's) deep\n                        $BASEPATH, $DEPTH\n================================================================================\n\nsubpath                                                         disk utilization\n-------                                                         ----------------\n.\n\nsub print_anything {\n}\n'

This completely wrong... With this fix, this is parsed as

PPI::Document
  PPI::Token::Format  	'format BYDEPTH_TOP =\nTop disk utilization in @*, @* level(s) deep\n                        $BASEPATH, $DEPTH\n================================================================================\n\nsubpath                                                         disk utilization\n-------                                                         ----------------\n.\n'
  PPI::Token::Whitespace  	'\n'
  PPI::Statement::Sub
    PPI::Token::Word  	'sub'
    PPI::Token::Whitespace  	' '
    PPI::Token::Word  	'print_anything'
    PPI::Token::Whitespace  	' '
    PPI::Structure::Block  	{ ... }
      PPI::Token::Whitespace  	'\n'
  PPI::Token::Whitespace  	'\n'

@oalders
Copy link
Collaborator

oalders commented Jan 21, 2022

Closing and re-opening to trigger CI.

@oalders
Copy link
Collaborator

oalders commented Jan 11, 2023

@wchristian did you have any thoughts on this one?

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

Successfully merging this pull request may close these issues.

2 participants