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