feat(parser): clock parsing
This commit is contained in:
parent
cd7e03accb
commit
69534576f1
|
@ -9,13 +9,12 @@ pub fn parse(text: &str) -> Option<(&str, Option<&str>, usize, usize, usize)> {
|
|||
return None;
|
||||
}
|
||||
|
||||
let bytes = text.as_bytes();
|
||||
let mut lines = memchr_iter(b'\n', text.as_bytes());
|
||||
|
||||
let (name, para, off) = lines
|
||||
.next()
|
||||
.map(|i| {
|
||||
memchr(b' ', &bytes[8..i])
|
||||
memchr(b' ', &text.as_bytes()[8..i])
|
||||
.map(|x| (&text[8..8 + x], Some(text[8 + x..i].trim()), i + 1))
|
||||
.unwrap_or((&text[8..i], None, i + 1))
|
||||
})
|
||||
|
|
|
@ -1,11 +1,6 @@
|
|||
#![allow(unused_variables)]
|
||||
|
||||
use crate::{
|
||||
elements::{Key, Planning},
|
||||
headline::Headline,
|
||||
objects::{Cookie, Timestamp},
|
||||
parser::Parser,
|
||||
};
|
||||
use crate::{elements::*, headline::Headline, objects::*, Parser};
|
||||
use jetscii::bytes;
|
||||
use std::{
|
||||
convert::From,
|
||||
|
@ -130,7 +125,7 @@ pub trait HtmlHandler<W: Write, E: From<Error>> {
|
|||
fn call(&mut self, w: &mut W, value: &str) -> Result<(), E> {
|
||||
Ok(())
|
||||
}
|
||||
fn clock(&mut self, w: &mut W) -> Result<(), E> {
|
||||
fn clock(&mut self, w: &mut W, clock: Clock<'_>) -> Result<(), E> {
|
||||
Ok(())
|
||||
}
|
||||
fn comment(&mut self, w: &mut W, cont: &str) -> Result<(), E> {
|
||||
|
|
|
@ -31,7 +31,7 @@ macro_rules! handle_event {
|
|||
ListItemEnd => $handler.list_end_item($writer)?,
|
||||
Call { value } => $handler.call($writer, value)?,
|
||||
Planning(p) => $handler.planning($writer, p)?,
|
||||
Clock => $handler.clock($writer)?,
|
||||
Clock(c) => $handler.clock($writer, c)?,
|
||||
Timestamp(t) => $handler.timestamp($writer, t)?,
|
||||
Comment(c) => $handler.comment($writer, c)?,
|
||||
FixedWidth(f) => $handler.fixed_width($writer, f)?,
|
||||
|
|
|
@ -86,7 +86,7 @@ pub enum Event<'a> {
|
|||
value: &'a str,
|
||||
},
|
||||
|
||||
Clock,
|
||||
Clock(Clock<'a>),
|
||||
|
||||
Comment(&'a str),
|
||||
FixedWidth(&'a str),
|
||||
|
@ -335,6 +335,12 @@ impl<'a> Parser<'a> {
|
|||
return Some((Event::ListBeg { ordered }, 0, line_begin, text.len()));
|
||||
}
|
||||
|
||||
if tail.starts_with("CLOCK:") {
|
||||
if let Some((clock, off)) = Clock::parse(tail) {
|
||||
return Some((Event::Clock(clock), off + line_begin, 0, 0));
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: LaTeX environment
|
||||
if tail.starts_with("\\begin{") {}
|
||||
|
||||
|
|
Loading…
Reference in a new issue