aravagarwal/CodeCloakPII
0
1//! This crate provides Python language support for the [tree-sitter][] parsing library.2//!3//! Typically, you will use the [language][language func] function to add this language to a4//! tree-sitter [Parser][], and then use the parser to parse some code:5//!6//! ```7//! let code = r#"8//! def double(x):9//! return x * 210//! "#;11//! let mut parser = tree_sitter::Parser::new();12//! parser.set_language(&tree_sitter_python::language()).expect("Error loading Python grammar");13//! let tree = parser.parse(code, None).unwrap();14//! assert!(!tree.root_node().has_error());15//! ```16//!17//! [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html18//! [language func]: fn.language.html19//! [Parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html20//! [tree-sitter]: https://tree-sitter.github.io/21 22use tree_sitter::Language;23 24extern "C" {25 fn tree_sitter_python() -> Language;26}27 28/// Get the tree-sitter [Language][] for this grammar.29///30/// [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html31pub fn language() -> Language {32 unsafe { tree_sitter_python() }33}34 35/// The source of the Python tree-sitter grammar description.36pub const GRAMMAR: &str = include_str!("../../grammar.js");37 38/// The content of the [`node-types.json`][] file for this grammar.39///40/// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types41pub const NODE_TYPES: &str = include_str!("../../src/node-types.json");42 43pub const HIGHLIGHTS_QUERY: &str = include_str!("../../queries/highlights.scm");44pub const TAGS_QUERY: &str = include_str!("../../queries/tags.scm");45 46#[cfg(test)]47mod tests {48 #[test]49 fn test_can_load_grammar() {50 let mut parser = tree_sitter::Parser::new();51 parser52 .set_language(&super::language())53 .expect("Error loading Python grammar");54 }55}56 