carllerche / codegen

A Rust library providing a builder API to generate Rust code.
MIT License
251 stars 67 forks source link

Code generation? #22

Closed piranna closed 4 years ago

piranna commented 4 years ago

So far docs and tests show only high level components can be generated, like structs, modules and functions, and code needs yo be created with raw code strings at Function.line(). Not sure if it's a limitation of the builder pattern used un the API, but how much would cost to add support for generation of variables, asignements, blocks, loops, conditionals and function calls?

andrewleverette commented 4 years ago

I could see adding constructs for loops and maybe function calls. I think that variable assignments and conditionals are at to low of a level to warrant building logic around that. Plus it would take away quite a bit of flexibility.

piranna commented 4 years ago

Flexibility would be drop if raw calls would be removed, but I think they are still useful. I've been investigating os using libsyntax and other tools, but seems they doesn't fit or are simple enought for code generation. I understand your concerns about making code more complex, but I only see it as a matter of adding some more extra builder functions...