aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthew Hall <hallmatthew314@gmail.com>2023-03-30 22:13:48 +1300
committerMatthew Hall <hallmatthew314@gmail.com>2023-03-30 22:13:48 +1300
commitf29f6ae49def24d314b0814e5d22ecadcc2b8e0b (patch)
tree5c8a769fcf133d6fea23a648d83290ed481b6c6c /src
parent2e9ae8cc26dd8c004edb9231fa219059e037eebf (diff)
Redefine in terms of and_then
Diffstat (limited to 'src')
-rw-r--r--src/parcom/parser.cr9
1 files changed, 4 insertions, 5 deletions
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.