From f29f6ae49def24d314b0814e5d22ecadcc2b8e0b Mon Sep 17 00:00:00 2001 From: Matthew Hall Date: Thu, 30 Mar 2023 22:13:48 +1300 Subject: Redefine in terms of and_then --- src/parcom/parser.cr | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/parcom/parser.cr b/src/parcom/parser.cr index d8f44c8..d13219d 100644 --- a/src/parcom/parser.cr +++ b/src/parcom/parser.cr @@ -255,11 +255,10 @@ module Parcom # try to parse with both parsers and return both results. If either # sub-parser fails, the whole parser fails. def +(other : Parser(T, V)) : Parser(T, {U, V}) forall V - Parser(T, {U, V}).new("#{@name} + #{other.name}") do |tokens| - r1 = self.parse(tokens) - r2 = other.parse(r1.tokens) - Result.new(r2.tokens, {r1.value, r2.value}) - end + parser_chain "#{@name} + #{other.name}", T, {U, V}, + {x, self}, + {y, other}, + finally: Parser(T, {U, V}).pure({x, y}) end # Same as `#+`, but discards the second parser's result. -- cgit v1.2.1