@@ -20,7 +20,6 @@ import {
2020 numberToSpokenForm ,
2121 ordinalToSpokenForm ,
2222} from "./defaultSpokenForms/numbers" ;
23- import { surroundingPairNameToSpokenForm } from "./defaultSpokenForms/modifiers" ;
2423import { characterToSpokenForm } from "./defaultSpokenForms/characters" ;
2524import {
2625 GeneratorSpokenFormMap ,
@@ -35,7 +34,7 @@ export class PrimitiveTargetSpokenFormGenerator {
3534 handlePrimitiveTarget (
3635 target : PartialPrimitiveTargetDescriptor ,
3736 ) : SpokenFormComponent {
38- const components : SpokenFormComponents = [ ] ;
37+ const components : SpokenFormComponent [ ] = [ ] ;
3938 if ( target . modifiers != null ) {
4039 components . push ( target . modifiers . map ( this . handleModifier ) ) ;
4140 }
@@ -147,7 +146,7 @@ export class PrimitiveTargetSpokenFormGenerator {
147146
148147 private handleRelativeScopeInclusive (
149148 modifier : RelativeScopeModifier ,
150- ) : SpokenFormComponents {
149+ ) : SpokenFormComponent {
151150 const scope = this . handleScopeType ( modifier . scopeType ) ;
152151
153152 if ( modifier . length === 1 ) {
@@ -175,7 +174,7 @@ export class PrimitiveTargetSpokenFormGenerator {
175174
176175 private handleRelativeScopeExclusive (
177176 modifier : RelativeScopeModifier ,
178- ) : SpokenFormComponents {
177+ ) : SpokenFormComponent {
179178 const scope = this . handleScopeType ( modifier . scopeType ) ;
180179 const direction =
181180 modifier . direction === "forward"
@@ -207,7 +206,7 @@ export class PrimitiveTargetSpokenFormGenerator {
207206 ) ;
208207 }
209208
210- handleScopeType ( scopeType : ScopeType ) : SpokenForms {
209+ handleScopeType ( scopeType : ScopeType ) : SpokenFormComponent {
211210 switch ( scopeType . type ) {
212211 case "oneOf" :
213212 case "customRegex" :
@@ -220,10 +219,7 @@ export class PrimitiveTargetSpokenFormGenerator {
220219 `Scope type '${ scopeType . type } ' with delimiter 'collectionBoundary'` ,
221220 ) ;
222221 }
223- const pair = surroundingPairNameToSpokenForm (
224- this . spokenFormMap ,
225- scopeType . delimiter ,
226- ) ;
222+ const pair = this . spokenFormMap . pairedDelimiter [ scopeType . delimiter ] ;
227223 if ( scopeType . forceDirection != null ) {
228224 const direction =
229225 scopeType . forceDirection === "left"
@@ -239,7 +235,7 @@ export class PrimitiveTargetSpokenFormGenerator {
239235 }
240236 }
241237
242- private handleMark ( mark : PartialMark ) : SpokenFormComponents {
238+ private handleMark ( mark : PartialMark ) : SpokenFormComponent {
243239 switch ( mark . type ) {
244240 case "decoratedSymbol" : {
245241 const [ color , shape ] = mark . symbolColor . split ( "-" ) ;
@@ -314,7 +310,28 @@ export class PrimitiveTargetSpokenFormGenerator {
314310 }
315311}
316312
313+ function pluralize ( name : SpokenFormComponent ) : SpokenFormComponent {
314+ if ( typeof name === "string" ) {
315+ return pluralizeString ( name ) ;
316+ }
317+
318+ if ( Array . isArray ( name ) ) {
319+ if ( name . length === 0 ) {
320+ return name ;
321+ }
322+
323+ const last = name [ name . length - 1 ] ;
324+
325+ return [ ...name . slice ( 0 , - 1 ) , pluralize ( last ) ] ;
326+ }
327+
328+ return {
329+ ...name ,
330+ spokenForms : name . spokenForms . map ( pluralizeString ) ,
331+ } ;
332+ }
333+
317334// FIXME: Properly pluralize
318- function pluralize ( name : string ) : string {
335+ function pluralizeString ( name : string ) : string {
319336 return `${ name } s` ;
320337}
0 commit comments