-
Notifications
You must be signed in to change notification settings - Fork 44
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
Allow statements as well as structures and tokens to be inserted adjacent to a token #151
base: master
Are you sure you want to change the base?
Allow statements as well as structures and tokens to be inserted adjacent to a token #151
Conversation
Conflicts: Makefile.PL
Conflicts: t/ppi_statement_sub.t
Conflicts: t/ppi_statement_package.t t/ppi_statement_sub.t t/ppi_token_operator.t
…cent to a token Otherwise, this would be impossible: my $doc = PPI::Document->new(\ "1;\n"); my $token = $doc->last_element; my $new_document = PPI::Document->new(\ '$foo = 1;'); $token->insert_after($_) foreach reverse $new_document->schildren;
I'm not sure it can be this simple. You need tests for this, because I'm fairly certain this will allow breaking the structural integrity rules. You end up with statement/statement children, and possibly structure/structure children as well. The token you insert after has to be insignificant and not be a direct child of the same type of thing you are inserting. But that said, I'm really excited to see someone padding document manipulation functionality forward. Thank you so much. |
Hmm ok, I guess I picked the wrong solution to the problem. Let me back up and restate the problem: "I have a parsed PPI::Document. I have a snippet of code, in a string, that I wish to insert at a specific point (let's say the end, for simplicity) in the document. How can I do that?" The code example in the top post was my best guess at a solution, but it only works if the new code snippet parses to specific types of nodes (e.g. tokens), and not other types (a statement). |
I had always intended PPI::Document::Fragment to represent arbitrary chunks Adam
|
By the way, that idea of serialisable or not is why you can't save Fragments would not be expected to serialize in this way, freeing them up Adam
|
07cd2bb
to
46e810f
Compare
This does need tests and also particularly tests of the type of "what happens if the document you're inserting to is a partial perl document and the last element is an unclosed string in the middle of a function call in the middle of a subrouting? how does this interact with serializing?" |
Otherwise, this would be impossible: