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, Default)]
8pub enum InputMode {
9    /// Input is a full script, which may contain multiple statements and declarations.
10    #[default]
11    Script,
12    /// Input is a single string literal, which may contain escape sequences.
13    Template,
14}
15
16/// Encoding for counting positions in diagnostics.
17#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
18#[cfg_attr(
19    any(feature = "wasm", feature = "wasm-constants"),
20    wasm_bindgen::prelude::wasm_bindgen
21)]
22#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
23pub enum DiagnosticPositionEncoding {
24    /// Convert positions to 1-based UTF-8 line-column format.
25    #[default]
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 CompileConfig {
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 CompileConfig {
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 CompileConfig {
80    fn default() -> Self {
81        Self::new()
82    }
83}
84
85#[cfg(feature = "wasm")]
86mod wasm;