Re: [Pharo-project] Adding a statement programmatically
On Mar 8, 2012, at 12:21 PM, Noury Bouraqadi wrote:
Hi Sean,
Did you thought about: -using method wrappers? -object as methods. An object o put in a method dictionary instead of some method with selector #s. When #s is looked up, o receives the message run: selector with: args in: originalReceiver -proxies (look at Ghost) so you introduce an indirection to perform what ever action you want before performing the actual code
-> Compile the code to an RB AST, this then has all the interfaces needed to replace nodes or add nodes. You can then pretty print it back to source. Marcus -- Marcus Denker -- http://marcusdenker.de
Marcus Denker-4 wrote
-> Compile the code to an RB AST, this then has all the interfaces needed to replace nodes or add nodes. You can then pretty print it back to source.
Thanks Marcus. That's what I was trying to do. I got the AST and created the node: body := (AbstractSound>>#initialize) parseTree body. body addNode: (RBParser parseExpression: 'envelopes := nil'). But then I couldn't figure out how to get the source back... "These both returned the statements without the header" body formattedCode. body newSource. "This returned the full method, but without the added node" body source -- View this message in context: http://forum.world.st/Adding-a-statement-programmatically-tp4454447p4456824.... Sent from the Pharo Smalltalk mailing list archive at Nabble.com.
Am 08.03.2012 um 17:08 schrieb Sean P. DeNigris:
Marcus Denker-4 wrote
-> Compile the code to an RB AST, this then has all the interfaces needed to replace nodes or add nodes. You can then pretty print it back to source.
Thanks Marcus. That's what I was trying to do. I got the AST and created the node: body := (AbstractSound>>#initialize) parseTree body. body addNode: (RBParser parseExpression: 'envelopes := nil').
But then I couldn't figure out how to get the source back...
"These both returned the statements without the header" body formattedCode. body newSource.
"This returned the full method, but without the added node" body source
Sean, you extracted the body first and operate on it. So you only have the body. Try method := (AbstractSound>>#initialize) parseTree. method body addNode: (RBParser parseExpression: 'envelopes := nil'). method formattedCode Norbert
Norbert Hartl wrote
Try...
Thanks Norbert. Same result. -- View this message in context: http://forum.world.st/Adding-a-statement-programmatically-tp4454447p4457352.... Sent from the Pharo Smalltalk mailing list archive at Nabble.com.
Am 08.03.2012 um 20:05 schrieb "Sean P. DeNigris" <sean@clipperadams.com>:
Norbert Hartl wrote
Try...
Thanks Norbert. Same result.
Does not work? What do you mean by saying "same result"? Norbert
-- View this message in context: http://forum.world.st/Adding-a-statement-programmatically-tp4454447p4457352.... Sent from the Pharo Smalltalk mailing list archive at Nabble.com.
Norbert Hartl wrote
method := (AbstractSound>>#initialize) parseTree. method body addNode: (RBParser parseExpression: 'envelopes := nil'). method formattedCode ... Does not work? What do you mean by saying "same result"?
It did work (one year later, lol)! My last statement was mistakenly "body formattedCode" instead of "method formattedCode" ----- Cheers, Sean -- View this message in context: http://forum.world.st/Adding-a-statement-programmatically-tp4454447p4692030.... Sent from the Pharo Smalltalk Developers mailing list archive at Nabble.com.
Am 06.06.2013 um 22:18 schrieb "Sean P. DeNigris" <sean@clipperadams.com>:
Norbert Hartl wrote
method := (AbstractSound>>#initialize) parseTree. method body addNode: (RBParser parseExpression: 'envelopes := nil'). method formattedCode ... Does not work? What do you mean by saying "same result"?
It did work (one year later, lol)! My last statement was mistakenly "body formattedCode" instead of "method formattedCode"
:) Norbert
----- Cheers, Sean -- View this message in context: http://forum.world.st/Adding-a-statement-programmatically-tp4454447p4692030.... Sent from the Pharo Smalltalk Developers mailing list archive at Nabble.com.
participants (3)
-
Marcus Denker -
Norbert Hartl -
Sean P. DeNigris