Remove parser function
//! that is configured to use this grammar, and then use the parser to parse some code:
//!
//! ```
+//! use tree_sitter::Parser;
+//!
//! let code = r#"
//! def double(x):
//! return x * 2
//! "#;
-//! let mut parser = tree_sitter_python::parser();
+//! let mut parser = Parser::new();
+//! parser.set_language(tree_sitter_python::language()).expect("Error loading Python grammar");
//! let parsed = parser.parse(code, None);
//! # assert!(parsed.is_some());
//! ```
//! [tree-sitter]: https://tree-sitter.github.io/
use tree_sitter::Language;
-use tree_sitter::Parser;
extern "C" {
fn tree_sitter_python() -> Language;
}
-/// Returns a new tree-sitter [Parser][] preconfigured to parse Python code.
-///
-/// [Parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html
-pub fn parser() -> Parser {
- let mut parser = Parser::new();
- parser
- .set_language(language())
- .expect("Error installing Python grammar");
- parser
-}
-
/// Returns the tree-sitter [Language][] for this grammar.
///
/// [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
@@ -61,6 +52,9 @@ pub const NODE_TYPES: &'static str = include_str!("../../src/node-types.json");
mod tests {
#[test]
fn can_load_grammar() {
- let _parser = super::parser();
+ let mut parser = tree_sitter::Parser::new();
+ parser
+ .set_language(super::language())
+ .expect("Error loading Python grammar");
}
}
