feat(parser): clock parsing

This commit is contained in:
PoiScript 2019-04-23 18:52:52 +08:00
parent cd7e03accb
commit 69534576f1
4 changed files with 11 additions and 11 deletions

View file

@ -9,13 +9,12 @@ pub fn parse(text: &str) -> Option<(&str, Option<&str>, usize, usize, usize)> {
return None; return None;
} }
let bytes = text.as_bytes();
let mut lines = memchr_iter(b'\n', text.as_bytes()); let mut lines = memchr_iter(b'\n', text.as_bytes());
let (name, para, off) = lines let (name, para, off) = lines
.next() .next()
.map(|i| { .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)) .map(|x| (&text[8..8 + x], Some(text[8 + x..i].trim()), i + 1))
.unwrap_or((&text[8..i], None, i + 1)) .unwrap_or((&text[8..i], None, i + 1))
}) })

View file

@ -1,11 +1,6 @@
#![allow(unused_variables)] #![allow(unused_variables)]
use crate::{ use crate::{elements::*, headline::Headline, objects::*, Parser};
elements::{Key, Planning},
headline::Headline,
objects::{Cookie, Timestamp},
parser::Parser,
};
use jetscii::bytes; use jetscii::bytes;
use std::{ use std::{
convert::From, 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> { fn call(&mut self, w: &mut W, value: &str) -> Result<(), E> {
Ok(()) Ok(())
} }
fn clock(&mut self, w: &mut W) -> Result<(), E> { fn clock(&mut self, w: &mut W, clock: Clock<'_>) -> Result<(), E> {
Ok(()) Ok(())
} }
fn comment(&mut self, w: &mut W, cont: &str) -> Result<(), E> { fn comment(&mut self, w: &mut W, cont: &str) -> Result<(), E> {

View file

@ -31,7 +31,7 @@ macro_rules! handle_event {
ListItemEnd => $handler.list_end_item($writer)?, ListItemEnd => $handler.list_end_item($writer)?,
Call { value } => $handler.call($writer, value)?, Call { value } => $handler.call($writer, value)?,
Planning(p) => $handler.planning($writer, p)?, Planning(p) => $handler.planning($writer, p)?,
Clock => $handler.clock($writer)?, Clock(c) => $handler.clock($writer, c)?,
Timestamp(t) => $handler.timestamp($writer, t)?, Timestamp(t) => $handler.timestamp($writer, t)?,
Comment(c) => $handler.comment($writer, c)?, Comment(c) => $handler.comment($writer, c)?,
FixedWidth(f) => $handler.fixed_width($writer, f)?, FixedWidth(f) => $handler.fixed_width($writer, f)?,

View file

@ -86,7 +86,7 @@ pub enum Event<'a> {
value: &'a str, value: &'a str,
}, },
Clock, Clock(Clock<'a>),
Comment(&'a str), Comment(&'a str),
FixedWidth(&'a str), FixedWidth(&'a str),
@ -335,6 +335,12 @@ impl<'a> Parser<'a> {
return Some((Event::ListBeg { ordered }, 0, line_begin, text.len())); 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 // TODO: LaTeX environment
if tail.starts_with("\\begin{") {} if tail.starts_with("\\begin{") {}