1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
use serde::Deserialize;

pub mod toml;

fn default_true() -> bool {
    true
}

#[derive(Deserialize)]
pub enum Mode {
    #[serde(rename = "lwb")]
    Lwb,
    #[serde(rename = "parser")]
    Parser,
    #[serde(rename = "parser")]
    Custom(String),
}

impl Mode {
    pub fn import_location(&self) -> &str {
        match self {
            Mode::Lwb => "rust_lwb",
            Mode::Parser => "lwb_parser",
            Mode::Custom(a) => a,
        }
    }
}

impl Default for Mode {
    fn default() -> Self {
        Self::Parser
    }
}

#[derive(Deserialize)]
pub struct SyntaxConfig {
    /// The location (path) where the generated code should be
    /// written, relative to the configuration file
    pub destination: String,

    /// The path to the syntax definition file, relative to the
    /// configuration file
    pub definition: String,

    /// Make AST items have the non-exhaustive attribute. This
    /// improves backwards compatibility, but reduces the number
    /// of checks the rust compiler can do on your code using the
    /// AST (ie. you can make more variants, but not handling the
    /// new variant is not an error with this on).
    ///
    /// Set to whichever you prefer.
    #[serde(default)]
    pub non_exhaustive: bool,

    /// Derive serde traits for the AST types
    #[serde(default)]
    pub serde: bool,

    /// The mode to work in. Defaults to parser since rust_lwb is far from done.
    /// This also sets import_location to lwb_parser
    #[serde(default)]
    pub mode: Mode,

    #[doc(hidden)]
    #[serde(default = "default_true")]
    pub write_serialized_ast: bool, // always true except during bootstrap.
}

#[derive(Deserialize)]
pub struct LanguageConfig {
    /// The name of your language
    pub name: String,

    /// The different extensions associated with your language
    #[serde(default)]
    pub extensions: Vec<String>,
}

#[derive(Deserialize)]
pub struct Config {
    pub syntax: SyntaxConfig,
    pub language: LanguageConfig,
}