genco
A whitespace-aware quasiquoter for beautiful code generation.
Central to genco are the quote! and quote_in! procedural macros which ease the construction of token streams.
This project solves the following language-specific concerns:
-
Imports — Generates and groups import statements as they are used. So you only import what you use, with no redundancy. We also do our best to solve namespace conflicts.
-
String Quoting — genco knows how to quote strings. And can even interpolate values into the quoted string if it's supported by the language.
-
Structural Indentation — The quoter relies on intuitive whitespace detection to structurally sort out spacings and indentation. Allowing genco to generate beautiful readable code with minimal effort. This is also a requirement for generating correctly behaving code in languages like Python where indentation is meaningful.
-
Language Customization — Building support for new languages is a piece of cake with the help of the impl_lang! macro.
To support line changes during whitespace detection, we depend on the
nightly proc_macro_span
feature. On stable we can only detect column
changes.
Until this is stabilized and you want fully functional whitespace
detection you must build and run projects using genco with a nightly
compiler. This is important for whitespace-sensitive languages like python.
You can try the difference between:
And:
Supported Languages
The following are languages which have built-in support in genco.
Is your favorite language missing? Open an issue!
You can run one of the examples by:
Rust Example
The following is a simple program producing Rust code to stdout with custom configuration:
use *;
let hash_map = import;
let tokens: Tokens = quote! ;
println!;
This would produce:
use HashMap;