pub fn print_with_source<O, T, I, W>(
    o: O,
    tree: &Tree<T, I, W>,
    source: &str
) -> Result<(), Error>where
    O: Write,
    T: Debug,
    I: Index + Display,
    W: Width,
Expand description

Pretty-print a tree with the source spans printed.

Examples

#[derive(Debug)]
enum Syntax {
    NUMBER,
    WHITESPACE,
    OPERATOR,
    PLUS,
}

use Syntax::*;

let source = "128 + 64";

let tree = syntree::tree! {
    NUMBER => {
        (NUMBER, 3),
    },
    (WHITESPACE, 1),
    OPERATOR => {
        (PLUS, 1)
    },
    (WHITESPACE, 1),
    NUMBER => {
        (NUMBER, 2),
    },
};

let mut s = Vec::new();
syntree::print::print_with_source(&mut s, &tree, source)?;

This would write:

NUMBER@0..3
  NUMBER@0..3 "128"
WHITESPACE@3..4 " "
OPERATOR@4..5
  PLUS@4..5 "+"
WHITESPACE@5..6 " "
NUMBER@6..8
  NUMBER@6..8 "64"