From 89758721ede17ad71281c08c24ce33cd2af6a28c Mon Sep 17 00:00:00 2001 From: Tom Alexander <tom@fizz.buzz> Date: Sun, 18 Dec 2022 04:40:44 -0500 Subject: [PATCH] Rename contents to source to match objects that need to store a separate source. --- src/parser/bold.rs | 2 +- src/parser/link.rs | 2 +- src/parser/text.rs | 10 +++++----- src/parser/token.rs | 28 ++++++++++++++-------------- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/parser/bold.rs b/src/parser/bold.rs index 0da997d..5c64cf7 100644 --- a/src/parser/bold.rs +++ b/src/parser/bold.rs @@ -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)) } diff --git a/src/parser/link.rs b/src/parser/link.rs index f9e6bc9..0b8f42e 100644 --- a/src/parser/link.rs +++ b/src/parser/link.rs @@ -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)) } diff --git a/src/parser/text.rs b/src/parser/text.rs index 054e480..4aaf632 100644 --- a/src/parser/text.rs +++ b/src/parser/text.rs @@ -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) } diff --git a/src/parser/token.rs b/src/parser/token.rs index d089aee..65d4bc0 100644 --- a/src/parser/token.rs +++ b/src/parser/token.rs @@ -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, } } }