Add the code structure for diary sexp.

This commit is contained in:
Tom Alexander 2023-04-21 20:22:31 -04:00
parent 48b5a9d67a
commit db78faa36f
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
6 changed files with 52 additions and 0 deletions

View File

@ -4,6 +4,7 @@ use super::util::assert_name;
use crate::parser::Clock;
use crate::parser::Comment;
use crate::parser::CommentBlock;
use crate::parser::DiarySexp;
use crate::parser::Document;
use crate::parser::DocumentElement;
use crate::parser::Drawer;
@ -215,6 +216,7 @@ fn compare_element<'s>(
Element::ExportBlock(obj) => compare_export_block(source, emacs, obj),
Element::SrcBlock(obj) => compare_src_block(source, emacs, obj),
Element::Clock(obj) => compare_clock(source, emacs, obj),
Element::DiarySexp(obj) => compare_diary_sexp(source, emacs, obj),
}
}
@ -702,3 +704,26 @@ fn compare_clock<'s>(
children: Vec::new(),
})
}
fn compare_diary_sexp<'s>(
source: &'s str,
emacs: &'s Token<'s>,
rust: &'s DiarySexp<'s>,
) -> Result<DiffResult, Box<dyn std::error::Error>> {
let mut this_status = DiffStatus::Good;
let emacs_name = "diary-sexp";
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(),
})
}

8
src/parser/diary_sexp.rs Normal file
View File

@ -0,0 +1,8 @@
use super::Context;
use crate::error::Res;
use crate::parser::DiarySexp;
#[tracing::instrument(ret, level = "debug")]
pub fn diary_sexp<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, DiarySexp<'s>> {
todo!()
}

View File

@ -7,6 +7,7 @@ use super::greater_element::Table;
use super::lesser_element::Clock;
use super::lesser_element::Comment;
use super::lesser_element::CommentBlock;
use super::lesser_element::DiarySexp;
use super::lesser_element::ExampleBlock;
use super::lesser_element::ExportBlock;
use super::lesser_element::Paragraph;
@ -32,6 +33,7 @@ pub enum Element<'s> {
ExportBlock(ExportBlock<'s>),
SrcBlock(SrcBlock<'s>),
Clock(Clock<'s>),
DiarySexp(DiarySexp<'s>),
}
impl<'s> Source<'s> for Element<'s> {
@ -52,6 +54,7 @@ impl<'s> Source<'s> for Element<'s> {
Element::ExportBlock(obj) => obj.source,
Element::SrcBlock(obj) => obj.source,
Element::Clock(obj) => obj.source,
Element::DiarySexp(obj) => obj.source,
}
}
}

View File

@ -1,5 +1,6 @@
use super::clock::clock;
use super::comment::comment;
use super::diary_sexp::diary_sexp;
use super::drawer::drawer;
use super::dynamic_block::dynamic_block;
use super::element::Element;
@ -47,6 +48,7 @@ pub fn non_paragraph_element<'r, 's>(
let export_block_matcher = parser_with_context!(export_block)(context);
let src_block_matcher = parser_with_context!(src_block)(context);
let clock_matcher = parser_with_context!(clock)(context);
let diary_sexp_matcher = parser_with_context!(diary_sexp)(context);
alt((
map(plain_list_matcher, Element::PlainList),
map(greater_block_matcher, Element::GreaterBlock),
@ -61,5 +63,6 @@ pub fn non_paragraph_element<'r, 's>(
map(export_block_matcher, Element::ExportBlock),
map(src_block_matcher, Element::SrcBlock),
map(clock_matcher, Element::Clock),
map(diary_sexp_matcher, Element::DiarySexp),
))(input)
}

View File

@ -64,6 +64,11 @@ pub struct Clock<'s> {
pub source: &'s str,
}
#[derive(Debug)]
pub struct DiarySexp<'s> {
pub source: &'s str,
}
impl<'s> Paragraph<'s> {
pub fn of_text(input: &'s str) -> Self {
let mut objects = Vec::with_capacity(1);
@ -124,3 +129,9 @@ impl<'s> Source<'s> for Clock<'s> {
self.source
}
}
impl<'s> Source<'s> for DiarySexp<'s> {
fn get_source(&'s self) -> &'s str {
self.source
}
}

View File

@ -1,5 +1,6 @@
mod clock;
mod comment;
mod diary_sexp;
mod document;
mod drawer;
mod dynamic_block;
@ -41,6 +42,7 @@ pub use greater_element::TableRow;
pub use lesser_element::Clock;
pub use lesser_element::Comment;
pub use lesser_element::CommentBlock;
pub use lesser_element::DiarySexp;
pub use lesser_element::ExampleBlock;
pub use lesser_element::ExportBlock;
pub use lesser_element::Paragraph;