[][src]Macro shoebill::compose

macro_rules! compose {
    ( $pr:expr; g @ $($rest:tt)* ) => { ... };
    ( $pr:expr; n @ $($rest:tt)* ) => { ... };
    ( $pr:expr; $x:tt @ $($rest:tt)* ) => { ... };
    ( $pr:expr; ($($x:tt)*) ) => { ... };
    ( $pr:expr; $l:tt <> $r:tt $($rest:tt)* ) => { ... };
    ( $pr:expr; $l:tt <s> $r:tt $($rest:tt)* ) => { ... };
    ( $pr:expr; $l:tt <n> $r:tt $($rest:tt)* ) => { ... };
    ( $pr:expr; $l:tt <z> $r:tt $($rest:tt)* ) => { ... };
    ( $pr:expr; $l:tt <h> $r:tt $($rest:tt)* ) => { ... };
    ( $pr:expr ; $d:expr ) => { ... };
}

Macro for allowing more pleasant composition items that implement Doclike using more familiar operators. The infix operators (which are all left-associtive, but allow for grouping w/ parentheses)

 //`a <> b` : Concat(a, b)
 //`a <n> b` : Concat(a, Concat(newline, b))
 //`a <s> b` : Concat(a, Concat(" ", b)) (concat with a space)
 //`a <h> b` : Concat(a, Concat(" ", b)) (concat with Hardline)
 //`n @ ds` : prefix ds with a newline
 //`g @ ds` : make ds a group
 //`<any u32> @ ds` : nest ds by whatever the amount specified by the integer literal.

There are some issues I need to come back to that aren't bugs, but certain things like "x" (n @ (<s> "y")) don't work like one might expect them to.

use shoebill::{ compose, Printer, Doclike };
let mut store = Printer::new();
let d = compose!(&mut store ; "this" <s> "is" <s> "text");
assert_eq!(format!("{}", d.render(80, &mut store)), format!("this is text"));