Skip to main content

tui_syntax/languages/
mod.rs

1//! Language definitions for syntax highlighting.
2//!
3//! Each language provides a tree-sitter grammar and highlight queries.
4
5mod html;
6mod json;
7mod sql;
8
9pub use html::html;
10pub use json::json;
11pub use sql::sql;
12
13use tree_sitter::Language as TsLanguage;
14
15/// Error configuring a language.
16#[derive(Debug)]
17pub enum LanguageError {
18    /// Failed to create highlight configuration
19    HighlightConfig(String),
20}
21
22impl std::fmt::Display for LanguageError {
23    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
24        match self {
25            LanguageError::HighlightConfig(msg) => write!(f, "Highlight config error: {}", msg),
26        }
27    }
28}
29
30impl std::error::Error for LanguageError {}
31
32/// A language configuration for syntax highlighting.
33pub struct Language {
34    /// Language name (e.g., "sql", "rust", "python")
35    pub name: &'static str,
36    /// Tree-sitter language grammar
37    pub ts_language: TsLanguage,
38    /// Highlight queries (tree-sitter query syntax)
39    pub highlights_query: &'static str,
40    /// Injection queries (for embedded languages, optional)
41    pub injections_query: &'static str,
42    /// Locals queries (for local variable scoping, optional)
43    pub locals_query: &'static str,
44}