From ed8b1405db6da1581fdb0a48f38f76b9545a6bb8 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Thu, 13 Jul 2023 22:42:42 -0400 Subject: [PATCH] Create structure for angle links. --- src/compare/diff.rs | 25 +++++++++++++++++++++++++ src/parser/angle_link.rs | 10 ++++++++++ src/parser/mod.rs | 2 ++ src/parser/object.rs | 15 +++++++++++++++ src/parser/object_parser.rs | 3 +++ 5 files changed, 55 insertions(+) create mode 100644 src/parser/angle_link.rs diff --git a/src/compare/diff.rs b/src/compare/diff.rs index 91a896b..1268fb3 100644 --- a/src/compare/diff.rs +++ b/src/compare/diff.rs @@ -1,6 +1,7 @@ use super::util::assert_bounds; use super::util::assert_name; use crate::parser::sexp::Token; +use crate::parser::AngleLink; use crate::parser::Bold; use crate::parser::Clock; use crate::parser::Code; @@ -150,6 +151,7 @@ fn compare_object<'s>( Object::RadioLink(obj) => compare_radio_link(source, emacs, obj), Object::RadioTarget(obj) => compare_radio_target(source, emacs, obj), Object::PlainLink(obj) => compare_plain_link(source, emacs, obj), + Object::AngleLink(obj) => compare_angle_link(source, emacs, obj), } } @@ -1188,3 +1190,26 @@ fn compare_plain_link<'s>( children: Vec::new(), }) } + +fn compare_angle_link<'s>( + source: &'s str, + emacs: &'s Token<'s>, + rust: &'s AngleLink<'s>, +) -> Result> { + let mut this_status = DiffStatus::Good; + let emacs_name = "link"; + 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(), + }) +} diff --git a/src/parser/angle_link.rs b/src/parser/angle_link.rs new file mode 100644 index 0000000..94e0a9a --- /dev/null +++ b/src/parser/angle_link.rs @@ -0,0 +1,10 @@ +use super::Context; +use crate::error::Res; +use crate::parser::util::not_yet_implemented; +use crate::parser::AngleLink; + +#[tracing::instrument(ret, level = "debug")] +pub fn angle_link<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, AngleLink<'s>> { + not_yet_implemented()?; + todo!(); +} diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 89f3a75..acb620e 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -1,3 +1,4 @@ +mod angle_link; mod clock; mod comment; mod diary_sexp; @@ -64,6 +65,7 @@ pub use lesser_element::Planning; pub use lesser_element::SrcBlock; pub use lesser_element::TableCell; pub use lesser_element::VerseBlock; +pub use object::AngleLink; pub use object::Bold; pub use object::Code; pub use object::Italic; diff --git a/src/parser/object.rs b/src/parser/object.rs index cef816c..bf4b85e 100644 --- a/src/parser/object.rs +++ b/src/parser/object.rs @@ -6,6 +6,7 @@ pub enum Object<'s> { RadioLink(RadioLink<'s>), RadioTarget(RadioTarget<'s>), PlainLink(PlainLink<'s>), + AngleLink(AngleLink<'s>), Bold(Bold<'s>), Italic(Italic<'s>), Underline(Underline<'s>), @@ -80,6 +81,13 @@ pub struct PlainLink<'s> { pub path: &'s str, } +#[derive(Debug, PartialEq)] +pub struct AngleLink<'s> { + pub source: &'s str, + pub link_type: &'s str, + pub path: &'s str, +} + impl<'s> Source<'s> for Object<'s> { fn get_source(&'s self) -> &'s str { match self { @@ -94,6 +102,7 @@ impl<'s> Source<'s> for Object<'s> { Object::RadioLink(obj) => obj.source, Object::RadioTarget(obj) => obj.source, Object::PlainLink(obj) => obj.source, + Object::AngleLink(obj) => obj.source, } } } @@ -157,3 +166,9 @@ impl<'s> Source<'s> for PlainLink<'s> { self.source } } + +impl<'s> Source<'s> for AngleLink<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} diff --git a/src/parser/object_parser.rs b/src/parser/object_parser.rs index 3b29a6c..e21231f 100644 --- a/src/parser/object_parser.rs +++ b/src/parser/object_parser.rs @@ -7,6 +7,7 @@ use super::plain_text::plain_text; use super::regular_link::regular_link; use super::Context; use crate::error::Res; +use crate::parser::angle_link::angle_link; use crate::parser::object::Object; use crate::parser::plain_link::plain_link; use crate::parser::radio_link::radio_link; @@ -33,6 +34,7 @@ pub fn standard_set_object<'r, 's>( Object::RegularLink, ), map(parser_with_context!(plain_link)(context), Object::PlainLink), + map(parser_with_context!(angle_link)(context), Object::AngleLink), map(parser_with_context!(plain_text)(context), Object::PlainText), ))(input) } @@ -69,6 +71,7 @@ pub fn any_object_except_plain_text<'r, 's>( Object::RegularLink, ), map(parser_with_context!(plain_link)(context), Object::PlainLink), + map(parser_with_context!(angle_link)(context), Object::AngleLink), ))(input) }