Create structure for targets.

This commit is contained in:
Tom Alexander 2023-07-22 01:15:04 -04:00
parent 537fc00fd3
commit d60cad07e0
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
4 changed files with 41 additions and 0 deletions

View File

@ -50,6 +50,7 @@ use crate::parser::StrikeThrough;
use crate::parser::Table;
use crate::parser::TableCell;
use crate::parser::TableRow;
use crate::parser::Target;
use crate::parser::Underline;
use crate::parser::Verbatim;
use crate::parser::VerseBlock;
@ -172,6 +173,7 @@ fn compare_object<'s>(
Object::InlineBabelCall(obj) => compare_inline_babel_call(source, emacs, obj),
Object::InlineSourceBlock(obj) => compare_inline_source_block(source, emacs, obj),
Object::LineBreak(obj) => compare_line_break(source, emacs, obj),
Object::Target(obj) => compare_target(source, emacs, obj),
}
}
@ -1463,3 +1465,26 @@ fn compare_line_break<'s>(
children: Vec::new(),
})
}
fn compare_target<'s>(
source: &'s str,
emacs: &'s Token<'s>,
rust: &'s Target<'s>,
) -> Result<DiffResult, Box<dyn std::error::Error>> {
let mut this_status = DiffStatus::Good;
let emacs_name = "target";
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

@ -43,6 +43,7 @@ mod regular_link;
pub mod sexp;
mod source;
mod table;
mod target;
mod text_markup;
mod token;
mod util;
@ -97,6 +98,7 @@ pub use object::RadioLink;
pub use object::RadioTarget;
pub use object::RegularLink;
pub use object::StrikeThrough;
pub use object::Target;
pub use object::Underline;
pub use object::Verbatim;
pub use source::Source;

View File

@ -24,6 +24,7 @@ pub enum Object<'s> {
InlineBabelCall(InlineBabelCall<'s>),
InlineSourceBlock(InlineSourceBlock<'s>),
LineBreak(LineBreak<'s>),
Target(Target<'s>),
}
#[derive(Debug, PartialEq)]
@ -155,6 +156,11 @@ pub struct LineBreak<'s> {
pub source: &'s str,
}
#[derive(Debug, PartialEq)]
pub struct Target<'s> {
pub source: &'s str,
}
impl<'s> Source<'s> for Object<'s> {
fn get_source(&'s self) -> &'s str {
match self {
@ -180,6 +186,7 @@ impl<'s> Source<'s> for Object<'s> {
Object::InlineBabelCall(obj) => obj.source,
Object::InlineSourceBlock(obj) => obj.source,
Object::LineBreak(obj) => obj.source,
Object::Target(obj) => obj.source,
}
}
}
@ -309,3 +316,9 @@ impl<'s> Source<'s> for LineBreak<'s> {
self.source
}
}
impl<'s> Source<'s> for Target<'s> {
fn get_source(&'s self) -> &'s str {
self.source
}
}

View File

@ -63,6 +63,7 @@ impl<'r, 's> Token<'r, 's> {
Object::InlineBabelCall(_) => Box::new(std::iter::empty()),
Object::InlineSourceBlock(_) => Box::new(std::iter::empty()),
Object::LineBreak(_) => Box::new(std::iter::empty()),
Object::Target(_) => Box::new(std::iter::empty()),
},
Token::Element(elem) => match elem {
Element::Paragraph(inner) => Box::new(inner.children.iter().map(Token::Object)),