[Newcompiler] Changing just a part of a method
Mathieu Suen
mathieusuen at yahoo.fr
Fri Jul 27 13:11:25 UTC 2007
So _ shouldn't be used anymore.
But I have publish a new AST version so the _ are kept.
Mth
On Jul 27, 2007, at 2:51 PM, Damien Cassou wrote:
> 2007/7/27, Mathieu Suen <mathieusuen at yahoo.fr>:
>> Try to use the SqueakParser in the NewParser package.
>> Could you give me your code to let me try.
>> Thanks
>
> CompiledMethod>>linesOfCode before change:
>
> linesOfCode
> "An approximate measure of lines of code.
> Includes comments, but excludes blank lines."
> | strm line lines |
> lines _ 0.
> strm _ ReadStream on: self getSource.
> [strm atEnd] whileFalse:
> [line _ strm upTo: Character cr.
> line isEmpty ifFalse: [lines _ lines+1]].
> ^lines
>
>
> CompiledMethod>>linesOfCode after change using RBParser:
>
> linesOfCode
> "An approximate measure of lines of code.
> Includes comments, but excludes blank lines."
>
> | strm line lines |
> lines := 0.
> strm := self getSource readStream.
> [strm atEnd] whileFalse:
> [line := strm upTo: Character cr.
> line isEmpty ifFalse: [lines := lines + 1]].
> ^ lines
>
> All _ has been changed to := and I don't want this.
>
> The code to change the method is:
>
> rewriteRule := ParseTreeRewriter new.
> rewriteRule replace: 'ReadStream on: ``@Expression' with:
> '``@Expression readStream'.
> tree := CompiledMethod parseTreeFor: #linesOfCode.
> rewriteRule executeTree: tree.
> rewriteRule tree printString.
>
>
> I understand why this is like this: once you have a tree, you can't go
> back to previous formatting. But is there a workaround?
>
> --
> Damien Cassou
___________________________________________________________________________
Yahoo! Mail réinvente le mail ! Découvrez le nouveau Yahoo! Mail et son interface révolutionnaire.
http://fr.mail.yahoo.com
More information about the Newcompiler
mailing list