Merge branch 'clock'
This commit is contained in:
commit
48b5a9d67a
6
org_mode_samples/clock/simple.org
Normal file
6
org_mode_samples/clock/simple.org
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
* foo
|
||||||
|
:LOGBOOK:
|
||||||
|
CLOCK: [2023-04-21 Fri 19:43]
|
||||||
|
CLOCK: [2023-04-21 Fri 19:32]--[2023-04-21 Fri 19:35] => 0:03
|
||||||
|
CLOCK: [2023-04-21 Fri 19:22]--[2023-04-21 Fri 19:28] => 0:06
|
||||||
|
:END:
|
@ -1,6 +1,7 @@
|
|||||||
use super::sexp::Token;
|
use super::sexp::Token;
|
||||||
use super::util::assert_bounds;
|
use super::util::assert_bounds;
|
||||||
use super::util::assert_name;
|
use super::util::assert_name;
|
||||||
|
use crate::parser::Clock;
|
||||||
use crate::parser::Comment;
|
use crate::parser::Comment;
|
||||||
use crate::parser::CommentBlock;
|
use crate::parser::CommentBlock;
|
||||||
use crate::parser::Document;
|
use crate::parser::Document;
|
||||||
@ -213,6 +214,7 @@ fn compare_element<'s>(
|
|||||||
Element::ExampleBlock(obj) => compare_example_block(source, emacs, obj),
|
Element::ExampleBlock(obj) => compare_example_block(source, emacs, obj),
|
||||||
Element::ExportBlock(obj) => compare_export_block(source, emacs, obj),
|
Element::ExportBlock(obj) => compare_export_block(source, emacs, obj),
|
||||||
Element::SrcBlock(obj) => compare_src_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(),
|
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(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
72
src/parser/clock.rs
Normal file
72
src/parser/clock.rs
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
use nom::branch::alt;
|
||||||
|
use nom::bytes::complete::is_not;
|
||||||
|
use nom::bytes::complete::tag;
|
||||||
|
use nom::bytes::complete::tag_no_case;
|
||||||
|
use nom::character::complete::digit1;
|
||||||
|
use nom::character::complete::line_ending;
|
||||||
|
use nom::character::complete::space0;
|
||||||
|
use nom::character::complete::space1;
|
||||||
|
use nom::combinator::eof;
|
||||||
|
use nom::combinator::recognize;
|
||||||
|
use nom::combinator::verify;
|
||||||
|
use nom::sequence::tuple;
|
||||||
|
|
||||||
|
use super::Context;
|
||||||
|
use crate::error::Res;
|
||||||
|
use crate::parser::parser_with_context::parser_with_context;
|
||||||
|
use crate::parser::util::get_consumed;
|
||||||
|
use crate::parser::util::maybe_consume_trailing_whitespace_if_not_exiting;
|
||||||
|
use crate::parser::util::start_of_line;
|
||||||
|
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>> {
|
||||||
|
start_of_line(context, input)?;
|
||||||
|
let (remaining, _leading_whitespace) = space0(input)?;
|
||||||
|
let (remaining, _clock) = tag_no_case("clock:")(remaining)?;
|
||||||
|
let (remaining, _gap_whitespace) = space1(remaining)?;
|
||||||
|
|
||||||
|
let (remaining, _timestamp_junk) = alt((
|
||||||
|
parser_with_context!(inactive_timestamp_range_duration)(context),
|
||||||
|
parser_with_context!(inactive_timestamp)(context),
|
||||||
|
))(remaining)?;
|
||||||
|
|
||||||
|
let (remaining, _trailing_ws) =
|
||||||
|
maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?;
|
||||||
|
|
||||||
|
let source = get_consumed(input, remaining);
|
||||||
|
Ok((remaining, Clock { source }))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(ret, level = "debug")]
|
||||||
|
fn inactive_timestamp_range_duration<'r, 's>(
|
||||||
|
context: Context<'r, 's>,
|
||||||
|
input: &'s str,
|
||||||
|
) -> Res<&'s str, &'s str> {
|
||||||
|
recognize(tuple((
|
||||||
|
tag("["),
|
||||||
|
is_not("\r\n]"),
|
||||||
|
tag("]--["),
|
||||||
|
is_not("\r\n]"),
|
||||||
|
tag("]"),
|
||||||
|
space1,
|
||||||
|
tag("=>"),
|
||||||
|
space1,
|
||||||
|
digit1,
|
||||||
|
tag(":"),
|
||||||
|
verify(digit1, |mm: &str| mm.len() == 2),
|
||||||
|
space0,
|
||||||
|
alt((line_ending, eof)),
|
||||||
|
)))(input)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(ret, level = "debug")]
|
||||||
|
fn inactive_timestamp<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s str> {
|
||||||
|
recognize(tuple((
|
||||||
|
tag("["),
|
||||||
|
is_not("\r\n]"),
|
||||||
|
tag("]"),
|
||||||
|
space0,
|
||||||
|
alt((line_ending, eof)),
|
||||||
|
)))(input)
|
||||||
|
}
|
@ -4,6 +4,7 @@ use super::greater_element::GreaterBlock;
|
|||||||
use super::greater_element::PlainList;
|
use super::greater_element::PlainList;
|
||||||
use super::greater_element::PropertyDrawer;
|
use super::greater_element::PropertyDrawer;
|
||||||
use super::greater_element::Table;
|
use super::greater_element::Table;
|
||||||
|
use super::lesser_element::Clock;
|
||||||
use super::lesser_element::Comment;
|
use super::lesser_element::Comment;
|
||||||
use super::lesser_element::CommentBlock;
|
use super::lesser_element::CommentBlock;
|
||||||
use super::lesser_element::ExampleBlock;
|
use super::lesser_element::ExampleBlock;
|
||||||
@ -30,6 +31,7 @@ pub enum Element<'s> {
|
|||||||
ExampleBlock(ExampleBlock<'s>),
|
ExampleBlock(ExampleBlock<'s>),
|
||||||
ExportBlock(ExportBlock<'s>),
|
ExportBlock(ExportBlock<'s>),
|
||||||
SrcBlock(SrcBlock<'s>),
|
SrcBlock(SrcBlock<'s>),
|
||||||
|
Clock(Clock<'s>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'s> Source<'s> for Element<'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::ExampleBlock(obj) => obj.source,
|
||||||
Element::ExportBlock(obj) => obj.source,
|
Element::ExportBlock(obj) => obj.source,
|
||||||
Element::SrcBlock(obj) => obj.source,
|
Element::SrcBlock(obj) => obj.source,
|
||||||
|
Element::Clock(obj) => obj.source,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
use super::clock::clock;
|
||||||
use super::comment::comment;
|
use super::comment::comment;
|
||||||
use super::drawer::drawer;
|
use super::drawer::drawer;
|
||||||
use super::dynamic_block::dynamic_block;
|
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 example_block_matcher = parser_with_context!(example_block)(context);
|
||||||
let export_block_matcher = parser_with_context!(export_block)(context);
|
let export_block_matcher = parser_with_context!(export_block)(context);
|
||||||
let src_block_matcher = parser_with_context!(src_block)(context);
|
let src_block_matcher = parser_with_context!(src_block)(context);
|
||||||
|
let clock_matcher = parser_with_context!(clock)(context);
|
||||||
alt((
|
alt((
|
||||||
map(plain_list_matcher, Element::PlainList),
|
map(plain_list_matcher, Element::PlainList),
|
||||||
map(greater_block_matcher, Element::GreaterBlock),
|
map(greater_block_matcher, Element::GreaterBlock),
|
||||||
@ -58,5 +60,6 @@ pub fn non_paragraph_element<'r, 's>(
|
|||||||
map(example_block_matcher, Element::ExampleBlock),
|
map(example_block_matcher, Element::ExampleBlock),
|
||||||
map(export_block_matcher, Element::ExportBlock),
|
map(export_block_matcher, Element::ExportBlock),
|
||||||
map(src_block_matcher, Element::SrcBlock),
|
map(src_block_matcher, Element::SrcBlock),
|
||||||
|
map(clock_matcher, Element::Clock),
|
||||||
))(input)
|
))(input)
|
||||||
}
|
}
|
||||||
|
@ -59,6 +59,11 @@ pub struct SrcBlock<'s> {
|
|||||||
pub contents: &'s str,
|
pub contents: &'s str,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct Clock<'s> {
|
||||||
|
pub source: &'s str,
|
||||||
|
}
|
||||||
|
|
||||||
impl<'s> Paragraph<'s> {
|
impl<'s> Paragraph<'s> {
|
||||||
pub fn of_text(input: &'s str) -> Self {
|
pub fn of_text(input: &'s str) -> Self {
|
||||||
let mut objects = Vec::with_capacity(1);
|
let mut objects = Vec::with_capacity(1);
|
||||||
@ -113,3 +118,9 @@ impl<'s> Source<'s> for SrcBlock<'s> {
|
|||||||
self.source
|
self.source
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'s> Source<'s> for Clock<'s> {
|
||||||
|
fn get_source(&'s self) -> &'s str {
|
||||||
|
self.source
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
mod clock;
|
||||||
mod comment;
|
mod comment;
|
||||||
mod document;
|
mod document;
|
||||||
mod drawer;
|
mod drawer;
|
||||||
@ -37,6 +38,7 @@ pub use greater_element::PlainListItem;
|
|||||||
pub use greater_element::PropertyDrawer;
|
pub use greater_element::PropertyDrawer;
|
||||||
pub use greater_element::Table;
|
pub use greater_element::Table;
|
||||||
pub use greater_element::TableRow;
|
pub use greater_element::TableRow;
|
||||||
|
pub use lesser_element::Clock;
|
||||||
pub use lesser_element::Comment;
|
pub use lesser_element::Comment;
|
||||||
pub use lesser_element::CommentBlock;
|
pub use lesser_element::CommentBlock;
|
||||||
pub use lesser_element::ExampleBlock;
|
pub use lesser_element::ExampleBlock;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user