@@ -20,14 +20,7 @@ import {
2020 UnexpectedError ,
2121 withSource ,
2222} from "../src/parser/parser_lib.ts" ;
23- import {
24- Definition ,
25- Determiner ,
26- Dictionary ,
27- Noun ,
28- NounForms ,
29- VerbForms ,
30- } from "./type.ts" ;
23+ import { Definition , Dictionary , VerbForms } from "./type.ts" ;
3124
3225const RESERVED_SYMBOLS = "#()*+/:;<=>@[\\]^`{|}~" ;
3326const WORDS = new RegExp ( `[^${ escapeRegex ( RESERVED_SYMBOLS ) } ]` ) ;
@@ -117,66 +110,62 @@ const nounOnly = choiceOnlyOne(
117110 . with ( optionalAll ( keyword ( "gerund" ) ) ) ,
118111 ) ,
119112 )
120- . map < NounForms & { gerund : boolean } > (
121- ( [ noun , gerund ] ) => {
122- const sentence = nlp ( noun ) ;
123- sentence . tag ( "Noun" ) ;
124- const singular = sentence
125- . nouns ( )
126- . toSingular ( )
127- . text ( ) ;
128- const plural = sentence
129- . nouns ( )
130- . toPlural ( )
131- . text ( ) ;
132- if ( singular === "" || plural === "" ) {
133- throw new ArrayResultError (
134- `no singular or plural form found for "${ noun } ". consider ` +
135- "providing both singular and plural forms instead" ,
136- ) ;
137- }
138- if ( noun !== singular ) {
139- throw new ArrayResultError (
140- `conjugation error: "${ noun } " is not "${ singular } ". ` +
141- "consider providing both singular and plural forms instead" ,
142- ) ;
143- }
144- return {
145- singular : escapeHtml ( singular ) ,
146- plural : escapeHtml ( plural ) ,
147- gerund : gerund != null ,
148- } ;
149- } ,
150- ) ,
113+ . map ( ( [ noun , gerund ] ) => {
114+ const sentence = nlp ( noun ) ;
115+ sentence . tag ( "Noun" ) ;
116+ const singular = sentence
117+ . nouns ( )
118+ . toSingular ( )
119+ . text ( ) ;
120+ const plural = sentence
121+ . nouns ( )
122+ . toPlural ( )
123+ . text ( ) ;
124+ if ( singular === "" || plural === "" ) {
125+ throw new ArrayResultError (
126+ `no singular or plural form found for "${ noun } ". consider ` +
127+ "providing both singular and plural forms instead" ,
128+ ) ;
129+ }
130+ if ( noun !== singular ) {
131+ throw new ArrayResultError (
132+ `conjugation error: "${ noun } " is not "${ singular } ". ` +
133+ "consider providing both singular and plural forms instead" ,
134+ ) ;
135+ }
136+ return {
137+ singular : escapeHtml ( singular ) ,
138+ plural : escapeHtml ( plural ) ,
139+ gerund : gerund != null ,
140+ } ;
141+ } ) ,
151142 sequence (
152143 word ,
153144 tag (
154145 keyword ( "n" )
155146 . with ( sequence ( optionalAll ( keyword ( "gerund" ) ) , number ) ) ,
156147 ) ,
157148 )
158- . map < NounForms & { gerund : boolean } > (
159- ( [ noun , [ gerund , number ] ] ) => {
160- let singular : null | string ;
161- let plural : null | string ;
162- switch ( number ) {
163- case "singular" :
164- case "plural" :
165- switch ( number ) {
166- case "singular" :
167- singular = noun ;
168- plural = null ;
169- break ;
170- case "plural" :
171- singular = null ;
172- plural = noun ;
173- break ;
174- }
175- break ;
176- }
177- return { singular, plural, gerund : gerund != null } ;
178- } ,
179- ) ,
149+ . map ( ( [ noun , [ gerund , number ] ] ) => {
150+ let singular : null | string ;
151+ let plural : null | string ;
152+ switch ( number ) {
153+ case "singular" :
154+ case "plural" :
155+ switch ( number ) {
156+ case "singular" :
157+ singular = noun ;
158+ plural = null ;
159+ break ;
160+ case "plural" :
161+ singular = null ;
162+ plural = noun ;
163+ break ;
164+ }
165+ break ;
166+ }
167+ return { singular, plural, gerund : gerund != null } ;
168+ } ) ,
180169 sequence (
181170 word ,
182171 optionalAll ( slash . with ( word ) ) ,
@@ -185,13 +174,11 @@ const nounOnly = choiceOnlyOne(
185174 . with ( optionalAll ( keyword ( "gerund" ) ) ) ,
186175 ) ,
187176 )
188- . map < NounForms & { gerund : boolean } > (
189- ( [ singular , plural , gerund ] ) => ( {
190- singular,
191- plural,
192- gerund : gerund != null ,
193- } ) ,
194- ) ,
177+ . map ( ( [ singular , plural , gerund ] ) => ( {
178+ singular,
179+ plural,
180+ gerund : gerund != null ,
181+ } ) ) ,
195182) ;
196183const determinerType = choiceOnlyOne (
197184 keyword ( "article" ) ,
@@ -208,17 +195,19 @@ const determiner = sequence(
208195 optionalAll ( slash . with ( word ) ) ,
209196 tag ( keyword ( "d" ) . with ( sequence ( determinerType , optionalNumber ) ) ) ,
210197)
211- . map < Determiner > ( ( [ determiner , plural , [ kind , quantity ] ] ) => ( {
212- determiner,
213- plural,
214- kind,
215- quantity : quantity ?? "both" ,
216- } ) ) ;
198+ . map ( ( [ determiner , plural , [ kind , quantity ] ] ) =>
199+ ( {
200+ determiner,
201+ plural,
202+ kind,
203+ quantity : quantity ?? "both" ,
204+ } ) as const
205+ ) ;
217206const adjectiveKind = choiceOnlyOne (
218207 keyword ( "opinion" ) ,
219208 keyword ( "size" ) ,
220209 sequence ( keyword ( "physical" ) , keyword ( "quality" ) )
221- . map < "physical quality" > ( ( ) => "physical quality" ) ,
210+ . map ( ( ) => "physical quality" as const ) ,
222211 keyword ( "age" ) ,
223212 keyword ( "color" ) ,
224213 keyword ( "origin" ) ,
@@ -249,17 +238,17 @@ const noun = sequence(
249238 . skip ( tag ( sequence ( keyword ( "n" ) , keyword ( "proper" ) ) ) ) ,
250239 ) ,
251240)
252- . map < Noun > ( ( [ determiner , adjective , noun , post ] ) => {
253- return {
241+ . map ( ( [ determiner , adjective , noun , post ] ) =>
242+ ( {
254243 ...noun ,
255244 determiner,
256245 adjective,
257246 postAdjective : mapNullable (
258247 post ,
259248 ( [ adjective , name ] ) => ( { adjective, name } ) ,
260249 ) ,
261- } ;
262- } ) ;
250+ } ) as const
251+ ) ;
263252function verbOnly ( tagInside : Parser < unknown > ) : Parser < VerbForms > {
264253 return choiceOnlyOne (
265254 sequence (
@@ -437,15 +426,13 @@ const definition = choiceOnlyOne<Definition>(
437426 ) ,
438427 )
439428 . skip ( semicolon )
440- . map ( (
441- [
442- singularSubject ,
443- singularObject ,
444- pluralSubject ,
445- pluralObject ,
446- perspective ,
447- ] ,
448- ) => ( {
429+ . map ( ( [
430+ singularSubject ,
431+ singularObject ,
432+ pluralSubject ,
433+ pluralObject ,
434+ perspective ,
435+ ] ) => ( {
449436 type : "personal pronoun" ,
450437 singular : { subject : singularSubject , object : singularObject } ,
451438 plural : { subject : pluralSubject , object : pluralObject } ,
0 commit comments