syntree::print

Function print

Source
pub fn print<O, T, F>(o: O, tree: &Tree<T, F>) -> Result<(), Error>
where O: Write, T: Copy + Debug, F: Flavor<Index: Display>,
Expand description

Pretty-print a tree without a source.

This will replace all source references with +. If you have a source available you can use print_with_source instead.

ยงExamples

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

use Syntax::*;

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(&mut s, &tree)?;

This would write:

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