example for skip_second

This commit is contained in:
Trevor Settles 2024-03-09 18:46:52 -07:00
parent eed1957180
commit c582ad6767
No known key found for this signature in database
GPG Key ID: F46B83058222DBAA

View File

@ -1424,6 +1424,29 @@ macro_rules! skip_first {
/// If the first one parses, parse the second one; if it also parses, use the
/// output from the first one.
///
/// # Examples
/// ```
/// # use roc_parse::state::{State};
/// # use crate::roc_parse::parser::{Parser, Progress, word};
/// # use roc_parse::ident::lowercase_ident;
/// # use roc_parse::skip_second;
/// # use roc_region::all::{Loc, Position};
/// # use bumpalo::Bump;
/// # let arena = Bump::new();
/// # fn foo<'a>(arena: &'a Bump) {
/// let parser = skip_second!(
/// lowercase_ident(),
/// word(", world", |_| ())
/// );
///
/// let (progress, output, state) = parser.parse(&arena, State::new("hello, world".as_bytes()), 0).unwrap();
/// assert_eq!(progress, Progress::MadeProgress);
/// assert_eq!(output, "hello");
/// assert_eq!(state.pos().offset, 12);
/// # }
/// # foo(&arena);
/// ```
#[macro_export]
macro_rules! skip_second {
($p1:expr, $p2:expr) => {