devgen_tree_sitter_php/lib.rs
1//! This crate provides php language support for the [tree-sitter][] parsing library.
2//!
3//! Typically, you will use the [language][language func] function to add this language to a
4//! tree-sitter [Parser][], and then use the parser to parse some code:
5//!
6//! ```
7//! let code = "";
8//! let mut parser = tree_sitter::Parser::new();
9//! parser.set_language(tree_sitter_php::language()).expect("Error loading php grammar");
10//! let tree = parser.parse(code, None).unwrap();
11//! ```
12//!
13//! [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
14//! [language func]: fn.language.html
15//! [Parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html
16//! [tree-sitter]: https://tree-sitter.github.io/
17
18use tree_sitter::Language;
19
20extern "C" {
21 fn tree_sitter_php() -> Language;
22 fn tree_sitter_php_only() -> Language;
23}
24
25/// Get the tree-sitter [Language][] for this grammar.
26///
27/// [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
28pub fn language_php() -> Language {
29 unsafe { tree_sitter_php() }
30}
31
32/// Get the tree-sitter [Language][] for this grammar.
33///
34/// [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
35pub fn language_php_only() -> Language {
36 unsafe { tree_sitter_php_only() }
37}
38
39/// The content of the [`node-types.json`][] file for this grammar.
40///
41/// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types
42pub const PHP_NODE_TYPES: &'static str = include_str!("../../php/src/node-types.json");
43pub const PHP_ONLY_NODE_TYPES: &'static str = include_str!("../../php_only/src/node-types.json");
44
45// Uncomment these to include any queries that this grammar contains
46
47pub const HIGHLIGHT_QUERY: &'static str = include_str!("../../queries/highlights.scm");
48pub const INJECTIONS_QUERY: &'static str = include_str!("../../queries/injections.scm");
49// pub const LOCALS_QUERY: &'static str = include_str!("../../queries/locals.scm");
50pub const TAGS_QUERY: &'static str = include_str!("../../queries/tags.scm");
51
52#[cfg(test)]
53mod tests {
54 #[test]
55 fn test_can_load_grammar() {
56 let mut parser = tree_sitter::Parser::new();
57 parser
58 .set_language(super::language())
59 .expect("Error loading php language");
60 }
61}