1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/// Trivia attachment strategy.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum TriviaAttachmentPolicy {
/// Attach trivia to the containing syntax link.
ContainmentLink,
/// Attach trivia to the token link.
TokenLink,
/// Emit both attachment links when they can coexist.
Both,
}
/// Region detection strategy for mixed-language parsing.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum RegionDetectionPolicy {
/// Use explicit region names such as fenced-code language tags.
NameDriven,
/// Use content sniffing.
ContentDriven,
/// Use name-driven detection first and content-driven detection as a fallback.
Both,
}
/// Natural-language identification backend.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum LanguageIdentificationDetector {
/// Use `lingua` for language identification.
Lingua,
/// Use `whatlang` for language identification.
Whatlang,
}
/// Configured amount of formal meaning to expose during reconstruction.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum FormalizationLevel {
/// Natural surface text in the requested target language.
Natural,
/// Predicate form using target-language labels where they are available.
Lexical,
/// Predicate form using shared concept identifiers.
Concept,
/// Link-like proposition form including the truth marker.
Logical,
}
/// Direction for text/network conversion.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum NaturalizationDirection {
/// Prefer target-language natural text when reconstructing.
Naturalize,
/// Prefer the configured formal representation when reconstructing.
Formalize,
}
/// Whether the engine produces a mutable network or an enforced read-only one.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
pub enum AccessMode {
/// The network is editable: mutators such as `insert_link` and
/// `apply_substitution` are available on `&mut LinkNetwork`.
#[default]
Mutable,
/// The network is frozen: only `&self` operations (query, project,
/// reconstruct, verify, serialize) are reachable, and mutation attempts at
/// the engine boundary fail with a clear diagnostic.
ReadOnly,
}
impl AccessMode {
/// Human-readable access-mode name.
#[must_use]
pub const fn label(self) -> &'static str {
match self {
Self::Mutable => "mutable",
Self::ReadOnly => "read-only",
}
}
/// Whether this access mode permits mutation.
#[must_use]
pub const fn is_mutable(self) -> bool {
matches!(self, Self::Mutable)
}
/// Whether this access mode forbids mutation.
#[must_use]
pub const fn is_read_only(self) -> bool {
matches!(self, Self::ReadOnly)
}
}
/// Configuration for parse-to-network operations.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct ParseConfiguration {
trivia_attachment_policy: TriviaAttachmentPolicy,
region_detection_policy: RegionDetectionPolicy,
language_identification_detector: LanguageIdentificationDetector,
formalization_level: FormalizationLevel,
naturalization_direction: NaturalizationDirection,
access_mode: AccessMode,
profile: Option<&'static str>,
}
impl ParseConfiguration {
/// Creates parse configuration with the supplied trivia policy.
#[must_use]
pub const fn new(trivia_attachment_policy: TriviaAttachmentPolicy) -> Self {
Self {
trivia_attachment_policy,
region_detection_policy: RegionDetectionPolicy::Both,
language_identification_detector: LanguageIdentificationDetector::Lingua,
formalization_level: FormalizationLevel::Natural,
naturalization_direction: NaturalizationDirection::Naturalize,
access_mode: AccessMode::Mutable,
profile: None,
}
}
/// Returns configuration with a mixed-language region detection policy.
#[must_use]
pub const fn with_region_detection_policy(
mut self,
region_detection_policy: RegionDetectionPolicy,
) -> Self {
self.region_detection_policy = region_detection_policy;
self
}
/// Returns configuration with a natural-language identification backend.
#[must_use]
pub const fn with_language_identification_detector(
mut self,
detector: LanguageIdentificationDetector,
) -> Self {
self.language_identification_detector = detector;
self
}
/// Returns configuration with a formalization detail level.
#[must_use]
pub const fn with_formalization_level(
mut self,
formalization_level: FormalizationLevel,
) -> Self {
self.formalization_level = formalization_level;
self
}
/// Returns configuration with a naturalization/formalization direction.
#[must_use]
pub const fn with_naturalization_direction(
mut self,
naturalization_direction: NaturalizationDirection,
) -> Self {
self.naturalization_direction = naturalization_direction;
self
}
/// Returns configuration with a read-only or mutable engine access mode.
#[must_use]
pub const fn with_access_mode(mut self, access_mode: AccessMode) -> Self {
self.access_mode = access_mode;
self
}
/// Returns configuration with a language capability profile name.
///
/// Built-in profiles such as `"JavaScript"` are materialized as queryable
/// links during parsing. User-declared profiles can be supplied directly to
/// transform-time APIs.
#[must_use]
pub const fn with_profile(mut self, profile: &'static str) -> Self {
self.profile = Some(profile);
self
}
/// Trivia attachment policy.
#[must_use]
pub const fn trivia_attachment_policy(self) -> TriviaAttachmentPolicy {
self.trivia_attachment_policy
}
/// Mixed-language region detection policy.
#[must_use]
pub const fn region_detection_policy(self) -> RegionDetectionPolicy {
self.region_detection_policy
}
/// Natural-language identification backend.
#[must_use]
pub const fn language_identification_detector(self) -> LanguageIdentificationDetector {
self.language_identification_detector
}
/// Formalization detail level.
#[must_use]
pub const fn formalization_level(self) -> FormalizationLevel {
self.formalization_level
}
/// Naturalization/formalization direction.
#[must_use]
pub const fn naturalization_direction(self) -> NaturalizationDirection {
self.naturalization_direction
}
/// Read-only or mutable engine access mode.
#[must_use]
pub const fn access_mode(self) -> AccessMode {
self.access_mode
}
/// Configured language capability profile name.
#[must_use]
pub const fn profile(self) -> Option<&'static str> {
self.profile
}
}
impl Default for ParseConfiguration {
fn default() -> Self {
Self::new(TriviaAttachmentPolicy::Both)
}
}