Compare commits
No commits in common. "bffaca4d683b768a1564be762e2cd89dd2982210" and "41829019b6ef6e1ea6c577e6b2b68c38237e2df7" have entirely different histories.
bffaca4d68
...
41829019b6
@ -1,18 +0,0 @@
|
|||||||
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,12 +1,10 @@
|
|||||||
#![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::*;
|
||||||
@ -67,11 +65,4 @@ mod tests {
|
|||||||
let output = parser.parse("abcd").unwrap();
|
let output = parser.parse("abcd").unwrap();
|
||||||
assert_eq!((59, "cd"), output);
|
assert_eq!((59, "cd"), output);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_combinators() {
|
|
||||||
let parser = sequence(map(repeated(literal_char('a')), |_| 10), literal_char('b'));
|
|
||||||
let output = parser.parse("aaaaaaaabcd").unwrap();
|
|
||||||
assert_eq! {((10, 'b'), "cd"), output};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user