1+ from itertools import chain
2+ from typing import TypedDict
3+
14from ..get_list import get_raw_list , make_dict_readable
25
36MODIFIER_LIST_NAMES = [
47 "simple_modifier" ,
58 "interior_modifier" ,
69 "head_tail_modifier" ,
7- "simple_scope_modifier" ,
10+ "every_scope_modifier" ,
11+ "ancestor_scope_modifier" ,
812 "first_modifier" ,
913 "last_modifier" ,
1014 "previous_next_modifier" ,
@@ -132,10 +136,6 @@ def get_modifiers():
132136 "spokenForm" : f"<ordinal> { complex_modifiers ['next' ]} <scope>" ,
133137 "description" : "<ordinal> instance of <scope> after target" ,
134138 },
135- {
136- "spokenForm" : f"{ complex_modifiers ['previous' ]} <number> <scope>s" ,
137- "description" : "previous <number> instances of <scope>" ,
138- },
139139 {
140140 "spokenForm" : f"<scope> { complex_modifiers ['backward' ]} " ,
141141 "description" : "single instance of <scope> including target, going backwards" ,
@@ -144,18 +144,25 @@ def get_modifiers():
144144 "spokenForm" : f"<scope> { complex_modifiers ['forward' ]} " ,
145145 "description" : "single instance of <scope> including target, going forwards" ,
146146 },
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+ ),
159166 ],
160167 },
161168 {
@@ -170,14 +177,40 @@ def get_modifiers():
170177 "spokenForm" : f"<ordinal> { complex_modifiers ['last' ]} <scope>" ,
171178 "description" : "<ordinal>-to-last instance of <scope> in iteration scope" ,
172179 },
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+ [
173205 {
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 " ,
176208 },
177209 {
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 " ,
180212 },
181- ],
182- },
183- ]
213+ ]
214+ for entry in entries
215+ )
216+ )
0 commit comments