Crate tree_sitter_test

Source
Expand description

This crate provides TS corpus test support for the tree-sitter parsing library.

Typically, you will use the LANGUAGE constant to add this language to a tree-sitter Parser, and then use the parser to parse some code:

let code = r#"
==================
Return statements
==================

func x() int {
  return 1;
}

---

(source_file
  (function_definition
    (identifier)
    (parameter_list)
    (primitive_type)
    (block
      (return_statement (number)))))
"#;
let mut parser = tree_sitter::Parser::new();
let language = tree_sitter_test::LANGUAGE;
parser
    .set_language(&language.into())
    .expect("Error loading Test parser");
let tree = parser.parse(code, None).unwrap();
assert!(!tree.root_node().has_error());

Constantsยง

HIGHLIGHTS_QUERY
The syntax highlight queries for this grammar.
INJECTIONS_QUERY
The language injection queries for this grammar.
LANGUAGE
The tree-sitter LanguageFn for this grammar.
NODE_TYPES
The content of the node-types.json file for this grammar.