Bubble up planning variables to the headline.

This commit is contained in:
Tom Alexander 2023-10-02 20:37:46 -04:00
parent 2e1a946ac9
commit a80d171e4d
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
4 changed files with 78 additions and 10 deletions

View File

@ -719,9 +719,58 @@ fn compare_heading<'b, 's>(
));
}
// TODO: Compare :pre-blank :scheduled :closed
//
// :scheduled and :closed seem to only appear when the headline has a planning
// Compare scheduled
let scheduled = get_property(emacs, ":scheduled")?;
match (scheduled, &rust.scheduled) {
(None, None) => {}
(None, Some(_)) | (Some(_), None) => {
this_status = DiffStatus::Bad;
message = Some(format!(
"Scheduled mismatch (emacs != rust) {:?} != {:?}",
scheduled, rust.scheduled
));
}
(Some(emacs_child), Some(rust_child)) => {
let result = compare_ast_node(source, emacs_child, rust_child.into())?;
child_status.push(artificial_diff_scope("scheduled", vec![result])?);
}
}
// Compare deadline
let deadline = get_property(emacs, ":deadline")?;
match (deadline, &rust.deadline) {
(None, None) => {}
(None, Some(_)) | (Some(_), None) => {
this_status = DiffStatus::Bad;
message = Some(format!(
"Deadline mismatch (emacs != rust) {:?} != {:?}",
deadline, rust.deadline
));
}
(Some(emacs_child), Some(rust_child)) => {
let result = compare_ast_node(source, emacs_child, rust_child.into())?;
child_status.push(artificial_diff_scope("deadline", vec![result])?);
}
}
// Compare closed
let closed = get_property(emacs, ":closed")?;
match (closed, &rust.closed) {
(None, None) => {}
(None, Some(_)) | (Some(_), None) => {
this_status = DiffStatus::Bad;
message = Some(format!(
"Closed mismatch (emacs != rust) {:?} != {:?}",
closed, rust.closed
));
}
(Some(emacs_child), Some(rust_child)) => {
let result = compare_ast_node(source, emacs_child, rust_child.into())?;
child_status.push(artificial_diff_scope("closed", vec![result])?);
}
}
// TODO: Compare :pre-blank
// Compare section
let section_status = children
@ -1402,7 +1451,7 @@ fn compare_diary_sexp<'b, 's>(
}
fn compare_planning<'b, 's>(
_source: &'s str,
source: &'s str,
emacs: &'b Token<'s>,
rust: &'b Planning<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
@ -1422,7 +1471,7 @@ fn compare_planning<'b, 's>(
));
}
(Some(emacs_child), Some(rust_child)) => {
let result = compare_ast_node(_source, emacs_child, rust_child.into())?;
let result = compare_ast_node(source, emacs_child, rust_child.into())?;
child_status.push(artificial_diff_scope("scheduled", vec![result])?);
}
}
@ -1439,7 +1488,7 @@ fn compare_planning<'b, 's>(
));
}
(Some(emacs_child), Some(rust_child)) => {
let result = compare_ast_node(_source, emacs_child, rust_child.into())?;
let result = compare_ast_node(source, emacs_child, rust_child.into())?;
child_status.push(artificial_diff_scope("deadline", vec![result])?);
}
}
@ -1456,7 +1505,7 @@ fn compare_planning<'b, 's>(
));
}
(Some(emacs_child), Some(rust_child)) => {
let result = compare_ast_node(_source, emacs_child, rust_child.into())?;
let result = compare_ast_node(source, emacs_child, rust_child.into())?;
child_status.push(artificial_diff_scope("closed", vec![result])?);
}
}

View File

@ -34,6 +34,7 @@ use crate::error::Res;
use crate::parser::object_parser::standard_set_object;
use crate::parser::util::blank_line;
use crate::types::DocumentElement;
use crate::types::Element;
use crate::types::Heading;
use crate::types::HeadlineLevel;
use crate::types::Object;
@ -55,6 +56,9 @@ fn _heading<'b, 'g, 'r, 's>(
input: OrgSource<'s>,
parent_star_count: HeadlineLevel,
) -> Res<OrgSource<'s>, Heading<'s>> {
let mut scheduled = None;
let mut deadline = None;
let mut closed = None;
not(|i| context.check_exit_matcher(i))(input)?;
let (remaining, pre_headline) = headline(context, input, parent_star_count)?;
let section_matcher = parser_with_context!(section)(context);
@ -65,6 +69,14 @@ fn _heading<'b, 'g, 'r, 's>(
let (remaining, mut children) =
many0(map(heading_matcher, DocumentElement::Heading))(remaining)?;
if let Some(section) = maybe_section {
// If the section has a planning then the timestamp values are copied to the heading.
if let DocumentElement::Section(inner_section) = &section {
if let Some(Element::Planning(planning)) = inner_section.children.first() {
scheduled = planning.scheduled.clone();
deadline = planning.deadline.clone();
closed = planning.closed.clone();
}
}
children.insert(0, section);
}
let remaining = if children.is_empty() {
@ -94,6 +106,9 @@ fn _heading<'b, 'g, 'r, 's>(
is_comment: pre_headline.comment.is_some(),
is_archived,
is_footnote_section: pre_headline.is_footnote_section,
scheduled,
deadline,
closed,
},
))
}

View File

@ -4,6 +4,7 @@ use super::Element;
use super::GetStandardProperties;
use super::Object;
use super::StandardProperties;
use super::Timestamp;
pub type PriorityCookie = u8;
pub type HeadlineLevel = u16;
@ -29,6 +30,9 @@ pub struct Heading<'s> {
pub is_comment: bool,
pub is_archived: bool,
pub is_footnote_section: bool,
pub scheduled: Option<Timestamp<'s>>,
pub deadline: Option<Timestamp<'s>>,
pub closed: Option<Timestamp<'s>>,
}
#[derive(Debug)]

View File

@ -182,7 +182,7 @@ pub struct Superscript<'s> {
pub source: &'s str,
}
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone)]
pub struct Timestamp<'s> {
pub source: &'s str,
pub timestamp_type: TimestampType,
@ -195,7 +195,7 @@ pub struct Timestamp<'s> {
pub warning_delay: Option<WarningDelay>,
}
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone)]
pub enum TimestampType {
Diary,
Active,
@ -204,7 +204,7 @@ pub enum TimestampType {
InactiveRange,
}
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone)]
pub enum TimestampRangeType {
None,
DateRange,