From 4ba9d7439a27da143d7141b1dd30001a7d6aea83 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Thu, 5 Oct 2023 03:46:14 -0400 Subject: [PATCH] Compare value. --- src/compare/diff.rs | 12 ++++++++++-- src/parser/diary_sexp.rs | 11 +++++------ src/types/lesser_element.rs | 1 + 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/compare/diff.rs b/src/compare/diff.rs index e9bd4926..052df3f1 100644 --- a/src/compare/diff.rs +++ b/src/compare/diff.rs @@ -2161,8 +2161,6 @@ fn compare_diary_sexp<'b, 's>( let mut this_status = DiffStatus::Good; let mut message = None; - // TODO: Compare :value - // TODO: Compare :caption // Compare name let name = get_property_quoted_string(emacs, ":name")?; @@ -2174,6 +2172,16 @@ fn compare_diary_sexp<'b, 's>( )); } + // Compare value + let value = get_property_quoted_string(emacs, ":value")?; + if value.as_ref().map(String::as_str) != Some(rust.value) { + this_status = DiffStatus::Bad; + message = Some(format!( + "Value mismatch (emacs != rust) {:?} != {:?}", + value, rust.value + )); + } + Ok(DiffResult { status: this_status, name: rust.get_elisp_name(), diff --git a/src/parser/diary_sexp.rs b/src/parser/diary_sexp.rs index 5c506f50..235fcabf 100644 --- a/src/parser/diary_sexp.rs +++ b/src/parser/diary_sexp.rs @@ -1,14 +1,13 @@ -use nom::branch::alt; use nom::bytes::complete::is_not; use nom::bytes::complete::tag; -use nom::character::complete::line_ending; -use nom::combinator::eof; +use nom::combinator::recognize; use nom::multi::many0; use nom::sequence::tuple; use super::keyword::affiliated_keyword; use super::org_source::OrgSource; use super::util::get_name; +use super::util::org_line_ending; use crate::context::RefContext; use crate::error::Res; use crate::parser::util::get_consumed; @@ -22,9 +21,8 @@ pub(crate) fn diary_sexp<'b, 'g, 'r, 's>( ) -> Res, DiarySexp<'s>> { let (input, affiliated_keywords) = many0(affiliated_keyword)(input)?; start_of_line(input)?; - let (remaining, _clock) = tag("%%(")(input)?; - let (remaining, _contents) = is_not("\r\n")(remaining)?; - let (remaining, _eol) = alt((line_ending, eof))(remaining)?; + let (remaining, value) = recognize(tuple((tag("%%("), is_not("\r\n"))))(input)?; + let (remaining, _eol) = org_line_ending(remaining)?; let source = get_consumed(input, remaining); Ok(( @@ -32,6 +30,7 @@ pub(crate) fn diary_sexp<'b, 'g, 'r, 's>( DiarySexp { source: source.into(), name: get_name(&affiliated_keywords), + value: Into::<&str>::into(value), }, )) } diff --git a/src/types/lesser_element.rs b/src/types/lesser_element.rs index dd19efeb..402636ff 100644 --- a/src/types/lesser_element.rs +++ b/src/types/lesser_element.rs @@ -102,6 +102,7 @@ pub struct Clock<'s> { pub struct DiarySexp<'s> { pub source: &'s str, pub name: Option<&'s str>, + pub value: &'s str, } #[derive(Debug)]