mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 22:09:09 +00:00
example for between
This commit is contained in:
parent
805ca70f75
commit
8ae0d99707
1 changed files with 26 additions and 0 deletions
|
@ -2675,6 +2675,32 @@ macro_rules! either {
|
|||
|
||||
/// Parse everything between two braces (e.g. parentheses), skipping both braces
|
||||
/// and keeping only whatever was parsed in between them.
|
||||
///
|
||||
/// # Example
|
||||
/// ```rust
|
||||
/// # use roc_parse::state::{State};
|
||||
/// # use crate::roc_parse::parser::{Parser, Progress, Progress::{MadeProgress, NoProgress}, word, word1};
|
||||
/// # use roc_region::all::Position;
|
||||
/// # use roc_parse::{between, skip_first, skip_second};
|
||||
/// # use bumpalo::{Bump, vec};
|
||||
/// # #[derive(Debug, PartialEq)]
|
||||
/// # enum Problem {
|
||||
/// # NotFound(Position),
|
||||
/// # }
|
||||
/// # let arena = Bump::new();
|
||||
/// # fn foo<'a>(arena: &'a Bump) {
|
||||
/// let parser = between!(
|
||||
/// word1(b'(', Problem::NotFound),
|
||||
/// word("hello", Problem::NotFound),
|
||||
/// word1(b')', 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, 7);
|
||||
/// # }
|
||||
/// # foo(&arena);
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! between {
|
||||
($opening_brace:expr, $parser:expr, $closing_brace:expr) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue