pub fn dump_node(
code: &[u8],
node: &Node<'_>,
depth: i32,
line_start: Option<usize>,
line_end: Option<usize>,
) -> Result<()>Expand description
Dumps the AST of a code.
Returns a Result value, when an error occurs.
§Errors
Propagates any std::io::Error produced by the color-aware
writer that backs stdout (broken pipe, write failure, …).
§Examples
use big_code_analysis::{dump_node, tree_sitter, LANG, Node};
let source = b"int a = 42;";
let mut parser = tree_sitter::Parser::new();
parser
.set_language(
&LANG::Cpp
.get_tree_sitter_language()
.expect("cpp feature enabled"),
)
.expect("cpp grammar pinned to a compatible version");
let tree = parser.parse(source, None).expect("parser has a language set");
let root = Node(tree.root_node());
// Dump the AST from the first line of code in a file to the last one
dump_node(source, &root, -1, None, None).unwrap();