genco
genco is a code generator and quasi quoter for Rust, written for use in reproto.
The workhorse of genco is the quote! and quote_in! macros. While tokens can be constructed manually, these make this process much easier.
genco only minimally deals with language-specific syntax, but primarily deals with solving the following:
-
Imports — genco generates and groups import statements according to conventions for the language being generated for.
-
String Quoting — Strings can be quoted in a language specific way either by including them literally in the token stream using
quote!("hello")
, or by through the quoted() function. -
Structural Indentation — genco's quasi quoting utilizes whitespace detection to structurally sort out spaces and indentation.
-
Language Customization — Building support for a custom language is straight forward with the impl_lang! macro.
We depend on proc_macro_hygiene
stabilizations. Until then, you must build
and run with the nightly
branch.
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;