Skip to main content

mirascript_core/config/
mod.rs

1/// Mode for reading input.
2#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
3#[cfg_attr(
4    any(feature = "wasm", feature = "wasm-constants"),
5    wasm_bindgen::prelude::wasm_bindgen
6)]
7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8pub enum InputMode {
9    Script,
10    Template,
11}
12
13/// Encoding for counting positions in diagnostics.
14#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
15#[cfg_attr(
16    any(feature = "wasm", feature = "wasm-constants"),
17    wasm_bindgen::prelude::wasm_bindgen
18)]
19#[derive(Debug, Clone, Copy, PartialEq, Eq)]
20pub enum DiagnosticPositionEncoding {
21    /// Use the default encoding (UTF-8) and
22    /// 0-based indexing from the start of the file.
23    /// Do not convert positions to line-column format.
24    None,
25    /// Convert positions to 1-based UTF-8 line-column format.
26    Utf8,
27    /// Convert positions to 1-based UTF-16 line-column format.
28    Utf16,
29    /// Convert positions to 1-based UTF-32 line-column format.
30    Utf32,
31}
32
33#[cfg_attr(
34    feature = "serde",
35    derive(serde::Serialize, serde::Deserialize),
36    serde(default)
37)]
38#[cfg_attr(
39    any(feature = "wasm", feature = "wasm-constants"),
40    wasm_bindgen::prelude::wasm_bindgen
41)]
42#[derive(Debug, Clone, PartialEq)]
43pub struct Config {
44    #[cfg(feature = "formatter")]
45    pub trivia: bool,
46
47    pub input_mode: InputMode,
48
49    pub diagnostic_position_encoding: DiagnosticPositionEncoding,
50    pub diagnostic_error: bool,
51    pub diagnostic_warning: bool,
52    pub diagnostic_info: bool,
53    pub diagnostic_hint: bool,
54    pub diagnostic_reference: bool,
55    pub diagnostic_tag: bool,
56    pub diagnostic_sourcemap: bool,
57}
58
59#[cfg_attr(feature = "wasm", wasm_bindgen::prelude::wasm_bindgen)]
60impl Config {
61    #[cfg_attr(feature = "wasm", wasm_bindgen::prelude::wasm_bindgen(constructor))]
62    pub fn new() -> Self {
63        Self {
64            #[cfg(feature = "formatter")]
65            trivia: false,
66            input_mode: InputMode::Script,
67            diagnostic_position_encoding: DiagnosticPositionEncoding::Utf8,
68            diagnostic_error: true,
69            diagnostic_warning: true,
70            diagnostic_info: true,
71            diagnostic_hint: true,
72            diagnostic_reference: true,
73            diagnostic_tag: false,
74            diagnostic_sourcemap: false,
75        }
76    }
77}
78
79impl Default for Config {
80    fn default() -> Self {
81        Self::new()
82    }
83}
84
85#[cfg(feature = "wasm")]
86mod wasm;