melt-umn / silver

An attribute grammar-based programming language for composable language extensions
http://melt.cs.umn.edu/silver/
GNU Lesser General Public License v3.0
58 stars 7 forks source link

Implement layout-preserving unparse and AST-based refactoring mechanism #821

Closed krame505 closed 8 months ago

krame505 commented 9 months ago

Fixes #800.

Changes

Adds a library for unparsing concrete syntax trees using reflection, origin tracking and the pp library to preserve layout. Most of the complexity here is to do with robustly handling indentation for trees that have undergone transformations. I don't expect anyone reviewing this to fully understand the details.

Also adds a mechanism to the Silver driver for refactoring Silver code. Two example refactorings are supported - replacing regular functions with the new concise syntax, and inserting calls to new wherever a tree is implicitly undecorated.

Documentation

Added doc comments for the API of the unparse library. I'm not sure if it is worthwhile trying to make the implementation intelligible.

Added help messages for command line flags related to refactoring.

Testing

Tested by running the refactoring tool on Silver.

This could maybe use some unit tests for the unparsing mechanism, but I don't really have time right now and would like to get this merged.