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 Trigram,
28 Lingua,
30 Whatlang,
32}
33
34#[derive(Clone, Copy, Debug, PartialEq, Eq)]
36pub enum FormalizationLevel {
37 Natural,
39 Lexical,
41 Concept,
43 Logical,
45}
46
47#[derive(Clone, Copy, Debug, PartialEq, Eq)]
49pub enum NaturalizationDirection {
50 Naturalize,
52 Formalize,
54}
55
56#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
58pub enum AccessMode {
59 #[default]
62 Mutable,
63 ReadOnly,
67}
68
69impl AccessMode {
70 #[must_use]
72 pub const fn label(self) -> &'static str {
73 match self {
74 Self::Mutable => "mutable",
75 Self::ReadOnly => "read-only",
76 }
77 }
78
79 #[must_use]
81 pub const fn is_mutable(self) -> bool {
82 matches!(self, Self::Mutable)
83 }
84
85 #[must_use]
87 pub const fn is_read_only(self) -> bool {
88 matches!(self, Self::ReadOnly)
89 }
90}
91
92#[derive(Clone, Copy, Debug, PartialEq, Eq)]
94pub struct ParseConfiguration {
95 trivia_attachment_policy: TriviaAttachmentPolicy,
96 region_detection_policy: RegionDetectionPolicy,
97 language_identification_detector: LanguageIdentificationDetector,
98 formalization_level: FormalizationLevel,
99 naturalization_direction: NaturalizationDirection,
100 access_mode: AccessMode,
101 profile: Option<&'static str>,
102}
103
104impl ParseConfiguration {
105 #[must_use]
107 pub const fn new(trivia_attachment_policy: TriviaAttachmentPolicy) -> Self {
108 Self {
109 trivia_attachment_policy,
110 region_detection_policy: RegionDetectionPolicy::Both,
111 language_identification_detector: LanguageIdentificationDetector::Trigram,
112 formalization_level: FormalizationLevel::Natural,
113 naturalization_direction: NaturalizationDirection::Naturalize,
114 access_mode: AccessMode::Mutable,
115 profile: None,
116 }
117 }
118
119 #[must_use]
121 pub const fn with_region_detection_policy(
122 mut self,
123 region_detection_policy: RegionDetectionPolicy,
124 ) -> Self {
125 self.region_detection_policy = region_detection_policy;
126 self
127 }
128
129 #[must_use]
131 pub const fn with_language_identification_detector(
132 mut self,
133 detector: LanguageIdentificationDetector,
134 ) -> Self {
135 self.language_identification_detector = detector;
136 self
137 }
138
139 #[must_use]
141 pub const fn with_formalization_level(
142 mut self,
143 formalization_level: FormalizationLevel,
144 ) -> Self {
145 self.formalization_level = formalization_level;
146 self
147 }
148
149 #[must_use]
151 pub const fn with_naturalization_direction(
152 mut self,
153 naturalization_direction: NaturalizationDirection,
154 ) -> Self {
155 self.naturalization_direction = naturalization_direction;
156 self
157 }
158
159 #[must_use]
161 pub const fn with_access_mode(mut self, access_mode: AccessMode) -> Self {
162 self.access_mode = access_mode;
163 self
164 }
165
166 #[must_use]
172 pub const fn with_profile(mut self, profile: &'static str) -> Self {
173 self.profile = Some(profile);
174 self
175 }
176
177 #[must_use]
179 pub const fn trivia_attachment_policy(self) -> TriviaAttachmentPolicy {
180 self.trivia_attachment_policy
181 }
182
183 #[must_use]
185 pub const fn region_detection_policy(self) -> RegionDetectionPolicy {
186 self.region_detection_policy
187 }
188
189 #[must_use]
191 pub const fn language_identification_detector(self) -> LanguageIdentificationDetector {
192 self.language_identification_detector
193 }
194
195 #[must_use]
197 pub const fn formalization_level(self) -> FormalizationLevel {
198 self.formalization_level
199 }
200
201 #[must_use]
203 pub const fn naturalization_direction(self) -> NaturalizationDirection {
204 self.naturalization_direction
205 }
206
207 #[must_use]
209 pub const fn access_mode(self) -> AccessMode {
210 self.access_mode
211 }
212
213 #[must_use]
215 pub const fn profile(self) -> Option<&'static str> {
216 self.profile
217 }
218}
219
220impl Default for ParseConfiguration {
221 fn default() -> Self {
222 Self::new(TriviaAttachmentPolicy::Both)
223 }
224}