Library for generating Rust code (something like Boost Karma)


I am looking for a library that supports generators, similar to boost karma (C ++).

look no further: generators - The Rust Unstable Book
(These are the built-in stackless generators, which are still unstable.)
For stackfull generators, search on GitHub - Xudong-Huang/generator-rs: rust stackful generator library looks like it could work.

1 Like

And here's a crate for stackless generators on Stable rust:

1 Like

It is not it.
The name is the same but the functionality is not.

Well… to be honest I am not quite sure what that boost::spirit::karma is doing…
if you just need formatting, then std::fmt contains most of what you need.

From the looks of it, I'd say karma is related to parsing, so maybe it is a parser generator?

If that's the case, then you may have a look at:

and also some parser combinators:

I need a generator, not a parser. I need to generate Rust code from AST (My Custom Config).

My bad karma does not look to parse i.e., deserialize but to go the other way around, i.e. serialize:

Spirit.Karma is the counterpart to Spirit.Qi . Some people say it's the Yin to Spirit.Qi 's Yang. Spirit.Karma is generating byte sequences from internal data structures as Spirit.Qi is parsing byte sequences into those (very same) internal data structures

Oh! Well, we don't call that generators.

quote - Rust is the de-facto standard of code generation.

Perhaps you would be willing to edit the title of this thread so that it does not show up in future searches for "generators", which in Rust are coroutines. I suggest "Need library for generating Rust code".


for illustration :

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.