-
Notifications
You must be signed in to change notification settings - Fork 591
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
Modifying the AST before printing? #201
Comments
Hi @brikis98! The HCL printer code is primarily intended for pretty-printing a parsed, unmodified AST. I expect the mangling you saw was related to how comments get re-inserted into the stream in order to write out the result, since comments are not normally part of the main AST. |
@apparentlymart Got it. I'll see if I can hack something up to properly update |
My suggestion is to add comments to AST so there would be no need to insert them back into the stream. And user could then even modify not only logic but comments too. Is it doable? |
+1 |
Is there a way to use this HCL library to:
main.tf
) to get back an AST.It seems like this should be easy, but it falls apart due to the logic in
token.Pos
. In particular, if you add a node somewhere to the AST, then all theline
andoffset
values in the rest of the AST are wrong; and if you modify an existing node in the AST, then all thecolumn
andoffset
values in the rest of the AST are wrong. As a result, when you print the AST back out, you get all sorts of mangled code, especially related to comments.Am I using this library wrong or is this just a current limitation?
The text was updated successfully, but these errors were encountered: