Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion src/combinator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,9 +562,34 @@ pub fn value<I, O1: Clone, E: ParseError<I>, F>(
parser: F,
) -> impl Parser<I, Output = O1, Error = E>
where
I: Input,
F: Parser<I, Error = E>,
{
parser.map(move |_| val.clone())
Value { parser, val }
}

/// Parser implementation for [value]
pub struct Value<F, O1> {
parser: F,
val: O1,
}

impl<I, F, O1> Parser<I> for Value<F, O1>
where
I: Input,
F: Parser<I>,
O1: Clone,
{
type Output = O1;
type Error = <F as Parser<I>>::Error;

fn process<OM: OutputMode>(&mut self, input: I) -> PResult<OM, I, Self::Output, Self::Error> {
let (input, ()) = self
.parser
.process::<OutputM<Check, OM::Error, OM::Incomplete>>(input)?;

Ok((input, OM::Output::bind(|| self.val.clone())))
}
}

/// Succeeds if the child parser returns an error.
Expand Down