1
+ from itertools import chain
2
+ from typing import TypedDict
3
+
1
4
from ..get_list import get_raw_list , make_dict_readable
2
5
3
6
MODIFIER_LIST_NAMES = [
4
7
"simple_modifier" ,
5
8
"interior_modifier" ,
6
9
"head_tail_modifier" ,
7
- "simple_scope_modifier" ,
10
+ "every_scope_modifier" ,
11
+ "ancestor_scope_modifier" ,
8
12
"first_modifier" ,
9
13
"last_modifier" ,
10
14
"previous_next_modifier" ,
@@ -132,10 +136,6 @@ def get_modifiers():
132
136
"spokenForm" : f"<ordinal> { complex_modifiers ['next' ]} <scope>" ,
133
137
"description" : "<ordinal> instance of <scope> after target" ,
134
138
},
135
- {
136
- "spokenForm" : f"{ complex_modifiers ['previous' ]} <number> <scope>s" ,
137
- "description" : "previous <number> instances of <scope>" ,
138
- },
139
139
{
140
140
"spokenForm" : f"<scope> { complex_modifiers ['backward' ]} " ,
141
141
"description" : "single instance of <scope> including target, going backwards" ,
@@ -144,18 +144,25 @@ def get_modifiers():
144
144
"spokenForm" : f"<scope> { complex_modifiers ['forward' ]} " ,
145
145
"description" : "single instance of <scope> including target, going forwards" ,
146
146
},
147
- {
148
- "spokenForm" : f"<number> <scope>s { complex_modifiers ['backward' ]} " ,
149
- "description" : "<number> instances of <scope> including target, going backwards" ,
150
- },
151
- {
152
- "spokenForm" : "<number> <scope>s" ,
153
- "description" : "<number> instances of <scope> including target, going forwards" ,
154
- },
155
- {
156
- "spokenForm" : f"{ complex_modifiers ['next' ]} <number> <scope>s" ,
157
- "description" : "next <number> instances of <scope>" ,
158
- },
147
+ * generateOptionalEvery (
148
+ complex_modifiers ["every" ],
149
+ {
150
+ "spokenForm" : f"<number> <scope>s { complex_modifiers ['backward' ]} " ,
151
+ "description" : "<number> instances of <scope> including target, going backwards" ,
152
+ },
153
+ {
154
+ "spokenForm" : "<number> <scope>s" ,
155
+ "description" : "<number> instances of <scope> including target, going forwards" ,
156
+ },
157
+ {
158
+ "spokenForm" : f"{ complex_modifiers ['previous' ]} <number> <scope>s" ,
159
+ "description" : "previous <number> instances of <scope>" ,
160
+ },
161
+ {
162
+ "spokenForm" : f"{ complex_modifiers ['next' ]} <number> <scope>s" ,
163
+ "description" : "next <number> instances of <scope>" ,
164
+ },
165
+ ),
159
166
],
160
167
},
161
168
{
@@ -170,14 +177,40 @@ def get_modifiers():
170
177
"spokenForm" : f"<ordinal> { complex_modifiers ['last' ]} <scope>" ,
171
178
"description" : "<ordinal>-to-last instance of <scope> in iteration scope" ,
172
179
},
180
+ * generateOptionalEvery (
181
+ complex_modifiers ["every" ],
182
+ {
183
+ "spokenForm" : f"{ complex_modifiers ['first' ]} <number> <scope>s" ,
184
+ "description" : "first <number> instances of <scope> in iteration scope" ,
185
+ },
186
+ {
187
+ "spokenForm" : f"{ complex_modifiers ['last' ]} <number> <scope>s" ,
188
+ "description" : "last <number> instances of <scope> in iteration scope" ,
189
+ },
190
+ ),
191
+ ],
192
+ },
193
+ ]
194
+
195
+
196
+ class Entry (TypedDict ):
197
+ spokenForm : str
198
+ description : str
199
+
200
+
201
+ def generateOptionalEvery (every : str , * entries : Entry ) -> list [Entry ]:
202
+ return list (
203
+ chain .from_iterable (
204
+ [
173
205
{
174
- "spokenForm" : f" { complex_modifiers [ 'first' ] } <number> <scope>s" ,
175
- "description" : "First <number> instances of <scope> in iteration scope " ,
206
+ "spokenForm" : entry [ "spokenForm" ] ,
207
+ "description" : f" { entry [ 'description' ] } , as contiguous range " ,
176
208
},
177
209
{
178
- "spokenForm" : f"{ complex_modifiers [ 'last ' ]} <number> <scope>s " ,
179
- "description" : "Last <number> instances of <scope> in iteration scope " ,
210
+ "spokenForm" : f"{ every } { entry [ 'spokenForm ' ]} " ,
211
+ "description" : f" { entry [ 'description' ] } , as individual targets " ,
180
212
},
181
- ],
182
- },
183
- ]
213
+ ]
214
+ for entry in entries
215
+ )
216
+ )
0 commit comments