← rgit
/
main
/
tree-sitter-grammar-repository/src/lib.rs
https://dev.kronoz.win/r/rgit.git
1//! # tree-sitter-grammar-repository
2//!
3//! This crate loads in all known languages and grammars from `helix`'s
4//! `languages.toml` at compile time and provides an easy way for you
5//! to easily map the language to a highlighter configuration.
6//!
7//! `tree-sitter` grammars can be dynamically linked by setting the
8//! `TREE_SITTER_GRAMMAR_LIB_DIR` environment variable. If set, this library
9//! expects a directory of the format:
10//!
11//! ```text
12//! - TREE_SITTER_GRAMMAR_LIB_DIR
13//! - sources/
14//! - html/
15//! - queries/
16//! - highlights.scm
17//! - injections.scm
18//! - package.json
19//! - javascript/
20//! - queries/
21//! - highlights.scm
22//! - injections.scm
23//! - package.json
24//! - libhtml-parser.so
25//! - libhtml-scanner.so
26//! - libjavascsript-scanner.so
27//! - ...
28//! ```
29//!
30//! Usage:
31//!
32//! ```ignore
33//! use std::collections::HashMap;
34//! use tree_sitter_grammar_repository::Grammar;
35//! use tree_sitter_highlight::HighlightConfiguration;
36//!
37//! let highlighter_configurations = Grammar::VARIANTS
38//! .iter()
39//! .copied()
40//! .map(Grammar::highlight_configuration_params)
41//! .map(|v| (v, HighlightConfiguration::new(
42//! v.language.into(),
43//! v.name,
44//! v.highlights_query,
45//! v.injection_query,
46//! v.locals_query
47//! )))
48//! .collect::<HashMap<Grammar, HighlightConfiguration>>();
49//!
50//! let highlighter_configuration = highlighter_configurations
51//! .get(&Language::from_file_name("hello_world.toml").grammar());
52//! ```
53
54include!(concat!(env!("OUT_DIR"), "/grammar.registry.rs"));
55include!(concat!(env!("OUT_DIR"), "/language.registry.rs"));
56pub mod grammar {
57 include!(concat!(env!("OUT_DIR"), "/grammar.defs.rs"));
58}
59
60pub struct HighlightConfigurationParams {
61 pub language: tree_sitter_language::LanguageFn,
62 pub name: &'static str,
63 pub highlights_query: &'static str,
64 pub injection_query: &'static str,
65 pub locals_query: &'static str,
66}