Make the types more consistent.
This commit is contained in:
parent
cc41074563
commit
c312673f12
@ -66,7 +66,7 @@ pub struct Symbol<'a> {
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct BlankLine<'a> {
|
pub struct BlankLine<'a> {
|
||||||
contents: Vec<TextElement<'a>>,
|
contents: &'a str,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[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.
|
/// 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> {
|
fn blank_line(input: &str) -> Res<&str, BlankLine> {
|
||||||
map(
|
map(
|
||||||
many_till(
|
recognize(many_till(
|
||||||
map(space, TextElement::Space),
|
map(space, TextElement::Space),
|
||||||
map(line_break, TextElement::LineBreak),
|
map(line_break, TextElement::LineBreak),
|
||||||
),
|
)),
|
||||||
|(mut whitespace, end_of_line)| {
|
|contents| BlankLine { contents },
|
||||||
whitespace.push(end_of_line);
|
|
||||||
BlankLine {
|
|
||||||
contents: whitespace,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
)(input)
|
)(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,8 +39,8 @@ fn flat_text_element<'s, 'r>(
|
|||||||
let link_matcher = parser_with_context!(flat_link)(context);
|
let link_matcher = parser_with_context!(flat_link)(context);
|
||||||
|
|
||||||
alt((
|
alt((
|
||||||
bold_matcher,
|
map(bold_matcher, TextElement::Bold),
|
||||||
link_matcher,
|
map(link_matcher, TextElement::Link),
|
||||||
map(span, TextElement::Span),
|
map(span, TextElement::Span),
|
||||||
map(symbol("*"), TextElement::Symbol),
|
map(symbol("*"), TextElement::Symbol),
|
||||||
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)
|
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 new_context = context.with_additional_fail_matcher(&recognize_bold_end);
|
||||||
let text_element_parser = parser_with_context!(flat_text_element)(&new_context);
|
let text_element_parser = parser_with_context!(flat_text_element)(&new_context);
|
||||||
let (remaining, captured) = recognize(tuple((
|
let (remaining, captured) = recognize(tuple((
|
||||||
bold_start,
|
bold_start,
|
||||||
many_till(text_element_parser, bold_end),
|
many_till(text_element_parser, bold_end),
|
||||||
)))(i)?;
|
)))(i)?;
|
||||||
let ret = TextElement::Bold(Bold { contents: captured });
|
let ret = Bold { contents: captured };
|
||||||
Ok((remaining, ret))
|
Ok((remaining, ret))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,14 +69,14 @@ fn recognize_link_end(input: &str) -> Res<&str, &str> {
|
|||||||
recognize(link_end)(input)
|
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 new_context = context.with_additional_fail_matcher(&recognize_link_end);
|
||||||
let text_element_parser = parser_with_context!(flat_text_element)(&new_context);
|
let text_element_parser = parser_with_context!(flat_text_element)(&new_context);
|
||||||
let (remaining, captured) = recognize(tuple((
|
let (remaining, captured) = recognize(tuple((
|
||||||
link_start,
|
link_start,
|
||||||
many_till(text_element_parser, link_end),
|
many_till(text_element_parser, link_end),
|
||||||
)))(i)?;
|
)))(i)?;
|
||||||
let ret = TextElement::Link(Link { contents: captured });
|
let ret = Link { contents: captured };
|
||||||
Ok((remaining, ret))
|
Ok((remaining, ret))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user