-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make parse round-trip-able #33
Comments
That's a great idea @cstrahan. You'll need to plumb attributes through the syntax tree that preserve knowledge like surrounding whitespace, etc. This part should be fairly easy, since we're using a Then, in the evaluator, you only need to preserve the attributes over any transformation (they would be abstract in that case). In the pretty printer, it would use the attributes for laying out the elements to be printed, or any other style decisions. It's not exactly trivial, but should be straightforward, and I'm sure there are examples of something similar living out on the Web. |
@jwiegley I don't think trailing white space matters as much, so perhaps just tracking source spans would be sufficient (ala If so, do you suppose I should add a monomorphic field (e.g. |
You shouldn't need to change the AST at all, but just change the |
Do you mean the Are you suggesting something like this? data SrcSpan = SrcSpan Int Int
data Ann x f a = Ann x (f a)
type NExpr = Fix (Ann SrcSpan NExprF) |
Oh yeah, sorry, |
I've started working towards this in #35 |
@cstrahan We've now merged @expipiplus1 's work, does this help you in building your tools? |
@jwiegley I believe so, although I've shelved that work for the time being. Thanks! |
For an example of this being used you can take a look here: https://github.com/expipiplus1/update-nix-fetchgit This doens't do a round trip though, It uses the source locations to modify the underlying string. |
There are a number of tools (including one I desperately need to write) that would require the ability to parse a nix expression, transform it in some way, and then write the expression back out - all while keeping unmodified portions unchanged in the output.
I could take a stab at this, but I think I might need some hints/help.
The text was updated successfully, but these errors were encountered: