Hello, I have MyTextModel class - a subclass of TextModel, it holds an ast of it's text. When I replace node of the ast using replaceWith: ast is changed, then I say text: ast formattedCode, so the text is changed too. But! when I inspect new ast(after replacing some node), I see that source interval isn't changed. Why? If I say bestNodeFor: someInterval, it doesn't give me the right node, because sourceInterval of ast wasn't changed, and I don't know why. Hope you will help me out:) Best, Mark -- View this message in context: http://forum.world.st/AST-source-interval-isn-t-changed-tp4772779.html Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
On 11 Aug 2014, at 10:09, Mark Rizun <mrizun@gmail.com> wrote:
Hello,
I have MyTextModel class - a subclass of TextModel, it holds an ast of it's text. When I replace node of the ast using replaceWith: ast is changed, then I say text: ast formattedCode, so the text is changed too. But! when I inspect new ast(after replacing some node), I see that source interval isn't changed. Why? If I say bestNodeFor: someInterval, it doesn't give me the right node, because sourceInterval of ast wasn't changed, and I don't know why. Hope you will help me out:)
I guess the AST is never used like that (it is re-created from source after a change normally). But I think we should fix it.. it should be possible to do multiple things with it and it should stay consistent. Marcus
On 14 Aug 2014, at 16:42, Mark Rizun <mrizun@gmail.com> wrote:
I guess the AST is never used like that (it is re-created from source after a change normally). That's what I do (reparse it if something has been changed). But it seems to me wrong, and also it causes problems.
Yes, we should fix this⦠Marcus
Le 11/08/2014 10:09, Mark Rizun a écrit :
Hello,
I have MyTextModel class - a subclass of TextModel, it holds an ast of it's text. When I replace node of the ast using replaceWith: ast is changed, then I say text: ast formattedCode, so the text is changed too. But! when I inspect new ast(after replacing some node), I see that source interval isn't changed. Why? If I say bestNodeFor: someInterval, it doesn't give me the right node, because sourceInterval of ast wasn't changed, and I don't know why. Hope you will help me out:) It is possible to update the positions, but this isn't easy to do (and not what an ast user may want in some cases).
In practice, when playing with asts this way, you even specifically want to keep the positions of the original ast nodes (and another numbering for the insertions : replacements) so that, if needed, you can make the distinction between the original nodes and the added nodes. In short, I would suggest a reparse, especially if you have produced the output. It will also ensure that bindings and all are properly rebuilt. Thierry
Best, Mark
-- View this message in context: http://forum.world.st/AST-source-interval-isn-t-changed-tp4772779.html Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
participants (3)
-
Marcus Denker -
Mark Rizun -
Thierry Goubier