tree_sitter_asm/lib.rs
1//! This crate provides asm language support for the [tree-sitter][] parsing library.
2//!
3//! Typically, you will use the [LANGUAGE][] constant to add this language to a
4//! tree-sitter [Parser][], and then use the parser to parse some code:
5//!
6//! ```
7//! let code = "pushq %rbp, %rbp";
8//! let mut parser = tree_sitter::Parser::new();
9//! let language = tree_sitter_asm::LANGUAGE;
10//! parser
11//! .set_language(&language.into())
12//! .expect("Error loading asm parser");
13//! let tree = parser.parse(code, None).unwrap();
14//! assert!(!tree.root_node().has_error());
15//! ```
16//!
17//! [Parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html
18//! [tree-sitter]: https://tree-sitter.github.io/
19
20use tree_sitter_language::LanguageFn;
21
22extern "C" {
23 fn tree_sitter_asm() -> *const ();
24}
25
26/// The tree-sitter [`LanguageFn`][LanguageFn] for this grammar.
27///
28/// [LanguageFn]: https://docs.rs/tree-sitter-language/*/tree_sitter_language/struct.LanguageFn.html
29pub const LANGUAGE: LanguageFn = unsafe { LanguageFn::from_raw(tree_sitter_asm) };
30
31/// The content of the [`node-types.json`][] file for this grammar.
32///
33/// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types
34pub const NODE_TYPES: &str = include_str!("../../src/node-types.json");
35
36pub const HIGHLIGHTS_QUERY: &str = include_str!("../../queries/asm/highlights.scm");
37// pub const INJECTIONS_QUERY: &str = include_str!("../../queries/injections.scm");
38// pub const LOCALS_QUERY: &str = include_str!("../../queries/locals.scm");
39// pub const TAGS_QUERY: &str = include_str!("../../queries/tags.scm");
40
41#[cfg(test)]
42mod tests {
43 #[test]
44 fn test_can_load_grammar() {
45 let mut parser = tree_sitter::Parser::new();
46 parser
47 .set_language(&super::LANGUAGE.into())
48 .expect("Error loading asm parser");
49 }
50}