mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-18 02:50:17 +00:00
added example for one_of_with_error
This commit is contained in:
parent
b146030fff
commit
47b537c278
1 changed files with 30 additions and 0 deletions
|
@ -1799,6 +1799,36 @@ macro_rules! one_of {
|
|||
};
|
||||
}
|
||||
|
||||
/// # Examples
|
||||
/// ```
|
||||
/// # use roc_parse::state::{State};
|
||||
/// # use crate::roc_parse::parser::{Parser, Progress, Progress::{MadeProgress, NoProgress}, word, word1};
|
||||
/// # use roc_region::all::{Loc, Position};
|
||||
/// # use roc_parse::ident::lowercase_ident;
|
||||
/// # use roc_parse::one_of_with_error;
|
||||
/// # use bumpalo::Bump;
|
||||
/// # #[derive(Debug, PartialEq)]
|
||||
/// # enum Problem {
|
||||
/// # NotFound(Position),
|
||||
/// # Other(Position),
|
||||
/// # }
|
||||
/// # let arena = Bump::new();
|
||||
/// # fn foo<'a>(arena: &'a Bump) {
|
||||
/// let parser = one_of_with_error!(
|
||||
/// Problem::Other;
|
||||
/// word("hello", Problem::NotFound)
|
||||
/// );
|
||||
/// let (progress, output, state) = parser.parse(&arena, State::new("hello, world".as_bytes()), 0).unwrap();
|
||||
/// assert_eq!(progress, Progress::MadeProgress);
|
||||
/// assert_eq!(output, ());
|
||||
/// assert_eq!(state.pos().offset, 5);
|
||||
///
|
||||
/// let (progress, err) = parser.parse(&arena, State::new("bye, world".as_bytes()), 0).unwrap_err();
|
||||
/// assert_eq!(progress, Progress::MadeProgress);
|
||||
/// assert_eq!(err, Problem::Other(Position::new(0)));
|
||||
/// # }
|
||||
/// # foo(&arena);
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! one_of_with_error {
|
||||
($toerror:expr; $p1:expr) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue