Create structure for timestamps.

This commit is contained in:
Tom Alexander 2023-07-24 17:34:07 -04:00
parent 73e15286dc
commit fa5fc41121
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
6 changed files with 59 additions and 2 deletions

View File

@ -54,6 +54,7 @@ use crate::parser::Table;
use crate::parser::TableCell;
use crate::parser::TableRow;
use crate::parser::Target;
use crate::parser::Timestamp;
use crate::parser::Underline;
use crate::parser::Verbatim;
use crate::parser::VerseBlock;
@ -180,6 +181,7 @@ fn compare_object<'s>(
Object::StatisticsCookie(obj) => compare_statistics_cookie(source, emacs, obj),
Object::Subscript(obj) => compare_subscript(source, emacs, obj),
Object::Superscript(obj) => compare_superscript(source, emacs, obj),
Object::Timestamp(obj) => compare_timestamp(source, emacs, obj),
}
}
@ -1563,3 +1565,26 @@ fn compare_superscript<'s>(
children: Vec::new(),
})
}
fn compare_timestamp<'s>(
source: &'s str,
emacs: &'s Token<'s>,
rust: &'s Timestamp<'s>,
) -> Result<DiffResult, Box<dyn std::error::Error>> {
let mut this_status = DiffStatus::Good;
let emacs_name = "timestamp";
if assert_name(emacs, emacs_name).is_err() {
this_status = DiffStatus::Bad;
}
if assert_bounds(source, emacs, rust).is_err() {
this_status = DiffStatus::Bad;
}
Ok(DiffResult {
status: this_status,
name: emacs_name.to_owned(),
message: None,
children: Vec::new(),
})
}

View File

@ -47,6 +47,7 @@ mod subscript_and_superscript;
mod table;
mod target;
mod text_markup;
mod timestamp;
mod token;
mod util;
pub use document::document;
@ -104,6 +105,7 @@ pub use object::StrikeThrough;
pub use object::Subscript;
pub use object::Superscript;
pub use object::Target;
pub use object::Timestamp;
pub use object::Underline;
pub use object::Verbatim;
pub use source::Source;

View File

@ -28,6 +28,7 @@ pub enum Object<'s> {
StatisticsCookie(StatisticsCookie<'s>),
Subscript(Subscript<'s>),
Superscript(Superscript<'s>),
Timestamp(Timestamp<'s>),
}
#[derive(Debug, PartialEq)]
@ -179,6 +180,11 @@ pub struct Superscript<'s> {
pub source: &'s str,
}
#[derive(Debug, PartialEq)]
pub struct Timestamp<'s> {
pub source: &'s str,
}
impl<'s> Source<'s> for Object<'s> {
fn get_source(&'s self) -> &'s str {
match self {
@ -205,6 +211,7 @@ impl<'s> Source<'s> for Object<'s> {
Object::InlineSourceBlock(obj) => obj.source,
Object::LineBreak(obj) => obj.source,
Object::Target(obj) => obj.source,
Object::Timestamp(obj) => obj.source,
Object::StatisticsCookie(obj) => obj.source,
Object::Subscript(obj) => obj.source,
Object::Superscript(obj) => obj.source,
@ -361,3 +368,9 @@ impl<'s> Source<'s> for Superscript<'s> {
self.source
}
}
impl<'s> Source<'s> for Timestamp<'s> {
fn get_source(&'s self) -> &'s str {
self.source
}
}

View File

@ -26,16 +26,17 @@ use crate::parser::subscript_and_superscript::subscript;
use crate::parser::subscript_and_superscript::superscript;
use crate::parser::target::target;
use crate::parser::text_markup::text_markup;
use crate::parser::timestamp::timestamp;
#[tracing::instrument(ret, level = "debug")]
pub fn standard_set_object<'r, 's>(
context: Context<'r, 's>,
input: &'s str,
) -> Res<&'s str, Object<'s>> {
// TODO: subscript and superscript, timestamps.
not(|i| context.check_exit_matcher(i))(input)?;
alt((
map(parser_with_context!(timestamp)(context), Object::Timestamp),
map(parser_with_context!(subscript)(context), Object::Subscript),
map(
parser_with_context!(superscript)(context),
@ -116,6 +117,7 @@ pub fn any_object_except_plain_text<'r, 's>(
) -> Res<&'s str, Object<'s>> {
// Used for exit matchers so this does not check exit matcher condition.
alt((
map(parser_with_context!(timestamp)(context), Object::Timestamp),
map(parser_with_context!(subscript)(context), Object::Subscript),
map(
parser_with_context!(superscript)(context),
@ -170,8 +172,12 @@ pub fn regular_link_description_object_set<'r, 's>(
context: Context<'r, 's>,
input: &'s str,
) -> Res<&'s str, Object<'s>> {
// TODO: add export snippets. It can also contain another link, but only when it is a plain or angle link. It can contain square brackets, but not ]]
// TODO: It can also contain another link, but only when it is a plain or angle link. It can contain square brackets, but not ]]
alt((
map(
parser_with_context!(export_snippet)(context),
Object::ExportSnippet,
),
map(
parser_with_context!(statistics_cookie)(context),
Object::StatisticsCookie,

10
src/parser/timestamp.rs Normal file
View File

@ -0,0 +1,10 @@
use super::Context;
use crate::error::Res;
use crate::parser::util::not_yet_implemented;
use crate::parser::Timestamp;
#[tracing::instrument(ret, level = "debug")]
pub fn timestamp<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, Timestamp<'s>> {
not_yet_implemented()?;
todo!()
}

View File

@ -67,6 +67,7 @@ impl<'r, 's> Token<'r, 's> {
Object::StatisticsCookie(_) => Box::new(std::iter::empty()),
Object::Subscript(_) => Box::new(std::iter::empty()), // TODO: Iterate over children
Object::Superscript(_) => Box::new(std::iter::empty()), // TODO: Iterate over children
Object::Timestamp(_) => Box::new(std::iter::empty()),
},
Token::Element(elem) => match elem {
Element::Paragraph(inner) => Box::new(inner.children.iter().map(Token::Object)),