Skip to main content

parse_string

Function parse_string 

Source
pub fn parse_string(language: &str, source: &[u8]) -> Result<Tree, Error>
Expand description

Parse source code with the named language, returning the syntax tree.

Uses the global registry to look up the language by name. Caches parsers per-thread so repeated calls for the same language avoid re-creating the parser.

ยงExamples

let tree = tree_sitter_language_pack::parse::parse_string("python", b"def hello(): pass").unwrap();
assert_eq!(tree.root_node().kind(), "module");