Compare todo-type on headlines.
All checks were successful
rust-test Build rust-test has succeeded
rust-build Build rust-build has succeeded

This commit is contained in:
Tom Alexander 2023-09-06 12:39:03 -04:00
parent 7c471ab32e
commit 12cbb89861
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
4 changed files with 54 additions and 11 deletions

View File

@ -60,6 +60,7 @@ use crate::types::TableCell;
use crate::types::TableRow; use crate::types::TableRow;
use crate::types::Target; use crate::types::Target;
use crate::types::Timestamp; use crate::types::Timestamp;
use crate::types::TodoKeywordType;
use crate::types::Underline; use crate::types::Underline;
use crate::types::Verbatim; use crate::types::Verbatim;
use crate::types::VerseBlock; use crate::types::VerseBlock;
@ -510,9 +511,9 @@ fn compare_heading<'s>(
.map(Token::as_atom) .map(Token::as_atom)
.map_or(Ok(None), |r| r.map(Some))? .map_or(Ok(None), |r| r.map(Some))?
.unwrap_or("nil"); .unwrap_or("nil");
match (todo_keyword, rust.todo_keyword, unquote(todo_keyword)) { match (todo_keyword, &rust.todo_keyword, unquote(todo_keyword)) {
("nil", None, _) => {} ("nil", None, _) => {}
(_, Some(rust_todo), Ok(emacs_todo)) if emacs_todo == rust_todo => {} (_, Some((_rust_todo_type, rust_todo)), Ok(emacs_todo)) if emacs_todo == *rust_todo => {}
(emacs_todo, rust_todo, _) => { (emacs_todo, rust_todo, _) => {
this_status = DiffStatus::Bad; this_status = DiffStatus::Bad;
message = Some(format!( message = Some(format!(
@ -521,6 +522,24 @@ fn compare_heading<'s>(
)); ));
} }
}; };
// Compare todo-type
let todo_type = get_property(emacs, ":todo-type")?
.map(Token::as_atom)
.map_or(Ok(None), |r| r.map(Some))?
.unwrap_or("nil");
// todo-type is an unquoted string either todo, done, or nil
match (todo_type, &rust.todo_keyword) {
("nil", None) => {}
("todo", Some((TodoKeywordType::Todo, _))) => {}
("done", Some((TodoKeywordType::Done, _))) => {}
(emacs_todo, rust_todo) => {
this_status = DiffStatus::Bad;
message = Some(format!(
"(emacs != rust) {:?} != {:?}",
emacs_todo, rust_todo
));
}
};
// Compare title // Compare title
let title = get_property(emacs, ":title")?.ok_or("Missing :title attribute.")?; let title = get_property(emacs, ":title")?.ok_or("Missing :title attribute.")?;
@ -532,7 +551,7 @@ fn compare_heading<'s>(
.collect::<Result<Vec<_>, _>>()?; .collect::<Result<Vec<_>, _>>()?;
child_status.push(artificial_diff_scope("title".to_owned(), title_status)?); child_status.push(artificial_diff_scope("title".to_owned(), title_status)?);
// TODO: Compare todo-type, priority, :footnote-section-p, :archivedp, :commentedp // TODO: Compare priority, :footnote-section-p, :archivedp, :commentedp
// Compare section // Compare section
let section_status = children let section_status = children

View File

@ -51,6 +51,7 @@ use crate::types::Element;
use crate::types::Heading; use crate::types::Heading;
use crate::types::Object; use crate::types::Object;
use crate::types::Section; use crate::types::Section;
use crate::types::TodoKeywordType;
/// Parse a full org-mode document. /// Parse a full org-mode document.
/// ///
@ -346,8 +347,9 @@ fn _heading<'b, 'g, 'r, 's>(
Heading { Heading {
source: source.into(), source: source.into(),
stars: star_count, stars: star_count,
todo_keyword: maybe_todo_keyword todo_keyword: maybe_todo_keyword.map(|((todo_keyword_type, todo_keyword), _ws)| {
.map(|(todo_keyword, _ws)| Into::<&str>::into(todo_keyword)), (todo_keyword_type, Into::<&str>::into(todo_keyword))
}),
title, title,
tags: heading_tags, tags: heading_tags,
children, children,
@ -371,7 +373,7 @@ fn headline<'b, 'g, 'r, 's>(
( (
usize, usize,
OrgSource<'s>, OrgSource<'s>,
Option<(OrgSource<'s>, OrgSource<'s>)>, Option<((TodoKeywordType, OrgSource<'s>), OrgSource<'s>)>,
Vec<Object<'s>>, Vec<Object<'s>>,
Vec<&'s str>, Vec<&'s str>,
), ),
@ -447,23 +449,38 @@ fn single_tag<'r, 's>(input: OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>>
fn heading_keyword<'b, 'g, 'r, 's>( fn heading_keyword<'b, 'g, 'r, 's>(
context: RefContext<'b, 'g, 'r, 's>, context: RefContext<'b, 'g, 'r, 's>,
input: OrgSource<'s>, input: OrgSource<'s>,
) -> Res<OrgSource<'s>, OrgSource<'s>> { ) -> Res<OrgSource<'s>, (TodoKeywordType, OrgSource<'s>)> {
let global_settings = context.get_global_settings(); let global_settings = context.get_global_settings();
if global_settings.in_progress_todo_keywords.is_empty() if global_settings.in_progress_todo_keywords.is_empty()
&& global_settings.complete_todo_keywords.is_empty() && global_settings.complete_todo_keywords.is_empty()
{ {
alt((tag("TODO"), tag("DONE")))(input) alt((
map(tag("TODO"), |capture| (TodoKeywordType::Todo, capture)),
map(tag("DONE"), |capture| (TodoKeywordType::Done, capture)),
))(input)
} else { } else {
for todo_keyword in global_settings for todo_keyword in global_settings
.in_progress_todo_keywords .in_progress_todo_keywords
.iter() .iter()
.chain(global_settings.complete_todo_keywords.iter())
.map(String::as_str) .map(String::as_str)
{ {
let result = tag::<_, _, CustomError<_>>(todo_keyword)(input); let result = tag::<_, _, CustomError<_>>(todo_keyword)(input);
match result { match result {
Ok((remaining, ent)) => { Ok((remaining, ent)) => {
return Ok((remaining, ent)); return Ok((remaining, (TodoKeywordType::Todo, ent)));
}
Err(_) => {}
}
}
for todo_keyword in global_settings
.complete_todo_keywords
.iter()
.map(String::as_str)
{
let result = tag::<_, _, CustomError<_>>(todo_keyword)(input);
match result {
Ok((remaining, ent)) => {
return Ok((remaining, (TodoKeywordType::Done, ent)));
} }
Err(_) => {} Err(_) => {}
} }

View File

@ -13,7 +13,7 @@ pub struct Document<'s> {
pub struct Heading<'s> { pub struct Heading<'s> {
pub source: &'s str, pub source: &'s str,
pub stars: usize, pub stars: usize,
pub todo_keyword: Option<&'s str>, pub todo_keyword: Option<(TodoKeywordType, &'s str)>,
// TODO: add todo-type enum // TODO: add todo-type enum
pub title: Vec<Object<'s>>, pub title: Vec<Object<'s>>,
pub tags: Vec<&'s str>, pub tags: Vec<&'s str>,
@ -32,6 +32,12 @@ pub enum DocumentElement<'s> {
Section(Section<'s>), Section(Section<'s>),
} }
#[derive(Debug)]
pub enum TodoKeywordType {
Todo,
Done,
}
impl<'s> Source<'s> for Document<'s> { impl<'s> Source<'s> for Document<'s> {
fn get_source(&'s self) -> &'s str { fn get_source(&'s self) -> &'s str {
self.source self.source

View File

@ -8,6 +8,7 @@ pub use document::Document;
pub use document::DocumentElement; pub use document::DocumentElement;
pub use document::Heading; pub use document::Heading;
pub use document::Section; pub use document::Section;
pub use document::TodoKeywordType;
pub use element::Element; pub use element::Element;
pub use greater_element::Drawer; pub use greater_element::Drawer;
pub use greater_element::DynamicBlock; pub use greater_element::DynamicBlock;