Skip to main content

print_tree

Function print_tree 

Source
pub fn print_tree(node: &SyntaxNode<Lang>)
Expand description

Prints the CST (Concrete Syntax Tree) structure to stdout.

This is invaluable for understanding how YAML is parsed into the tree structure, debugging formatting issues, and verifying that mutations produce the expected tree.

ยงExample

use yaml_edit::{YamlFile, debug};
use rowan::ast::AstNode;
use std::str::FromStr;

let yaml = YamlFile::from_str("team:\n  - Alice\n  - Bob").unwrap();
debug::print_tree(yaml.syntax());

Output:

DOCUMENT
  MAPPING
    MAPPING_ENTRY
      KEY
        SCALAR
          STRING: "team"
      COLON: ":"
      VALUE
        NEWLINE: "\n"
        INDENT: "  "
        SEQUENCE
          SEQUENCE_ENTRY
            DASH: "-"
            WHITESPACE: " "
            SCALAR
              STRING: "Alice"
            NEWLINE: "\n"
...