@@ -3,7 +3,7 @@ import { MemoizationCacheResult, memoize } from "@std/cache/memoize";
3
3
import { ArrayResult , ArrayResultError } from "../array_result.ts" ;
4
4
5
5
type Source = Readonly < { source : string ; position : number } > ;
6
- type ParserResult < T > = ArrayResult < Readonly < { value : T ; size : number } > > ;
6
+ type ParserResult < T > = ArrayResult < Readonly < { value : T ; length : number } > > ;
7
7
type InnerParser < T > = ( input : Source ) => ParserResult < T > ;
8
8
9
9
let source = "" ;
@@ -75,7 +75,7 @@ export class Parser<T> {
75
75
map < U > ( mapper : ( value : T ) => U ) : Parser < U > {
76
76
return new Parser ( ( source ) =>
77
77
this . rawParser ( source )
78
- . map ( ( { value, size } ) => ( { value : mapper ( value ) , size } ) )
78
+ . map ( ( { value, length } ) => ( { value : mapper ( value ) , length } ) )
79
79
) ;
80
80
}
81
81
filter ( mapper : ( value : T ) => boolean ) : Parser < T > {
@@ -87,15 +87,15 @@ export class Parser<T> {
87
87
return new Parser ( ( source ) =>
88
88
this
89
89
. rawParser ( source )
90
- . flatMap ( ( { value, size } ) =>
90
+ . flatMap ( ( { value, length } ) =>
91
91
mapper ( value )
92
92
. rawParser ( {
93
93
source : source . source ,
94
- position : source . position + size ,
94
+ position : source . position + length ,
95
95
} )
96
- . map ( ( { value, size : addedSize } ) => ( {
96
+ . map ( ( { value, length : addedLength } ) => ( {
97
97
value,
98
- size : size + addedSize ,
98
+ length : length + addedLength ,
99
99
} ) )
100
100
)
101
101
) ;
@@ -133,13 +133,13 @@ export function error(error: ArrayResultError): Parser<never> {
133
133
}
134
134
export const empty = new Parser < never > ( ( ) => new ArrayResult ( ) ) ;
135
135
export const nothing = new Parser ( ( ) =>
136
- new ArrayResult ( [ { value : null , size : 0 } ] )
136
+ new ArrayResult ( [ { value : null , length : 0 } ] )
137
137
) ;
138
138
export const emptyArray = nothing . map ( ( ) => [ ] ) ;
139
139
export function lookAhead < T > ( parser : Parser < T > ) : Parser < T > {
140
140
return new Parser ( ( source ) =>
141
141
parser . rawParser ( source )
142
- . map ( ( { value } ) => ( { value, size : 0 } ) )
142
+ . map ( ( { value } ) => ( { value, length : 0 } ) )
143
143
) ;
144
144
}
145
145
export function lazy < T > ( parser : ( ) => Parser < T > ) : Parser < T > {
@@ -242,7 +242,7 @@ export function matchCapture(
242
242
const sourceString = source . slice ( position ) ;
243
243
const match = sourceString . match ( newRegex ) ;
244
244
if ( match != null ) {
245
- return new ArrayResult ( [ { value : match , size : match [ 0 ] . length } ] ) ;
245
+ return new ArrayResult ( [ { value : match , length : match [ 0 ] . length } ] ) ;
246
246
} else {
247
247
return new ArrayResult (
248
248
new UnexpectedError ( describeSource ( sourceString ) , description ) ,
@@ -264,7 +264,7 @@ export function matchString(
264
264
) {
265
265
return new ArrayResult ( [ {
266
266
value : match ,
267
- size : match . length ,
267
+ length : match . length ,
268
268
} ] ) ;
269
269
} else {
270
270
return new ArrayResult (
@@ -279,13 +279,13 @@ export function matchString(
279
279
export const everything = new Parser ( ( { source, position } ) =>
280
280
new ArrayResult ( [ {
281
281
value : source . slice ( position ) ,
282
- size : source . length - position ,
282
+ length : source . length - position ,
283
283
} ] )
284
284
) ;
285
285
export const character = match ( / ./ us, "character" ) ;
286
286
export const end = new Parser ( ( source ) =>
287
287
source . position === source . source . length
288
- ? new ArrayResult ( [ { value : null , size : 0 } ] )
288
+ ? new ArrayResult ( [ { value : null , length : 0 } ] )
289
289
: new ArrayResult (
290
290
new UnexpectedError (
291
291
describeSource ( source . source . slice ( source . position ) ) ,
@@ -297,12 +297,12 @@ export function withSource<T>(
297
297
parser : Parser < T > ,
298
298
) : Parser < readonly [ value : T , source : string ] > {
299
299
return new Parser ( ( source ) =>
300
- parser . rawParser ( source ) . map ( ( { value, size } ) => ( {
300
+ parser . rawParser ( source ) . map ( ( { value, length } ) => ( {
301
301
value : [
302
302
value ,
303
- source . source . slice ( source . position , source . position + size ) ,
303
+ source . source . slice ( source . position , source . position + length ) ,
304
304
] as const ,
305
- size ,
305
+ length ,
306
306
} ) )
307
307
) ;
308
308
}
0 commit comments