-
Hi, I wanted to try the pub(crate) fn text_plain_part<'a>() -> impl Parser<'a, &'a str, String, extra::Err<Rich<'a, char>>>
{
choice((
just(SINGLE_PART_BEGIN),
just(SINGLE_PART_END),
just(MULTI_PART_BEGIN),
just(MULTI_PART_END),
))
// FIXME: not() returns unit instead
.not()
.repeated()
.at_least(1)
.collect::<String>()
} Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
In this case to get the desired behavior you use something like pub(crate) fn text_plain_part<'a>() -> impl Parser<'a, &'a str, String, extra::Err<Rich<'a, char>>> {
any()
.and_is(
choice((
just(SINGLE_PART_BEGIN),
just(SINGLE_PART_END),
just(MULTI_PART_BEGIN),
just(MULTI_PART_END),
))
.not()
)
.repeated()
.at_least(1)
.map_slice(ToString::to_string)
} The |
Beta Was this translation helpful? Give feedback.
In this case to get the desired behavior you use something like
(map_)slice
:The
any().and_is(/* snip */)
is required because an empty parse is valid forsomething.not()
and therefore will infinite loop without progress when used in combination withrepeated
. By…