Unify the standard properties checks in diff.
Instead of copy+pasting them into each compare function, we now call a shared function from a handful of places.
This commit is contained in:
@@ -4,6 +4,7 @@ use super::greater_element::GreaterBlock;
|
||||
use super::greater_element::PlainList;
|
||||
use super::greater_element::PropertyDrawer;
|
||||
use super::greater_element::Table;
|
||||
use super::lesser_element::BabelCall;
|
||||
use super::lesser_element::Clock;
|
||||
use super::lesser_element::Comment;
|
||||
use super::lesser_element::CommentBlock;
|
||||
@@ -45,7 +46,7 @@ pub enum Element<'s> {
|
||||
FixedWidthArea(FixedWidthArea<'s>),
|
||||
HorizontalRule(HorizontalRule<'s>),
|
||||
Keyword(Keyword<'s>),
|
||||
BabelCall(Keyword<'s>),
|
||||
BabelCall(BabelCall<'s>),
|
||||
LatexEnvironment(LatexEnvironment<'s>),
|
||||
}
|
||||
|
||||
|
||||
@@ -2,9 +2,7 @@ use super::StandardProperties;
|
||||
|
||||
pub trait GetStandardProperties<'s> {
|
||||
// TODO: Can I eliminate this dynamic dispatch, perhaps using nominal generic structs? Low prioritiy since this is not used during parsing.
|
||||
fn get_standard_properties(&'s self) -> &'s dyn StandardProperties
|
||||
where
|
||||
Self: Sized;
|
||||
fn get_standard_properties(&'s self) -> &'s dyn StandardProperties;
|
||||
}
|
||||
|
||||
impl<'s, I: StandardProperties<'s>> GetStandardProperties<'s> for I {
|
||||
|
||||
@@ -91,6 +91,13 @@ pub struct Keyword<'s> {
|
||||
pub value: &'s str,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct BabelCall<'s> {
|
||||
pub source: &'s str,
|
||||
pub key: &'s str,
|
||||
pub value: &'s str,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct LatexEnvironment<'s> {
|
||||
pub source: &'s str,
|
||||
@@ -187,6 +194,12 @@ impl<'s> StandardProperties<'s> for Keyword<'s> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'s> StandardProperties<'s> for BabelCall<'s> {
|
||||
fn get_source(&'s self) -> &'s str {
|
||||
self.source
|
||||
}
|
||||
}
|
||||
|
||||
impl<'s> StandardProperties<'s> for LatexEnvironment<'s> {
|
||||
fn get_source(&'s self) -> &'s str {
|
||||
self.source
|
||||
|
||||
@@ -27,6 +27,7 @@ pub use greater_element::PlainListItem;
|
||||
pub use greater_element::PropertyDrawer;
|
||||
pub use greater_element::Table;
|
||||
pub use greater_element::TableRow;
|
||||
pub use lesser_element::BabelCall;
|
||||
pub use lesser_element::Clock;
|
||||
pub use lesser_element::Comment;
|
||||
pub use lesser_element::CommentBlock;
|
||||
|
||||
Reference in New Issue
Block a user