[Pharo-project] Adding a statement programmatically
norbert at hartl.name
Thu Mar 8 11:24:39 EST 2012
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
> 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
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').
More information about the Pharo-dev