2014-10-29 8:32 GMT+01:00 Mark Rizun <mri...@gmail.com>: > > Which ones? > > > In my tool each node has property oldNodes, which holds collection of > obviously AST nodes:) > When I replace one of node I have to update source interval in some way. >
> 1)If I update it with reparsing, I loose all data about oldNodes for each > node of my AST. > So I have to save old AST with all oldNodes, and somehow detect which > nodes were not changed and reassign their lost oldNodes. > But sometimes it's difficult to detect where and what you have to assign, > as sometimes AST may be changed in dramatic way. > Ok; yes, I can relate to that. But, knowing who has designed the RB ast, I'm sure it has a proper equality property where: oldNodeFromAST = sameNodeFromASTreparsed holds true. So you can reparse and rematch old node to new node. But I would only regenerate and reparse when I need to update the source intervals (or display the modified source). > 2) But if source interval is updated automatically I don't bother with > losing data for all AST. > I just have to update oldNodes for node that was replaced. > Well, not really. If during regeneration of your source, you change the way the code is formatted (more tabs here, removing a return there, etc...) then regenerated source intervals are different from modified ast source intervals. So your 'modify source intervals' is very fragile for me. The only way I can see a way out for that problem: Inserted / replaced node have source intervals in a separate source; unmodified nodes keep their source interval. This is the way I do it in my source to source compilers when I want to inject code (and tag in the generated file where that code comes from: usefull for debugging). Or the match of old node to new node as seen above. > > That is way I'd like to have automatically updated source interval. > I'm still not entirely sure why. Source intervals are only there to help relating the ast to the source, not much else, really. Thierry > > >> >> No it shouldn't. If the source has not been regenerated from the modified >> AST, then >> >> 'source copyFrom: theBarASTNode start to: theBarASTNode stop' >> >> end past the end of it (20 to 23 with source ending at 19). >> >> If you regenerate the source, then you can parse it and you'll have >> correct intervals. >> > > Marcus, do I have to redo everything back, or you can somehow remove that > slice from newest version? > > Mark > > >