tui_markup/parser/item.rs
1use crate::generator::{Tag, TagG};
2
3/// AST item.
4///
5/// In parsing stage, each line of source code will be parsed as a `Vec<Item>`, so the final result
6/// is `Vec<Vec<Item>>`.
7///
8/// Tag conversion stage, Each tag will be converted from [`&str`] into [Tag] type the generator
9/// needed, by using [`TagConvertor`][crate::generator::TagConvertor] of the generator.
10///
11/// In generating stage, generator will convert `Vec<Vec<Item<'_, Tag>>>` to final output.
12#[derive(Debug, Clone, PartialEq)]
13pub enum Item<'a, Tag = &'a str> {
14 /// Plain text(escaped) without any style.
15 PlainText(&'a str),
16 /// A styled element, contains a series tag name and subitems.
17 Element(Vec<Tag>, Vec<Item<'a, Tag>>),
18}
19
20/// Item type for tag convertor C.
21pub type ItemC<'a, C> = Item<'a, Tag<'a, C>>;
22
23/// Item type for generator G.
24pub type ItemG<'a, G> = Item<'a, TagG<'a, G>>;