meta_language/
configuration.rs1#[derive(Clone, Copy, Debug, PartialEq, Eq)]
3pub enum TriviaAttachmentPolicy {
4 ContainmentLink,
6 TokenLink,
8 Both,
10}
11
12#[derive(Clone, Copy, Debug, PartialEq, Eq)]
14pub enum RegionDetectionPolicy {
15 NameDriven,
17 ContentDriven,
19 Both,
21}
22
23#[derive(Clone, Copy, Debug, PartialEq, Eq)]
25pub enum LanguageIdentificationDetector {
26 Lingua,
28 Whatlang,
30}
31
32#[derive(Clone, Copy, Debug, PartialEq, Eq)]
34pub enum FormalizationLevel {
35 Natural,
37 Lexical,
39 Concept,
41 Logical,
43}
44
45#[derive(Clone, Copy, Debug, PartialEq, Eq)]
47pub enum NaturalizationDirection {
48 Naturalize,
50 Formalize,
52}
53
54#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
56pub enum AccessMode {
57 #[default]
60 Mutable,
61 ReadOnly,
65}
66
67impl AccessMode {
68 #[must_use]
70 pub const fn label(self) -> &'static str {
71 match self {
72 Self::Mutable => "mutable",
73 Self::ReadOnly => "read-only",
74 }
75 }
76
77 #[must_use]
79 pub const fn is_mutable(self) -> bool {
80 matches!(self, Self::Mutable)
81 }
82
83 #[must_use]
85 pub const fn is_read_only(self) -> bool {
86 matches!(self, Self::ReadOnly)
87 }
88}
89
90#[derive(Clone, Copy, Debug, PartialEq, Eq)]
92pub struct ParseConfiguration {
93 trivia_attachment_policy: TriviaAttachmentPolicy,
94 region_detection_policy: RegionDetectionPolicy,
95 language_identification_detector: LanguageIdentificationDetector,
96 formalization_level: FormalizationLevel,
97 naturalization_direction: NaturalizationDirection,
98 access_mode: AccessMode,
99 profile: Option<&'static str>,
100}
101
102impl ParseConfiguration {
103 #[must_use]
105 pub const fn new(trivia_attachment_policy: TriviaAttachmentPolicy) -> Self {
106 Self {
107 trivia_attachment_policy,
108 region_detection_policy: RegionDetectionPolicy::Both,
109 language_identification_detector: LanguageIdentificationDetector::Lingua,
110 formalization_level: FormalizationLevel::Natural,
111 naturalization_direction: NaturalizationDirection::Naturalize,
112 access_mode: AccessMode::Mutable,
113 profile: None,
114 }
115 }
116
117 #[must_use]
119 pub const fn with_region_detection_policy(
120 mut self,
121 region_detection_policy: RegionDetectionPolicy,
122 ) -> Self {
123 self.region_detection_policy = region_detection_policy;
124 self
125 }
126
127 #[must_use]
129 pub const fn with_language_identification_detector(
130 mut self,
131 detector: LanguageIdentificationDetector,
132 ) -> Self {
133 self.language_identification_detector = detector;
134 self
135 }
136
137 #[must_use]
139 pub const fn with_formalization_level(
140 mut self,
141 formalization_level: FormalizationLevel,
142 ) -> Self {
143 self.formalization_level = formalization_level;
144 self
145 }
146
147 #[must_use]
149 pub const fn with_naturalization_direction(
150 mut self,
151 naturalization_direction: NaturalizationDirection,
152 ) -> Self {
153 self.naturalization_direction = naturalization_direction;
154 self
155 }
156
157 #[must_use]
159 pub const fn with_access_mode(mut self, access_mode: AccessMode) -> Self {
160 self.access_mode = access_mode;
161 self
162 }
163
164 #[must_use]
170 pub const fn with_profile(mut self, profile: &'static str) -> Self {
171 self.profile = Some(profile);
172 self
173 }
174
175 #[must_use]
177 pub const fn trivia_attachment_policy(self) -> TriviaAttachmentPolicy {
178 self.trivia_attachment_policy
179 }
180
181 #[must_use]
183 pub const fn region_detection_policy(self) -> RegionDetectionPolicy {
184 self.region_detection_policy
185 }
186
187 #[must_use]
189 pub const fn language_identification_detector(self) -> LanguageIdentificationDetector {
190 self.language_identification_detector
191 }
192
193 #[must_use]
195 pub const fn formalization_level(self) -> FormalizationLevel {
196 self.formalization_level
197 }
198
199 #[must_use]
201 pub const fn naturalization_direction(self) -> NaturalizationDirection {
202 self.naturalization_direction
203 }
204
205 #[must_use]
207 pub const fn access_mode(self) -> AccessMode {
208 self.access_mode
209 }
210
211 #[must_use]
213 pub const fn profile(self) -> Option<&'static str> {
214 self.profile
215 }
216}
217
218impl Default for ParseConfiguration {
219 fn default() -> Self {
220 Self::new(TriviaAttachmentPolicy::Both)
221 }
222}