lux_lib/lua_rockspec/build/
tree_sitter.rs

1use std::{collections::HashMap, path::PathBuf};
2
3use mlua::UserData;
4
5#[derive(Debug, PartialEq, Default, Clone)]
6pub struct TreesitterParserBuildSpec {
7    /// Name of the parser language, e.g. "haskell"
8    pub lang: String,
9
10    /// Won't build the parser if `false`
11    /// (useful for packages that only include queries)
12    pub parser: bool,
13
14    /// Must the sources be generated?
15    pub generate: bool,
16
17    /// tree-sitter grammar's location (relative to the source root)
18    pub location: Option<PathBuf>,
19
20    /// Embedded queries to be installed in the `etc/queries` directory
21    pub queries: HashMap<PathBuf, String>,
22}
23
24impl UserData for TreesitterParserBuildSpec {
25    fn add_methods<M: mlua::UserDataMethods<Self>>(methods: &mut M) {
26        methods.add_method("lang", |_, this, _: ()| Ok(this.lang.clone()));
27        methods.add_method("parser", |_, this, _: ()| Ok(this.parser));
28        methods.add_method("generate", |_, this, _: ()| Ok(this.generate));
29        methods.add_method("location", |_, this, _: ()| Ok(this.location.clone()));
30        methods.add_method("queries", |_, this, _: ()| Ok(this.queries.clone()));
31    }
32}