Rename contents to source to match objects that need to store a separate source.

This commit is contained in:
Tom Alexander 2022-12-18 04:40:44 -05:00
parent 448dcfac72
commit 89758721ed
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
4 changed files with 21 additions and 21 deletions

View File

@ -30,7 +30,7 @@ pub fn bold<'r, 's>(context: Context<'r, 's>, i: &'s str) -> Res<&'s str, Bold<'
let (remaining, captured) = recognize(tuple((bold_start, |i| {
context_many_till(&parser_context, text_element, context_bold_end)(i)
})))(i)?;
let ret = Bold { contents: captured };
let ret = Bold { source: captured };
Ok((remaining, ret))
}

View File

@ -27,7 +27,7 @@ pub fn link<'r, 's>(context: Context<'r, 's>, i: &'s str) -> Res<&'s str, Link<'
let (remaining, captured) = recognize(tuple((link_start, |i| {
context_many_till(&parser_context, text_element, context_link_end)(i)
})))(i)?;
let ret = Link { contents: captured };
let ret = Link { source: captured };
Ok((remaining, ret))
}

View File

@ -21,19 +21,19 @@ use super::token::TextElement;
use super::Context;
pub fn line_break(input: &str) -> Res<&str, LineBreak> {
map(line_ending, |s: &str| LineBreak { contents: s })(input)
map(line_ending, |s: &str| LineBreak { source: s })(input)
}
fn space(input: &str) -> Res<&str, Space> {
map(space1, |s: &str| Space { contents: s })(input)
map(space1, |s: &str| Space { source: s })(input)
}
fn span(input: &str) -> Res<&str, Span> {
map(alphanumeric1, |s: &str| Span { contents: s })(input)
map(alphanumeric1, |s: &str| Span { source: s })(input)
}
pub fn symbol(symbol_tag: &'static str) -> impl for<'a> Fn(&'a str) -> Res<&'a str, Symbol<'a>> {
move |i: &str| map(tag(symbol_tag), |s: &str| Symbol { contents: s })(i)
move |i: &str| map(tag(symbol_tag), |s: &str| Symbol { source: s })(i)
}
/// A line containing only whitespace and then a line break
@ -45,7 +45,7 @@ pub fn blank_line(input: &str) -> Res<&str, BlankLine> {
map(space, TextElement::Space),
map(line_break, TextElement::LineBreak),
)),
|contents| BlankLine { contents },
|contents| BlankLine { source: contents },
)(input)
}

View File

@ -28,42 +28,42 @@ pub enum TextElement<'a> {
#[derive(Debug)]
pub struct Span<'a> {
pub contents: &'a str,
pub source: &'a str,
}
#[derive(Debug)]
pub struct Space<'a> {
pub contents: &'a str,
pub source: &'a str,
}
#[derive(Debug)]
pub struct LineBreak<'a> {
pub contents: &'a str,
pub source: &'a str,
}
#[derive(Debug)]
pub struct Symbol<'a> {
pub contents: &'a str,
pub source: &'a str,
}
#[derive(Debug)]
pub struct BlankLine<'a> {
pub contents: &'a str,
pub source: &'a str,
}
#[derive(Debug)]
pub struct Sequence<'a> {
pub contents: &'a str,
pub source: &'a str,
}
#[derive(Debug)]
pub struct Bold<'a> {
pub contents: &'a str,
pub source: &'a str,
}
#[derive(Debug)]
pub struct Link<'a> {
pub contents: &'a str,
pub source: &'a str,
}
#[derive(Debug)]
@ -80,12 +80,12 @@ pub trait Source<'a> {
impl<'a> Source<'a> for TextElement<'a> {
fn get_source(&'a self) -> &'a str {
match self {
TextElement::Span(elem) => elem.contents,
TextElement::Space(elem) => elem.contents,
TextElement::LineBreak(elem) => elem.contents,
TextElement::Symbol(elem) => elem.contents,
TextElement::Bold(elem) => elem.contents,
TextElement::Link(elem) => elem.contents,
TextElement::Span(elem) => elem.source,
TextElement::Space(elem) => elem.source,
TextElement::LineBreak(elem) => elem.source,
TextElement::Symbol(elem) => elem.source,
TextElement::Bold(elem) => elem.source,
TextElement::Link(elem) => elem.source,
}
}
}