mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 15:21:12 +00:00
Add one_of2 and one_of3
This commit is contained in:
parent
f9f63f88c6
commit
329effe4ea
1 changed files with 35 additions and 0 deletions
|
@ -252,3 +252,38 @@ fn whitespace<'a>() -> impl Parser<'a, char> {
|
|||
// TODO advance the state appropriately, in terms of line, col, indenting, etc.
|
||||
satisfies(any, |ch| ch.is_whitespace())
|
||||
}
|
||||
|
||||
pub fn one_of2<'a, P1, P2, A>(p1: P1, p2: P2) -> impl Parser<'a, A>
|
||||
where
|
||||
P1: Parser<'a, A>,
|
||||
P2: Parser<'a, A>,
|
||||
{
|
||||
move |arena: &'a Bump, state: State<'a>, attempting| {
|
||||
if let Ok((next_state, output)) = p1.parse(arena, state, attempting) {
|
||||
Ok((next_state, output))
|
||||
} else if let Ok((next_state, output)) = p2.parse(arena, state, attempting) {
|
||||
Ok((next_state, output))
|
||||
} else {
|
||||
Err((state.clone(), attempting))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn one_of3<'a, P1, P2, P3, A>(p1: P1, p2: P2, p3: P3) -> impl Parser<'a, A>
|
||||
where
|
||||
P1: Parser<'a, A>,
|
||||
P2: Parser<'a, A>,
|
||||
P3: Parser<'a, A>,
|
||||
{
|
||||
move |arena: &'a Bump, state: State<'a>, attempting| {
|
||||
if let Ok((next_state, output)) = p1.parse(arena, state, attempting) {
|
||||
Ok((next_state, output))
|
||||
} else if let Ok((next_state, output)) = p2.parse(arena, state, attempting) {
|
||||
Ok((next_state, output))
|
||||
} else if let Ok((next_state, output)) = p3.parse(arena, state, attempting) {
|
||||
Ok((next_state, output))
|
||||
} else {
|
||||
Err((state.clone(), attempting))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue