pub fn sequence<'a, A: Clone + 'a, StartOutput: Clone + 'a, StartParser, ItemParser, SepOutput: Clone + 'a, SepParser, SpacesParser, EndOutput: Clone + 'a, EndParser, S: Clone + 'a>(
start: StartParser,
item: impl Fn() -> ItemParser,
separator: impl Fn() -> SepParser,
spaces: impl Fn() -> SpacesParser,
end: EndParser,
trailing: Trailing,
) -> impl Parser<'a, Output = Vec<A>, State = S>Expand description
Parse a sequence like lists or code blocks.
Example: Parse a list containing the string “abc” with optional trailing comma:
assert_succeed(sequence(
token("["),
|| token("abc"),
|| token(","),
|| space0(),
token("]"),
Trailing::Optional),
"[abc, abc, abc]", vec!["abc", "abc", "abc"]);Note: spaces are inserted between every part.
So if you use space1 instead of space0, you need to
put more spaces before and after separators, between
start symbol and first item and between last item or separator
and the end symbol:
assert_succeed(sequence(
token("["),
|| token("abc"),
|| token(","),
|| space1(),
token("]"),
Trailing::Optional),
"[ abc , abc , abc ]", vec!["abc", "abc", "abc"]);