syntastica_macros/
schema.rs

1use std::fmt::{self, Display, Formatter};
2
3use serde::Deserialize;
4use tft::FileType;
5
6#[derive(Clone, Debug, Deserialize)]
7pub struct LanguageConfig {
8    pub languages: Vec<Language>,
9}
10
11fn default_true() -> bool {
12    true
13}
14
15#[derive(Clone, Debug, Deserialize, PartialEq, Eq)]
16#[serde(rename_all = "kebab-case")]
17pub struct Language {
18    pub name: String,
19    pub group: Group,
20    pub file_types: Vec<FileType>,
21    #[serde(default = "default_true")]
22    pub wasm: bool,
23    #[serde(default = "default_true")]
24    pub wasm_unknown: bool,
25    // TODO: injection regex
26    pub parser: Parser,
27    pub queries: Queries,
28}
29
30#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
31#[serde(rename_all = "kebab-case")]
32pub enum Group {
33    Some,
34    Most,
35    All,
36}
37
38impl Group {
39    #[allow(dead_code)] // is used in `xtask/src/codegen.rs`
40    pub fn next_smaller(&self) -> Option<Self> {
41        match self {
42            Group::Some => None,
43            Group::Most => Some(Group::Some),
44            Group::All => Some(Group::Most),
45        }
46    }
47}
48
49impl Display for Group {
50    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
51        match self {
52            Self::Some => write!(f, "some"),
53            Self::Most => write!(f, "most"),
54            Self::All => write!(f, "all"),
55        }
56    }
57}
58
59#[derive(Clone, Debug, Deserialize, PartialEq, Eq)]
60#[serde(rename_all = "kebab-case")]
61pub struct Parser {
62    pub git: ParserGit,
63    pub external_scanner: ParserExternal,
64    pub ffi_func: String,
65    pub rust_const: Option<String>,
66    pub rust_func: Option<String>,
67    pub package: String,
68    pub crates_io: Option<String>,
69    #[serde(default)]
70    pub generate: bool,
71}
72
73impl Parser {
74    pub fn supports_dep(&self) -> bool {
75        (self.rust_const.is_some() || self.rust_func.is_some()) && self.crates_io.is_some()
76    }
77
78    pub fn supports_gitdep(&self) -> bool {
79        (self.rust_const.is_some() || self.rust_func.is_some()) && !self.generate
80    }
81
82    pub fn supports(&self, git: bool) -> bool {
83        match git {
84            true => self.supports_gitdep(),
85            false => self.supports_dep(),
86        }
87    }
88}
89
90#[derive(Clone, Debug, Deserialize, PartialEq, Eq)]
91#[serde(rename_all = "kebab-case")]
92pub struct ParserGit {
93    pub url: String,
94    pub rev: String,
95    pub path: Option<String>,
96}
97
98#[derive(Clone, Debug, Deserialize, PartialEq, Eq)]
99#[serde(rename_all = "kebab-case")]
100pub struct ParserExternal {
101    pub c: bool,
102    pub cpp: bool,
103}
104
105#[derive(Clone, Debug, Deserialize, PartialEq, Eq)]
106#[serde(rename_all = "kebab-case")]
107pub struct Queries {
108    pub nvim_like: bool,
109    pub injections: bool,
110    pub locals: bool,
111}