MMM: Correctly parse empty strings

Surely I wouldn't forget to do that, right?
This commit is contained in:
Natty 2023-12-30 19:23:32 +01:00
parent 64350cfcb8
commit 9c8489ced7
Signed by: natty
GPG Key ID: BF6CB659ADEE60EC
1 changed files with 36 additions and 15 deletions

View File

@ -718,40 +718,54 @@ impl Context {
} }
pub fn full<'a>(&self, input: Span<'a>) -> IResult<Span<'a>, Token> { pub fn full<'a>(&self, input: Span<'a>) -> IResult<Span<'a>, Token> {
map(many1(self.partial(Self::full_single)), Token::Sequence)(input) map(
many_till(self.partial(Self::full_single), eof).map(|v| v.0),
Token::Sequence,
)(input)
} }
pub fn inline<'a>(&self, input: Span<'a>) -> IResult<Span<'a>, Token> { pub fn inline<'a>(&self, input: Span<'a>) -> IResult<Span<'a>, Token> {
map(many1(self.partial(Self::inline_single)), Token::Sequence)(input) map(
many_till(self.partial(Self::inline_single), eof).map(|v| v.0),
Token::Sequence,
)(input)
} }
pub fn inline_label_safe<'a>(&self, input: Span<'a>) -> IResult<Span<'a>, Token> { pub fn inline_label_safe<'a>(&self, input: Span<'a>) -> IResult<Span<'a>, Token> {
map( map(
many1(self.partial(Self::inline_label_safe_single)), many_till(self.partial(Self::inline_label_safe_single), eof).map(|v| v.0),
Token::Sequence, Token::Sequence,
)(input) )(input)
} }
fn inline_profile_fields<'a>(&self, input: Span<'a>) -> IResult<Span<'a>, Token> { fn inline_profile_fields<'a>(&self, input: Span<'a>) -> IResult<Span<'a>, Token> {
map( map(
many1(alt(( many_till(
alt((
self.partial(Self::unicode_emoji), self.partial(Self::unicode_emoji),
self.partial(Self::tag_mention), self.partial(Self::tag_mention),
self.partial(Self::tag_hashtag), self.partial(Self::tag_hashtag),
self.partial(Self::raw_url), self.partial(Self::raw_url),
self.partial(Self::tag_raw_text), self.partial(Self::tag_raw_text),
))), )),
eof,
)
.map(|v| v.0),
Token::Sequence, Token::Sequence,
)(input) )(input)
} }
fn inline_ui<'a>(&self, input: Span<'a>) -> IResult<Span<'a>, Token> { fn inline_ui<'a>(&self, input: Span<'a>) -> IResult<Span<'a>, Token> {
map( map(
many1(alt(( many_till(
alt((
self.partial(Self::unicode_emoji), self.partial(Self::unicode_emoji),
self.partial(Self::shortcode_emoji), self.partial(Self::shortcode_emoji),
self.partial(Self::tag_raw_text), self.partial(Self::tag_raw_text),
))), )),
eof,
)
.map(|v| v.0),
Token::Sequence, Token::Sequence,
)(input) )(input)
} }
@ -1709,6 +1723,13 @@ mod test {
.merged() .merged()
} }
#[test]
fn parse_empty() {
let ctx = Context::default();
assert_eq!(parse_full(""), Token::Sequence(vec![]));
}
#[test] #[test]
fn parse_url_chars() { fn parse_url_chars() {
let ctx = Context::default(); let ctx = Context::default();