[Newcompiler] Changing just a part of a method
Damien Cassou
damien.cassou at gmail.com
Fri Jul 27 12:51:06 UTC 2007
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
More information about the Newcompiler
mailing list