pub enum Item<L>where
L: Lang,{
Literal(ItemStr),
Lang(usize, Box<L::Item>),
Register(usize, Box<L::Item>),
Push,
Line,
Space,
Indentation(i16),
OpenQuote(bool),
CloseQuote,
OpenEval,
CloseEval,
}
Expand description
A single item in a stream of tokens.
Variants§
Literal(ItemStr)
A literal item. Is added as a raw string to the stream of tokens.
Lang(usize, Box<L::Item>)
A language-specific item.
Register(usize, Box<L::Item>)
A language-specific item that is not rendered.
Push
Push a new line unless the current line is empty. Will be flushed on indentation changes.
Line
Push a line. Will be flushed on indentation changes.
Space
Space between language items. Typically a single space.
Multiple spacings in sequence are collapsed into one. A spacing does nothing if at the beginning of a line.
Indentation(i16)
Manage indentation.
An indentation of 0 has no effect.
OpenQuote(bool)
Switch to handling input as a quote.
The argument indicates whether the string contains any interpolated values.
The string content is quoted with the language-specific [quoting method]. [quoting method]: Lang::Openquote_string
CloseQuote
Close the current quote.
OpenEval
Switch on evaluation. Only valid during string handling.
CloseEval
Close evaluation.
Trait Implementations§
Source§impl<L> FormatInto<L> for Item<L>where
L: Lang,
Formatting an item is the same as simply adding that item to the token
stream.
impl<L> FormatInto<L> for Item<L>where
L: Lang,
Formatting an item is the same as simply adding that item to the token stream.
§Examples
use genco::prelude::*;
use genco::tokens::{Item, ItemStr};
let foo = Item::Literal(ItemStr::Static("foo"));
let bar = Item::Literal(ItemStr::Box("bar".into()));
let result: Tokens = quote!($foo $bar baz);
assert_eq!("foo bar baz", result.to_string()?);
assert_eq!{
vec![
Item::Literal(ItemStr::Static("foo")),
Item::Space,
Item::Literal(ItemStr::Box("bar".into())),
Item::Space,
Item::Literal(ItemStr::Static("baz")),
] as Vec<Item<()>>,
result,
};