xsd_parser/config/
interpreter.rs

1use std::path::PathBuf;
2
3use bitflags::bitflags;
4
5use crate::models::meta::MetaType;
6use crate::traits::Naming;
7
8use super::IdentTriple;
9
10/// Configuration for the schema interpreter.
11#[derive(Debug)]
12pub struct InterpreterConfig {
13    /// List of user defined types to add to the interpreter before the schemas
14    /// are actually interpreted.
15    ///
16    /// See [`with_type`](crate::Interpreter::with_type) for more details.
17    pub types: Vec<(IdentTriple, MetaType)>,
18
19    /// Additional flags to control the interpreter.
20    pub flags: InterpreterFlags,
21
22    /// Wether to enable the debug output and where to write it to.
23    pub debug_output: Option<PathBuf>,
24
25    /// Controls how names are generated in the interpreter.
26    pub naming: Option<Box<dyn Naming>>,
27}
28
29impl Default for InterpreterConfig {
30    fn default() -> Self {
31        Self {
32            types: vec![],
33            debug_output: None,
34            flags: InterpreterFlags::BUILDIN_TYPES
35                | InterpreterFlags::DEFAULT_TYPEDEFS
36                | InterpreterFlags::WITH_XS_ANY_TYPE,
37            naming: None,
38        }
39    }
40}
41
42impl Clone for InterpreterConfig {
43    fn clone(&self) -> Self {
44        Self {
45            types: self.types.clone(),
46            debug_output: self.debug_output.clone(),
47            flags: self.flags.clone(),
48            naming: self.naming.as_deref().map(Naming::clone_boxed),
49        }
50    }
51}
52
53bitflags! {
54    /// Flags to control the [`Interpreter`](crate::Interpreter).
55    #[derive(Debug, Clone)]
56    pub struct InterpreterFlags: u32 {
57        /// Whether to add the build-in types to the interpreter or not.
58        ///
59        /// See [`with_buildin_types`](crate::Interpreter::with_buildin_types) for details.
60        const BUILDIN_TYPES = 1 << 0;
61
62        /// Whether to add the default types definitions to the interpreter or not.
63        ///
64        /// See [`with_default_typedefs`](crate::Interpreter::with_default_typedefs) for details.
65        const DEFAULT_TYPEDEFS = 1 << 1;
66
67        /// Whether to add a default type definitions for `xs:anyType` or not.
68        ///
69        /// See [`with_xs_any_type`](crate::Interpreter::with_xs_any_type) for details.
70        const WITH_XS_ANY_TYPE = 1 << 2;
71
72        /// Whether to use `num::BigInt` and `num::BigUint` instead of build-in integer types.
73        ///
74        /// See [`with_num_big_int`](crate::Interpreter::with_num_big_int) for details.
75        const WITH_NUM_BIG_INT = 1 << 3;
76    }
77}