4 ms·
Funny, I actually did the same thing for python years ago and also talked about "Lossless Syntax Tree" then start calling it a Full Syntax Tree since CST doesn'
by brabram 10y ago
Funny, I actually did the same thing for python years ago and also talked about "Lossless Syntax Tree" then start calling it a Full Syntax Tree since CST doesn't really fit; I wasn't aware of the existence of lib2to3 at that time.
My goal was different than your: I wanted make writing custom refactoring code (that's it: code that modify source code) and code that works on source code a do-able task.
I end up doing some design decisions that I haven't found elsewhere (but this field is hard to explore):
- producing json, because datastructure doesn't lie to you and potential interoperability
- nodes are responsible for the formatting within itself, in opposition with lib2to3 where a node is responsible for the formatting before itself (or after, I'm not sure anymore)
- the tree is design for the human brain instead of an interpreter/compiler (for example having list instead of recursive structures)
The project is called Baron https://github.com/pycqa/baron https://github.com/pycqa/baron and was actually a mean for me to work on what really interest me: the abstraction that attempt to make writing custom refactoring a doable task https://github.com/pycqa/redbaron https://github.com/pycqa/redbaron
Good luck with your project :)
- shakna 10y agoI've used RedBaron before when building some toy languages. Thanks for a great project!
- brabram 10y agoOh, can you give more details/links please? I'm really curious about that!
- shakna 10y agoThe code never became public, but I can give some details. The idea was to create an easier C, using Python as an intermediary language. RedBaron provided the AST and AST->Python layers. Unfortunately, the project had to pivot, because optimising Python to be fast enough was overly difficult/unpredictable.
- derblitzmann 10y agoAdding a comment as a reminder to look up your project. Which sounds really interesting!
- jasonkostempski 10y agoNever did this before but after reading your comment, I thought there must be a better way. Click the "n units ago" timestamp next to the commentors user name, there's a "favorite" option you can then access through your profile page "favorite stories / comments".
- chubot 10y agoCool, I didn't know about those projects. I have been using sed for a long time to refactor Python! I think the goals are actually similar -- refactoring is a style-preserving transformation that is similar to changing the language. At Google there is a bunch of work on converting C++ 03 to 11 to 14 to 17, etc. and they're using similar techniques with Clang. That's an example of a refactoring that's also changing the language. I think it would be nice to make a "LST-aware sed". Once you have the parsers, I don't think it's that hard to add something like that on top. The parsers are of course a lot of labor!