-
Notifications
You must be signed in to change notification settings - Fork 162
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
NewFile from bytes or ast #44
Comments
I don't think jennifer is the right tool for this. Manipulating existing files is a problem, and one I'm currently working on with https://github.com/dave/dst |
Once the |
Problem in manipulating with ast is that it binded to FileSet and adding some nodes to existing tree is hard to work and render properly. Idk how to add to ast.File and token.FileSet at the same time correctly. I write https://github.com/vetcher/go-astra to make life easier, but it does not work with function's bodies. |
That's exactly what https://github.com/dave/dst will solve. |
Oh, it will be great. But anyway I will fork this one and make all what I mention in topic, because right now it's an easiest way to render imports properly. Just want to ask you first |
Sure go ahead. I'm interested to see what you come up with... |
@dave dst looks great. I hit this problem with a code generator and ended up doing an almighty hack of outputting comments into the generated code so that on a 2nd parse i can see what is the human code and what is the code generated code. DST will open doors to some very interesting possibilities ! thanks for doing this. |
Thanks! I've got some big plans for this project... Imagine something like: parser.Parse("foo.go").Search(
nodes.OfType(nodes.CallExpr),
nodes.HasParent().OfType(nodes.ExprStmt).HasId("foo"),
).ReplaceWith(
jen.Qual("bar", "Foo").Call(),
) ... basically a DSL to query and replace bits of the AST, using jennifer syntax to craft the new code. I'll probably do a full re-write of jennifer to support this that uses DST under the hood. Feel free to join me in the |
I'd love some feedback on how the I've been dog-fooding it myself in https://github.com/dave/forky... Forky uses |
Hi @dave, what you think about adding constructor for
*jen.File
, likeNewFileFromSource()
orNewFileFromAst(*ast.File)
, to create file from existing files or asts?My use cases:
The text was updated successfully, but these errors were encountered: