GenCo
GenCo is an even simpler code generator for Rust, written for use in reproto.
Note: We currently depend on #![feature(proc_macro_hygiene)]
, which is set to
be stabilized in Rust 1.45.
The workhorse of GenCo is the quote! macro. While tokens can be constructed manually, quote! makes this process much easier.
GenCo only minimally deals with language-specific syntax, but primarily deals with solving the following:
- Generates and groups import statements.
- Quote (and escape) strings using
<stmt>.quoted()
. - Indents and spaces your code according to generic indentation rules that can be tweaked on a per-language basis.
Examples
The following are language specific examples for GenCo using the quote! macro.
- Rust Example
- Java Example
- C# Example
- Go Example
- Dart Example (TODO)
- JavaScript Example (TODO)
- Python Example (TODO)
You can run one of the examples above using:
The following is the included example Rust program.
use ;
use ;
use Rng;
use fmt;
Indentation Rules
The quote!
macro has the following rules for dealing with indentation and
spacing.
Two tokens that are separated, are spaced. Regardless of how many spaces there are between them.
So:
let _: Tokens = quote!;
Becomes:
More that two line breaks are collapsed.
So:
let _: Tokens = quote! ;
Becomes:
Indentation is determined on a row-by-row basis. If a column is further in than the one on the preceeding row, it is indented one level deeper.
Like wise if a column starts before the previous rows column, it is indended one level shallower.
So:
let _: Tokens = quote! ;
Becomes: