Set up the initial code structure for the clock.

This commit is contained in:
Tom Alexander 2023-04-21 19:02:16 -04:00
parent 2d4a592846
commit c2ccf4da37
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
6 changed files with 52 additions and 0 deletions

View File

@ -1,6 +1,7 @@
use super::sexp::Token;
use super::util::assert_bounds;
use super::util::assert_name;
use crate::parser::Clock;
use crate::parser::Comment;
use crate::parser::CommentBlock;
use crate::parser::Document;
@ -213,6 +214,7 @@ fn compare_element<'s>(
Element::ExampleBlock(obj) => compare_example_block(source, emacs, obj),
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),
}
}
@ -677,3 +679,26 @@ fn compare_src_block<'s>(
children: Vec::new(),
})
}
fn compare_clock<'s>(
source: &'s str,
emacs: &'s Token<'s>,
rust: &'s Clock<'s>,
) -> Result<DiffResult, Box<dyn std::error::Error>> {
let mut this_status = DiffStatus::Good;
let emacs_name = "clock";
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/clock.rs Normal file
View File

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

View File

@ -4,6 +4,7 @@ use super::greater_element::GreaterBlock;
use super::greater_element::PlainList;
use super::greater_element::PropertyDrawer;
use super::greater_element::Table;
use super::lesser_element::Clock;
use super::lesser_element::Comment;
use super::lesser_element::CommentBlock;
use super::lesser_element::ExampleBlock;
@ -30,6 +31,7 @@ pub enum Element<'s> {
ExampleBlock(ExampleBlock<'s>),
ExportBlock(ExportBlock<'s>),
SrcBlock(SrcBlock<'s>),
Clock(Clock<'s>),
}
impl<'s> Source<'s> for Element<'s> {
@ -49,6 +51,7 @@ impl<'s> Source<'s> for Element<'s> {
Element::ExampleBlock(obj) => obj.source,
Element::ExportBlock(obj) => obj.source,
Element::SrcBlock(obj) => obj.source,
Element::Clock(obj) => obj.source,
}
}
}

View File

@ -1,3 +1,4 @@
use super::clock::clock;
use super::comment::comment;
use super::drawer::drawer;
use super::dynamic_block::dynamic_block;
@ -45,6 +46,7 @@ pub fn non_paragraph_element<'r, 's>(
let example_block_matcher = parser_with_context!(example_block)(context);
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);
alt((
map(plain_list_matcher, Element::PlainList),
map(greater_block_matcher, Element::GreaterBlock),
@ -58,5 +60,6 @@ pub fn non_paragraph_element<'r, 's>(
map(example_block_matcher, Element::ExampleBlock),
map(export_block_matcher, Element::ExportBlock),
map(src_block_matcher, Element::SrcBlock),
map(clock_matcher, Element::Clock),
))(input)
}

View File

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

View File

@ -1,3 +1,4 @@
mod clock;
mod comment;
mod document;
mod drawer;
@ -37,6 +38,7 @@ pub use greater_element::PlainListItem;
pub use greater_element::PropertyDrawer;
pub use greater_element::Table;
pub use greater_element::TableRow;
pub use lesser_element::Clock;
pub use lesser_element::Comment;
pub use lesser_element::CommentBlock;
pub use lesser_element::ExampleBlock;