Skip to main content

Crate tree_sitter_java

Crate tree_sitter_java 

Source
Expand description

This crate provides Java language support for the tree-sitter parsing library.

The parser carries the ABI number of the WillBooster fork (0x57420007) and is tested with the willbooster-tree-sitter runtime 9.0.0 (depend on it as tree-sitter = { package = "willbooster-tree-sitter", version = "9.0.0" }). Runtimes with a different ABI, including upstream’s tree-sitter crate, reject it with a LanguageError.

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 = "class Main {\n    int answer() {\n        return 42;\n    }\n}\n";
let mut parser = tree_sitter::Parser::new();
let language = tree_sitter_java::LANGUAGE;
parser
    .set_language(&language.into())
    .expect("Error loading Java parser");
let tree = parser.parse(code, None).unwrap();
assert!(!tree.root_node().has_error());

Constants§

LANGUAGE
The tree-sitter LanguageFn for this grammar.
NODE_TYPES
The content of the node-types.json file for this grammar.