lwb_parser/config/
mod.rs

1use serde::Deserialize;
2
3pub mod toml;
4
5fn default_true() -> bool {
6    true
7}
8
9#[derive(Deserialize)]
10pub enum Mode {
11    #[serde(rename = "lwb")]
12    Lwb,
13    #[serde(rename = "parser")]
14    Parser,
15    #[serde(rename = "parser")]
16    Custom(String),
17}
18
19impl Mode {
20    pub fn import_location(&self) -> &str {
21        match self {
22            Mode::Lwb => "rust_lwb",
23            Mode::Parser => "lwb_parser",
24            Mode::Custom(a) => a,
25        }
26    }
27}
28
29impl Default for Mode {
30    fn default() -> Self {
31        Self::Parser
32    }
33}
34
35#[derive(Deserialize)]
36pub struct SyntaxConfig {
37    /// The location (path) where the generated code should be
38    /// written, relative to the configuration file
39    pub destination: String,
40
41    /// The path to the syntax definition file, relative to the
42    /// configuration file
43    pub definition: String,
44
45    /// Make AST items have the non-exhaustive attribute. This
46    /// improves backwards compatibility, but reduces the number
47    /// of checks the rust compiler can do on your code using the
48    /// AST (ie. you can make more variants, but not handling the
49    /// new variant is not an error with this on).
50    ///
51    /// Set to whichever you prefer.
52    #[serde(default)]
53    pub non_exhaustive: bool,
54
55    /// Derive serde traits for the AST types
56    #[serde(default)]
57    pub serde: bool,
58
59    /// The mode to work in. Defaults to parser since rust_lwb is far from done.
60    /// This also sets import_location to lwb_parser
61    #[serde(default)]
62    pub mode: Mode,
63
64    #[doc(hidden)]
65    #[serde(default = "default_true")]
66    pub write_serialized_ast: bool, // always true except during bootstrap.
67}
68
69#[derive(Deserialize)]
70pub struct LanguageConfig {
71    /// The name of your language
72    pub name: String,
73
74    /// The different extensions associated with your language
75    #[serde(default)]
76    pub extensions: Vec<String>,
77}
78
79#[derive(Deserialize)]
80pub struct Config {
81    pub syntax: SyntaxConfig,
82    pub language: LanguageConfig,
83}