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
//! Provides types for working with modular adjuncts.
use crate::{
category::{
ArbitraryMoodOrCaseScope, Aspect, ModularAdjunctMode, ModularAdjunctScope, NonAspectualVn,
Stress, Valence, Vn,
},
gloss::{Gloss, GlossFlags, GlossHelpers},
prelude::{IntoTokens, IntoTokensFlags, TokenList},
romanize::{
flags::FromTokenFlags,
segment::{VnCm, VnCn},
stream::{ParseError, TokenStream},
traits::FromTokens,
},
};
/// A modular adjunct.
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub enum ModularAdjunct {
/// A variant containing a single aspect.
Aspect {
/// The mode, i.e. whether this word scopes over the parent or child formative.
mode: ModularAdjunctMode,
/// The single aspect represented by this adjunct.
aspect: Aspect,
},
/// A variant containing 2-3 Vn segments and no special scope.
NonScoped {
/// The mode, i.e. whether this word scopes over the parent or child formative.
mode: ModularAdjunctMode,
/// The first Vn segment marked by this formative.
vn1: Vn,
/// The Cn segment marked by this formative.
cn: ArbitraryMoodOrCaseScope,
/// The optional second Vn segment marked by this formative.
vn2: Option<Vn>,
/// The third Vn segment marked by this formative. This may actually be the second one if
/// `vn2` if [`None`]. Cannot be an [`Aspect`].
vn3: NonAspectualVn,
},
/// A variant containing 1-2 Vn segments and a specialized scope.
Scoped {
/// The mode, i.e. whether this word scopes over the parent or child formative.
mode: ModularAdjunctMode,
/// The first Vn segment marked by this formative.
vn1: Vn,
/// The Cn segment marked by this formative.
cn: ArbitraryMoodOrCaseScope,
/// The optional second Vn segment marked by this formative.
vn2: Option<Vn>,
/// The specialized scope of this formative.
scope: ModularAdjunctScope,
},
}
impl Default for ModularAdjunct {
fn default() -> Self {
Self::Aspect {
mode: ModularAdjunctMode::Full,
aspect: Aspect::RTR,
}
}
}
impl Gloss for ModularAdjunct {
fn gloss(&self, flags: GlossFlags) -> String {
match self {
Self::Aspect { mode, aspect } => {
let mut output = mode.gloss_non_default(flags);
output.add_dashed(&aspect.gloss(flags));
output
}
Self::NonScoped {
mode,
vn1,
cn,
vn2,
vn3,
} => {
let mut output = mode.gloss_non_default(flags);
output.add_dashed(&vn1.gloss_non_default(flags));
output.add_dashed(&cn.gloss_non_default(flags));
if let Some(vn2) = vn2 {
output.add_dashed(&vn2.gloss_non_default(flags));
}
output.add_dashed(&vn3.gloss_non_default(flags));
if output.is_empty() {
Valence::MNO.gloss(flags)
} else {
output
}
}
Self::Scoped {
mode,
vn1,
cn,
vn2,
scope,
} => {
let mut output = mode.gloss_non_default(flags);
output.add_dashed(&vn1.gloss_non_default(flags));
output.add_dashed(&cn.gloss_non_default(flags));
if let Some(vn2) = vn2 {
output.add_dashed(&vn2.gloss_non_default(flags));
}
output.add_dashed(&scope.gloss_non_default(flags));
if output.is_empty() {
Valence::MNO.gloss(flags)
} else {
output
}
}
}
}
}
impl FromTokens for ModularAdjunct {
fn parse_volatile(stream: &mut TokenStream, flags: FromTokenFlags) -> Result<Self, ParseError> {
let mode: ModularAdjunctMode = stream.parse(flags)?;
let Some(VnCn { vn: vn1, cn }): Option<VnCn> = stream.parse(flags).ok() else {
return Ok(ModularAdjunct::Aspect {
mode,
aspect: stream.parse(flags)?,
});
};
let vn2: Option<VnCm> = stream.parse(flags).ok();
match stream.stress() {
Some(Stress::Ultimate) => Ok(ModularAdjunct::Scoped {
mode,
vn1,
cn,
vn2: vn2.map(|x| x.vn),
scope: stream.parse(flags)?,
}),
Some(Stress::Antepenultimate) => return Err(ParseError::AntepenultimateStress),
_ => Ok(ModularAdjunct::NonScoped {
mode,
vn1,
cn,
vn2: vn2.map(|x| x.vn),
vn3: stream.parse(flags)?,
}),
}
}
}
impl IntoTokens for ModularAdjunct {
fn append_tokens_to(&self, list: &mut TokenList, flags: IntoTokensFlags) {
match *self {
Self::Aspect { mode, aspect } => {
list.append(&mode, flags);
list.push(aspect);
list.set_stress(Stress::Penultimate);
}
Self::NonScoped {
mode,
vn1,
cn,
vn2,
vn3,
} => {
list.append(&mode, flags);
list.append(&VnCn { vn: vn1, cn }, flags);
if let Some(vn) = vn2 {
list.append(&VnCm { vn }, flags);
}
list.push(vn3);
list.set_stress(Stress::Penultimate);
}
Self::Scoped {
mode,
vn1,
cn,
vn2,
scope,
} => {
list.append(&mode, flags);
list.append(&VnCn { vn: vn1, cn }, flags);
if let Some(vn) = vn2 {
list.append(&VnCm { vn }, flags);
}
list.push(scope);
list.set_stress(Stress::Ultimate);
}
}
}
}