hjkl_bonsai/lib.rs
1//! `hjkl-bonsai` — generic tree-sitter syntax highlighting for the hjkl editor stack.
2//!
3//! Grammars are loaded at runtime via the [`runtime`] module: the loader
4//! resolves `<name>.so` from a system / user / cache lookup chain, falling
5//! back to a clone + compile-on-demand path. Pair a [`runtime::Grammar`] with
6//! a [`Highlighter`] to drive parsing.
7//!
8//! # Quick start
9//!
10//! ```no_run
11//! use std::sync::Arc;
12//! use hjkl_bonsai::{Highlighter, DotFallbackTheme, Theme};
13//! use hjkl_bonsai::runtime::{Grammar, GrammarLoader, GrammarRegistry};
14//!
15//! let registry = GrammarRegistry::embedded()?;
16//! let loader = GrammarLoader::user_default(registry.meta())?;
17//!
18//! let spec = registry.by_name("rust").unwrap();
19//! let grammar = Arc::new(Grammar::load("rust", spec, &loader, registry.meta())?);
20//! let mut highlighter = Highlighter::new(grammar)?;
21//! let spans = highlighter.highlight(b"fn main() {}");
22//!
23//! let theme = DotFallbackTheme::dark();
24//! for span in &spans {
25//! if let Some(_style) = theme.style(span.capture()) {
26//! // apply style to byte_range in your renderer
27//! }
28//! }
29//! # Ok::<(), anyhow::Error>(())
30//! ```
31
32pub mod comment_markers;
33pub mod highlighter;
34pub mod runtime;
35pub mod theme;
36
37// Flat re-exports for the primary public API surface.
38pub use comment_markers::{CommentMarkerPass, MarkerWord, default_markers};
39pub use highlighter::{HighlightSpan, Highlighter, ParseError, Syntax};
40pub use theme::{DotFallbackTheme, Style, Theme};
41pub use tree_sitter::{InputEdit, Point};