From afdeb29d2325767e0d826c8ff1eb16ab1dc13301 Mon Sep 17 00:00:00 2001 From: Matthew Hall Date: Sun, 2 Apr 2023 23:49:28 +1200 Subject: Re-factoring parsers implemented with parser_chain --- src/parcom/parser.cr | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/parcom/parser.cr b/src/parcom/parser.cr index 398c95d..c064d98 100644 --- a/src/parcom/parser.cr +++ b/src/parcom/parser.cr @@ -255,17 +255,23 @@ module Parcom parser_chain T, {U, V}, "#{@name} + #{other.name}", {x, self}, {y, other}, - make: Parser(T, {U, V}).pure({x, y}) + pure: {x, y} end # Same as `#+`, but discards the second parser's result. def <<(other : Parser(T, _)) : Parser(T, U) - (self + other).map(&.first).named("#{@name} << #{other.name}") + parser_chain T, U, "#{@name} << #{other.name}", + {x, self}, + {_, other}, + pure: x end # Same as `#+`, but discards the first parser's result. def >>(other : Parser(T, V)) : Parser(T, V) forall V - (self + other).map(&.last).named("#{@name} >> #{other.name}") + parser_chain T, V, "#{@name} >> #{other.name}", + {_, self}, + {y, other}, + pure: y end # Creates a new parser from `self` and a function based on @@ -440,7 +446,7 @@ module Parcom parser_chain T, Array(U), "<#{@name}> sep by <#{sep.name}>", {head, self}, {tail, (sep >> self).many}, - make: Parser(T, Array(U)).pure(tail.unshift(head)) + pure: tail.unshift(head) end end end -- cgit v1.2.1