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, Ast, LANG, Source};
let source = b"int a = 42;";
let ast = Ast::parse(Source::new(LANG::Cpp, source))
.expect("cpp feature enabled");
let root = ast.root_node();
// Dump the AST from the first line of code in a file to the last one
dump_node(ast.source(), &root, -1, None, None).unwrap();§Panics
Panics if code is not the exact source node was parsed from.
node’s byte range is used to slice code, so a node taken from a
different (or smaller) tree indexes out of bounds. Always pair a node
with the source it came from — e.g. ast.source() and a node obtained
from the same crate::Ast (ast.root_node() or a descendant).