repeated combinator
This commit is contained in:
parent
41829019b6
commit
97d35df687
18
src/combinators.rs
Normal file
18
src/combinators.rs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
use crate::Parser;
|
||||||
|
|
||||||
|
pub fn repeated<P, I, O, E>(parser: P) -> impl Parser<I, Vec<O>, E>
|
||||||
|
where
|
||||||
|
P: Parser<I, O, E>,
|
||||||
|
I: Copy,
|
||||||
|
{
|
||||||
|
move |input: I| {
|
||||||
|
let mut acc = input;
|
||||||
|
let mut results = vec![];
|
||||||
|
|
||||||
|
while let Ok((item, rest)) = parser.parse(acc) {
|
||||||
|
results.push(item);
|
||||||
|
acc = rest;
|
||||||
|
}
|
||||||
|
Ok((results, acc))
|
||||||
|
}
|
||||||
|
}
|
@ -1,10 +1,12 @@
|
|||||||
#![allow(dead_code)] //TODO eventually turn this off
|
#![allow(dead_code)] //TODO eventually turn this off
|
||||||
mod choice;
|
mod choice;
|
||||||
|
mod combinators;
|
||||||
mod map;
|
mod map;
|
||||||
mod primitives;
|
mod primitives;
|
||||||
mod sequence;
|
mod sequence;
|
||||||
|
|
||||||
pub use choice::*;
|
pub use choice::*;
|
||||||
|
pub use combinators::*;
|
||||||
pub use map::*;
|
pub use map::*;
|
||||||
pub use primitives::*;
|
pub use primitives::*;
|
||||||
pub use sequence::*;
|
pub use sequence::*;
|
||||||
|
Loading…
Reference in New Issue
Block a user