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
//! Utilities for working with token streams. //! //! This is typically a module you will use if you intend to provide a manual //! implementation of [FormatInto]. //! //! # Examples //! //! ```rust //! use genco::quote_in; //! use genco::tokens::{from_fn, ItemStr, FormatInto, static_literal}; //! use genco::lang::Lang; //! //! /// Format a block comment, starting with `/**`, and ending in `*/`. //! pub fn block_comment<I, L>(text: I) -> impl FormatInto<L> //! where //! I: IntoIterator, //! I::Item: Into<ItemStr>, //! L: Lang, //! { //! from_fn(move |t| { //! let mut it = text.into_iter().peekable(); //! //! if it.peek().is_some() { //! quote_in! { *t => //! #(static_literal("/**")) //! #(for line in it join (#<push>) { //! #<space>* #(line.into()) //! }) //! #<space>#(static_literal("*/")) //! } //! } //! }) //! } //! //! # fn main() -> genco::fmt::Result { //! use genco::prelude::*; //! //! let tokens: java::Tokens = quote! { //! #(block_comment(&["This class is used for awesome stuff", "ok?"])) //! public static class Foo { //! } //! }; //! //! assert_eq!( //! vec![ //! "/**", //! " * This class is used for awesome stuff", //! " * ok?", //! " */", //! "public static class Foo {", //! "}" //! ], //! tokens.to_vec()? //! ); //! # Ok(()) //! # } //! ``` mod cursor; mod display; mod format_into; mod from_fn; mod item; mod item_str; mod quoted; mod register; mod static_literal; mod tokens; pub use self::display::{display, Display}; pub use self::format_into::FormatInto; pub use self::from_fn::{from_fn, FromFn}; pub use self::item::Item; pub use self::item_str::ItemStr; pub use self::quoted::{quoted, QuotedFn}; pub use self::register::{register, Register, RegisterFn}; pub use self::static_literal::static_literal; pub use self::tokens::Tokens;