since import { empty , getMonoid } from 'fp-ts/lib/Array' ; import { Either , left , right } from 'fp-ts/lib/Either' ; import { getFirstSemigroup , getLastSemigroup , getStructSemigroup , Semigroup } from 'fp-ts/lib/Semigroup' ; import { Stream } from './Stream' ; category since export interface ParseError < I > { input : Stream < I > ; expected : Array < string > ; fatal : boolean ; } category since export interface ParseSuccess < I , A > { value : A ; next : Stream < I > ; start : Stream < I > ; } category since export type ParseResult < I , A > = Either < ParseError < I > , ParseSuccess < I , A > > ; category since export const success = ( value , next , start ) => right ( { value , next , start } ) ; category since export const error = ( input , expected = empty , fatal = false ) => left ( { input , expected , fatal } ) ; category since export const withExpected = ( err , expected ) => ( { ... err , expected } ) ; category since export const escalate = err => ( { ... err , fatal : true } ) ; category since export const extend = < I > ( err1 , err2 ) : ParseError < I > => getSemigroup < I > ( ) . concat ( err1 , err2 ) ; const getSemigroup = < I > ( ) : Semigroup < ParseError < I > > => ( { concat : ( x , y ) => { if ( x . input . cursor < y . input . cursor ) return getLastSemigroup < ParseError < I > > ( ) . concat ( x , y ) ; if ( x . input . cursor > y . input . cursor ) return getFirstSemigroup < ParseError < I > > ( ) . concat ( x , y ) ; return getStructSemigroup < ParseError < I > > ( { input : getFirstSemigroup < Stream < I > > ( ) , fatal : getFirstSemigroup < boolean > ( ) , expected : getMonoid < string > ( ) } ) . concat ( x , y ) ; } } ) ;