Skip to content
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

Support AST manipulation #36

Open
kevinburke opened this issue Apr 16, 2017 · 2 comments
Open

Support AST manipulation #36

kevinburke opened this issue Apr 16, 2017 · 2 comments

Comments

@kevinburke
Copy link

Say I wanted to load a TOML file from a program, change a value, and write it back to disk.

The current configuration makes that difficult. Say I wanted to change the value in testdata/example.toml. I would call toml.Parse() and eventually get an ast.Value, but there's no way to modify that, and updating the Value would not update the ast.Table.Data. In addition, it doesn't seem like there's a way to convert an *ast.Table back into a []byte.

@fjl
Copy link
Collaborator

fjl commented Apr 16, 2017

You're right, there is no built-in support for modifying the AST. It would be interesting to know what your use case is.

You can do simple transformations by parsing into interface{}, modifying the result and finally writing it back out using Marshal. This is lossy because formatting and comments are lost. If the AST had support for modifications, how should comments/formatting be handled?

@kevinburke
Copy link
Author

kevinburke commented Apr 16, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants