mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 05:49:08 +00:00
Un-macro succeed
This implementation requires that the type of the value impls `Clone`, which means the function version of `succeed` cannot be used to succeed with values of non-`Clone` types. If this becomes an issue, we could either bring back the macro version, or create a new `succeed_with` function that takes a `Fn() -> T` argument. `succeed_with` could then be used to succeed with values that aren't `Clone` by creating the value on-demand each time the parser is run.
This commit is contained in:
parent
5c0b2a0938
commit
f6c977fb96
3 changed files with 11 additions and 13 deletions
|
@ -1521,7 +1521,7 @@ macro_rules! collection_trailing_sep_e {
|
|||
/// # use bumpalo::Bump;
|
||||
/// # let arena = Bump::new();
|
||||
/// # fn foo<'a>(arena: &'a Bump) {
|
||||
/// let parser = succeed!("different");
|
||||
/// let parser = succeed("different");
|
||||
///
|
||||
/// let (progress, output, state) = Parser::<&'a str,()>::parse(&parser, &arena, State::new("hello, world".as_bytes()), 0).unwrap();
|
||||
/// assert_eq!(progress, Progress::NoProgress);
|
||||
|
@ -1530,13 +1530,10 @@ macro_rules! collection_trailing_sep_e {
|
|||
/// # }
|
||||
/// # foo(&arena);
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! succeed {
|
||||
($value:expr) => {
|
||||
move |_arena: &'a bumpalo::Bump, state: $crate::state::State<'a>, _min_indent: u32| {
|
||||
Ok((NoProgress, $value, state))
|
||||
}
|
||||
};
|
||||
pub fn succeed<'a, T: Clone, E: 'a>(value: T) -> impl Parser<'a, T, E> {
|
||||
move |_arena: &'a bumpalo::Bump, state: crate::state::State<'a>, _min_indent: u32| {
|
||||
Ok((NoProgress, value.clone(), state))
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a parser that always fails.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue