Make the types more consistent.

This commit is contained in:
Tom Alexander 2022-11-25 18:55:56 -05:00
parent cc41074563
commit c312673f12
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
2 changed files with 10 additions and 15 deletions

View File

@ -66,7 +66,7 @@ pub struct Symbol<'a> {
#[derive(Debug)]
pub struct BlankLine<'a> {
contents: Vec<TextElement<'a>>,
contents: &'a str,
}
#[derive(Debug)]
@ -105,16 +105,11 @@ pub fn symbol(symbol_tag: &'static str) -> impl for<'a> Fn(&'a str) -> Res<&'a s
/// It is up to the caller to ensure this is called at the start of a line.
fn blank_line(input: &str) -> Res<&str, BlankLine> {
map(
many_till(
recognize(many_till(
map(space, TextElement::Space),
map(line_break, TextElement::LineBreak),
),
|(mut whitespace, end_of_line)| {
whitespace.push(end_of_line);
BlankLine {
contents: whitespace,
}
},
)),
|contents| BlankLine { contents },
)(input)
}

View File

@ -39,8 +39,8 @@ fn flat_text_element<'s, 'r>(
let link_matcher = parser_with_context!(flat_link)(context);
alt((
bold_matcher,
link_matcher,
map(bold_matcher, TextElement::Bold),
map(link_matcher, TextElement::Link),
map(span, TextElement::Span),
map(symbol("*"), TextElement::Symbol),
map(symbol("["), TextElement::Symbol),
@ -54,14 +54,14 @@ fn recognize_bold_end(input: &str) -> Res<&str, &str> {
recognize(bold_end)(input)
}
fn flat_bold<'s, 'r>(i: &'s str, context: &'r OrgModeContext<'r>) -> Res<&'s str, TextElement<'s>> {
fn flat_bold<'s, 'r>(i: &'s str, context: &'r OrgModeContext<'r>) -> Res<&'s str, Bold<'s>> {
let new_context = context.with_additional_fail_matcher(&recognize_bold_end);
let text_element_parser = parser_with_context!(flat_text_element)(&new_context);
let (remaining, captured) = recognize(tuple((
bold_start,
many_till(text_element_parser, bold_end),
)))(i)?;
let ret = TextElement::Bold(Bold { contents: captured });
let ret = Bold { contents: captured };
Ok((remaining, ret))
}
@ -69,14 +69,14 @@ fn recognize_link_end(input: &str) -> Res<&str, &str> {
recognize(link_end)(input)
}
fn flat_link<'s, 'r>(i: &'s str, context: &'r OrgModeContext<'r>) -> Res<&'s str, TextElement<'s>> {
fn flat_link<'s, 'r>(i: &'s str, context: &'r OrgModeContext<'r>) -> Res<&'s str, Link<'s>> {
let new_context = context.with_additional_fail_matcher(&recognize_link_end);
let text_element_parser = parser_with_context!(flat_text_element)(&new_context);
let (remaining, captured) = recognize(tuple((
link_start,
many_till(text_element_parser, link_end),
)))(i)?;
let ret = TextElement::Link(Link { contents: captured });
let ret = Link { contents: captured };
Ok((remaining, ret))
}