Compare commits

..

No commits in common. "477fc50b65f3c8c8b444d65d07239d95aa8f0a53" and "bffaca4d683b768a1564be762e2cd89dd2982210" have entirely different histories.

3 changed files with 0 additions and 29 deletions

View File

@ -1,6 +0,0 @@
_default:
just --list
test:
cargo nextest run

View File

@ -16,13 +16,3 @@ where
Ok((results, acc)) Ok((results, acc))
} }
} }
pub fn optional<I, O, E>(parser: impl Parser<I, O, E>) -> impl Parser<I, Option<O>, E>
where
I: Clone,
{
move |input: I| match parser.parse(input.clone()) {
Ok((output, rest)) => Ok((Some(output), rest)),
Err(_e) => Ok((None, input)),
}
}

View File

@ -74,17 +74,4 @@ mod tests {
let output = parser.parse("aaaaaaaabcd").unwrap(); let output = parser.parse("aaaaaaaabcd").unwrap();
assert_eq! {((10, 'b'), "cd"), output}; assert_eq! {((10, 'b'), "cd"), output};
} }
#[test]
fn test_optional() {
let parser = sequence(
optional(literal("alpha")),
sequence(repeated(literal(" ")), literal("beta")),
);
let output1 = parser.parse(" beta").unwrap();
assert_eq!(output1.0 .0, None);
let output2 = parser.parse("alpha beta").unwrap();
assert_eq!(output2.0 .0, Some("alpha"));
}
} }