1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
//! This crate provides Salesforce Apex, SOQL, SOSL, and Log syntax support for the [tree-sitter] parsing library.
//!
//! Typically, you will use the [apex::LANGUAGE] constant to add this language to a
//! tree-sitter [Parser], and then use the parser to parse some code:
//!
//! ```
//! use tree_sitter::Parser;
//!
//! let code = r#"
//! public class Test123 {
//! public Test123(){}
//! }
//! "#;
//! let mut parser = Parser::new();
//! let language_fn = tree_sitter_sfapex::apex::LANGUAGE;
//! parser
//! .set_language(&language_fn.into())
//! .expect("Error loading Apex parser");
//! let tree = parser.parse(code, None).unwrap();
//! assert!(!tree.root_node().has_error());
//! ```
//!
//! [Parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html
//! [tree-sitter]: https://tree-sitter.github.io/
pub mod apex {
use tree_sitter_language::LanguageFn;
extern "C" {
fn tree_sitter_apex() -> *const ();
}
/// Returns the tree-sitter [LanguageFn] for this grammar.
///
/// [LanguageFn]: https://docs.rs/tree-sitter-language/*/tree_sitter_language/struct.LanguageFn.html
pub const LANGUAGE: LanguageFn = unsafe { LanguageFn::from_raw(tree_sitter_apex) };
/// The content of the [`node-types.json`] file for this grammar.
///
/// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types
pub const NODE_TYPES: &str = include_str!("../../apex/src/node-types.json");
/// The syntax highlighting query for this language.
pub const HIGHLIGHTS_QUERY: &str = include_str!("../../apex/queries/highlights.scm");
// /// The injections query for this language.
// pub const INJECTIONS_QUERY: &str = include_str!("../../apex/queries/injections.scm");
/// The symbol tagging query for this language.
pub const TAGS_QUERY: &str = include_str!("../../apex/queries/tags.scm");
}
pub mod soql {
use tree_sitter_language::LanguageFn;
extern "C" {
fn tree_sitter_soql() -> *const ();
}
/// Returns the tree-sitter [LanguageFn] for this grammar.
///
/// [LanguageFn]: https://docs.rs/tree-sitter-language/*/tree_sitter_language/struct.LanguageFn.html
pub const LANGUAGE: LanguageFn = unsafe { LanguageFn::from_raw(tree_sitter_soql) };
/// The content of the [`node-types.json`] file for this grammar.
///
/// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types
pub const NODE_TYPES: &str = include_str!("../../soql/src/node-types.json");
/// The syntax highlighting query for this language.
pub const HIGHLIGHTS_QUERY: &str = include_str!("../../soql/queries/highlights.scm");
// /// The injections query for this language.
// pub const INJECTIONS_QUERY: &str = include_str!("../../soql/queries/injections.scm");
// /// The symbol tagging query for this language.
// pub const TAGS_QUERY: &str = include_str!("../../soql/queries/tags.scm");
}
pub mod sosl {
use tree_sitter_language::LanguageFn;
extern "C" {
fn tree_sitter_sosl() -> *const ();
}
/// Returns the tree-sitter [LanguageFn] for this grammar.
///
/// [LanguageFn]: https://docs.rs/tree-sitter-language/*/tree_sitter_language/struct.LanguageFn.html
pub const LANGUAGE: LanguageFn = unsafe { LanguageFn::from_raw(tree_sitter_sosl) };
/// The content of the [`node-types.json`] file for this grammar.
///
/// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types
pub const NODE_TYPES: &str = include_str!("../../sosl/src/node-types.json");
/// The syntax highlighting query for this language.
pub const HIGHLIGHTS_QUERY: &str = include_str!("../../sosl/queries/highlights.scm");
// /// The injections query for this language.
// pub const INJECTIONS_QUERY: &str = include_str!("../../sosl/queries/injections.scm");
// /// The symbol tagging query for this language.
// pub const TAGS_QUERY: &str = include_str!("../../sosl/queries/tags.scm");
}
pub mod sflog {
use tree_sitter_language::LanguageFn;
extern "C" {
fn tree_sitter_sflog() -> *const ();
}
/// Returns the tree-sitter [LanguageFn] for this grammar.
///
/// [LanguageFn]: https://docs.rs/tree-sitter-language/*/tree_sitter_language/struct.LanguageFn.html
pub const LANGUAGE: LanguageFn = unsafe { LanguageFn::from_raw(tree_sitter_sflog) };
/// The content of the [`node-types.json`] file for this grammar.
///
/// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types
pub const NODE_TYPES: &str = include_str!("../../sflog/src/node-types.json");
/// The syntax highlighting query for this language.
pub const HIGHLIGHTS_QUERY: &str = include_str!("../../sflog/queries/highlights.scm");
// /// The injections query for this language.
// pub const INJECTIONS_QUERY: &str = include_str!("../../sflog/queries/injections.scm");
// /// The symbol tagging query for this language.
// pub const TAGS_QUERY: &str = include_str!("../../sflog/queries/tags.scm");
}
#[cfg(test)]
mod tests {
use tree_sitter::Parser;
// Helper function to test language loading
fn test_language_loading(language_fn: tree_sitter_language::LanguageFn) {
let mut parser = Parser::new();
parser
.set_language(&language_fn.into())
.expect("Failed to load language parser");
}
#[test]
fn test_can_load_apex_grammar() {
test_language_loading(super::apex::LANGUAGE);
}
#[test]
fn test_can_load_soql_grammar() {
test_language_loading(super::soql::LANGUAGE);
}
#[test]
fn test_can_load_sosl_grammar() {
test_language_loading(super::sosl::LANGUAGE);
}
#[test]
fn test_can_load_sflog_grammar() {
test_language_loading(super::sflog::LANGUAGE);
}
}