Skip to main content

tree_to_string

Function tree_to_string 

Source
pub fn tree_to_string(node: &SyntaxNode<Lang>) -> String
Expand description

Returns a string representation of the CST structure.

Like print_tree but returns a string instead of printing to stdout.

ยงExample

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

let yaml = YamlFile::from_str("name: Alice").unwrap();
let tree_str = debug::tree_to_string(yaml.syntax());

let expected = "DOCUMENT\n  MAPPING\n    MAPPING_ENTRY\n      KEY\n        SCALAR\n          STRING: \"name\"\n      COLON: \":\"\n      WHITESPACE: \" \"\n      VALUE\n        SCALAR\n          STRING: \"Alice\"\n";
assert_eq!(tree_str, expected);