aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/parcom/parser.cr14
1 files changed, 10 insertions, 4 deletions
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