genco
genco is a language neutral code generator and quasi quoter.
Central to genco is the quote! and quote_in! macros. While token streams can be constructed manually, these makes the process much more intuitive.
genco solves the following, language-specific concerns.
-
Imports — genco generates and groups import statements as they are used. No redundancy, no mess. Only exactly what you need. Worried about conflicts? We've got you covered.
-
String Quoting — we figure out how to correctly quote strings for your language. We even know how to generate code to interpolate values into the quoted string (like
"Hello $name"
in Dart). -
Structural Indentation — our quasi quoter performs efficient whitespace detection to structurally sort out spaces and indentation. Allowing us to generate beautiful, readable code with minimal effort.
-
Language Customization — building support for new languages is a piece of cake with the help of the batteries included impl_lang! macro.
In order to do whitespace detection, we depend on the
proc_macro_span
feature to access information on spans.
Until this is stable, you must build and run projects using genco with the
nightly
compiler.
Examples
The following are language specific examples for genco using the quote! macro.
You can run one of the examples above using:
Rust Example
The following is a simple program producing Rust code to stdout with custom configuration:
use *;
use fmt;
let map = import;
let tokens: Tokens = quote! ;
let stdout = stdout;
let mut w = new;
let fmt =
.with_indentation;
let config = default;
tokens.format_file?;
This would produce:
use HashMap;