diff options
| author | Matthew Hall <hallmatthew314@gmail.com> | 2023-04-02 23:49:28 +1200 |
|---|---|---|
| committer | Matthew Hall <hallmatthew314@gmail.com> | 2023-04-02 23:49:28 +1200 |
| commit | afdeb29d2325767e0d826c8ff1eb16ab1dc13301 (patch) | |
| tree | 9c7293530d440f3758811d55b1cb7dc8c22938dc | |
| parent | 8bd7f4ec8f4885c0d8a915d4693e25935503d5bb (diff) | |
Re-factoring parsers implemented with parser_chain
| -rw-r--r-- | src/parcom/parser.cr | 14 |
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 |
