@@ -3,7 +3,7 @@ import { MemoizationCacheResult, memoize } from "@std/cache/memoize";
33import { ArrayResult , ArrayResultError } from "../array_result.ts" ;
44
55type 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 } > > ;
77type InnerParser < T > = ( input : Source ) => ParserResult < T > ;
88
99let source = "" ;
@@ -75,7 +75,7 @@ export class Parser<T> {
7575 map < U > ( mapper : ( value : T ) => U ) : Parser < U > {
7676 return new Parser ( ( source ) =>
7777 this . rawParser ( source )
78- . map ( ( { value, size } ) => ( { value : mapper ( value ) , size } ) )
78+ . map ( ( { value, length } ) => ( { value : mapper ( value ) , length } ) )
7979 ) ;
8080 }
8181 filter ( mapper : ( value : T ) => boolean ) : Parser < T > {
@@ -87,15 +87,15 @@ export class Parser<T> {
8787 return new Parser ( ( source ) =>
8888 this
8989 . rawParser ( source )
90- . flatMap ( ( { value, size } ) =>
90+ . flatMap ( ( { value, length } ) =>
9191 mapper ( value )
9292 . rawParser ( {
9393 source : source . source ,
94- position : source . position + size ,
94+ position : source . position + length ,
9595 } )
96- . map ( ( { value, size : addedSize } ) => ( {
96+ . map ( ( { value, length : addedLength } ) => ( {
9797 value,
98- size : size + addedSize ,
98+ length : length + addedLength ,
9999 } ) )
100100 )
101101 ) ;
@@ -133,13 +133,13 @@ export function error(error: ArrayResultError): Parser<never> {
133133}
134134export const empty = new Parser < never > ( ( ) => new ArrayResult ( ) ) ;
135135export const nothing = new Parser ( ( ) =>
136- new ArrayResult ( [ { value : null , size : 0 } ] )
136+ new ArrayResult ( [ { value : null , length : 0 } ] )
137137) ;
138138export const emptyArray = nothing . map ( ( ) => [ ] ) ;
139139export function lookAhead < T > ( parser : Parser < T > ) : Parser < T > {
140140 return new Parser ( ( source ) =>
141141 parser . rawParser ( source )
142- . map ( ( { value } ) => ( { value, size : 0 } ) )
142+ . map ( ( { value } ) => ( { value, length : 0 } ) )
143143 ) ;
144144}
145145export function lazy < T > ( parser : ( ) => Parser < T > ) : Parser < T > {
@@ -242,7 +242,7 @@ export function matchCapture(
242242 const sourceString = source . slice ( position ) ;
243243 const match = sourceString . match ( newRegex ) ;
244244 if ( match != null ) {
245- return new ArrayResult ( [ { value : match , size : match [ 0 ] . length } ] ) ;
245+ return new ArrayResult ( [ { value : match , length : match [ 0 ] . length } ] ) ;
246246 } else {
247247 return new ArrayResult (
248248 new UnexpectedError ( describeSource ( sourceString ) , description ) ,
@@ -264,7 +264,7 @@ export function matchString(
264264 ) {
265265 return new ArrayResult ( [ {
266266 value : match ,
267- size : match . length ,
267+ length : match . length ,
268268 } ] ) ;
269269 } else {
270270 return new ArrayResult (
@@ -279,13 +279,13 @@ export function matchString(
279279export const everything = new Parser ( ( { source, position } ) =>
280280 new ArrayResult ( [ {
281281 value : source . slice ( position ) ,
282- size : source . length - position ,
282+ length : source . length - position ,
283283 } ] )
284284) ;
285285export const character = match ( / ./ us, "character" ) ;
286286export const end = new Parser ( ( source ) =>
287287 source . position === source . source . length
288- ? new ArrayResult ( [ { value : null , size : 0 } ] )
288+ ? new ArrayResult ( [ { value : null , length : 0 } ] )
289289 : new ArrayResult (
290290 new UnexpectedError (
291291 describeSource ( source . source . slice ( source . position ) ) ,
@@ -297,12 +297,12 @@ export function withSource<T>(
297297 parser : Parser < T > ,
298298) : Parser < readonly [ value : T , source : string ] > {
299299 return new Parser ( ( source ) =>
300- parser . rawParser ( source ) . map ( ( { value, size } ) => ( {
300+ parser . rawParser ( source ) . map ( ( { value, length } ) => ( {
301301 value : [
302302 value ,
303- source . source . slice ( source . position , source . position + size ) ,
303+ source . source . slice ( source . position , source . position + length ) ,
304304 ] as const ,
305- size ,
305+ length ,
306306 } ) )
307307 ) ;
308308}
0 commit comments