parser-ts icon indicating copy to clipboard operation
parser-ts copied to clipboard

P.either should fail with fatal error, if second parser failed with fatal, or should it?

Open regevbr opened this issue 4 years ago • 2 comments

Take a look at the following test (which currently fails):

const fatalParser: P.Parser<Char, Char> = i => error(i, ['expected'], true)
const parser5 = P.either(C.char('a'), () => fatalParser)
assert.deepStrictEqual(S.run('c')(parser5), error(stream(['c']), ['"a"', 'expected'], true))

I believe that the semigroup of ParserResult should use getLastSemigroup on the fatal property, and not getFirstSemigroup. I guess it is kind of a philosophical question as one can argue that I'm mistaken....

@gcanti thoughts?

If you think this should indeed be fixed, I have a PR ready to go

regevbr avatar Jun 30 '21 16:06 regevbr

Hmm. We could also use the Semigroup for boolean so that if a fatal error is encountered it always escalated?

IMax153 avatar Jun 30 '21 17:06 IMax153

@IMax153 yes that sounds even better!

regevbr avatar Jun 30 '21 17:06 regevbr