1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
//! 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 //! language convention. //! //! * **String Quoting** — strings can be quoted in a language specific way //! either by including them literally in the token stream by using //! `quote!("hello")` or `quote!(#_(hello))`. Or explicitly with the //! [quoted()] function. //! //! * **Structural Indentation** — genco's quasi quoting utilizes //! [whitespace detection] to structurally sort out spaces and indentation. //! //! * **Language Customization** — building support for an unsupported language //! is easy with the [impl_lang!] macro. //! //! <br> //! //! 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. //! //! ```bash //! cargo +nightly run --example rust //! ``` //! //! [`proc_macro_span` feature]: https://github.com/rust-lang/rust/issues/54725 //! //! <br> //! //! ## Examples //! //! The following are language specific examples for genco using the [quote!] //! macro. //! //! * [Rust Example] //! * [Java Example] //! * [C# Example] //! * [Go Example] //! * [Dart Example] //! * [JavaScript Example] //! * [Python Example] //! //! You can run one of the examples above using: //! //! ```bash //! cargo run --example go //! ``` //! //! <br> //! //! ## Rust Example //! //! The following is a simple program producing Rust code to stdout with custom //! configuration: //! //! ```rust,no_run //! use genco::prelude::*; //! use genco::fmt; //! //! # fn main() -> fmt::Result { //! let map = rust::import("std::collections", "HashMap"); //! //! let tokens: rust::Tokens = quote! { //! fn main() { //! let mut m = #map::new(); //! m.insert(1u32, 2u32); //! } //! }; //! //! let stdout = std::io::stdout(); //! let mut w = fmt::IoWriter::new(stdout.lock()); //! //! let fmt = fmt::Config::from_lang::<Rust>() //! .with_indentation(fmt::Indentation::Space(2)); //! let config = rust::Config::default(); //! //! tokens.format_file(&mut w.as_formatter(fmt), &config)?; //! # Ok(()) //! # } //! ``` //! //! This would produce: //! //! ```rust,no_run //! use std::collections::HashMap; //! //! fn main() { //! let mut m = HashMap::new(); //! m.insert(1u32, 2u32); //! } //! ``` //! //! <br> //! //! [reproto]: https://github.com/reproto/reproto //! [whitespace detection]: https://docs.rs/genco/0/genco/macro.quote.html#whitespace-detection //! [Rust Example]: https://github.com/udoprog/genco/blob/master/examples/rust.rs //! [Java Example]: https://github.com/udoprog/genco/blob/master/examples/java.rs //! [C# Example]: https://github.com/udoprog/genco/blob/master/examples/csharp.rs //! [Go Example]: https://github.com/udoprog/genco/blob/master/examples/go.rs //! [Dart Example]: https://github.com/udoprog/genco/blob/master/examples/dart.rs //! [JavaScript Example]: https://github.com/udoprog/genco/blob/master/examples/js.rs //! [Python Example]: https://github.com/udoprog/genco/blob/master/examples/python.rs //! [quote!]: https://docs.rs/genco/0/genco/macro.quote.html //! [quote_in!]: https://docs.rs/genco/0/genco/macro.quote_in.html //! [impl_lang!]: https://docs.rs/genco/0/genco/fn.impl_lang.html //! [quoted()]: https://docs.rs/genco/0/genco/tokens/fn.quoted.html #![doc(html_root_url = "https://docs.rs/genco/0.10.4")] #![deny(missing_docs)] #![deny(intra_doc_link_resolution_failure)] pub use genco_macros::{quote, quote_in}; #[macro_use] mod macros; pub mod fmt; pub mod lang; pub mod prelude; pub mod tokens; pub use self::tokens::Tokens;