diff --git a/Cargo.toml b/Cargo.toml index 1005273..1760925 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,10 +1,11 @@ [package] name = "orgize" -version = "0.1.1" +version = "0.1.2" authors = ["PoiScript "] description = "A Rust library for parsing orgmode files." repository = "https://github.com/PoiScript/orgize" readme = "README.md" +edition = "2018" license = "MIT" keywords = ["orgmode","emacs","parser"] diff --git a/README.md b/README.md index d7c665b..4f2d799 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ _Section 2_ Alternatively, you can use the built-in render. ```rust -use orgize::{HtmlHandler, Render}; +use orgize::export::{HtmlHandler, Render}; use std::io::Cursor; fn main() { diff --git a/src/elements/block.rs b/src/elements/block.rs index fa7edf4..1e75cdc 100644 --- a/src/elements/block.rs +++ b/src/elements/block.rs @@ -1,4 +1,4 @@ -use lines::Lines; +use crate::lines::Lines; use memchr::memchr2; #[cfg_attr(test, derive(PartialEq))] @@ -27,7 +27,7 @@ impl Block { let end_line = format!(r"#+END_{}", name); let mut pre_end = cont_beg; - while let Some((_, end, line)) = lines.next() { + for (_, end, line) in lines { if line.trim().eq_ignore_ascii_case(&end_line) { return Some((name, args, cont_beg, pre_end, end)); } else { diff --git a/src/elements/dyn_block.rs b/src/elements/dyn_block.rs index 5b84159..2dbed0c 100644 --- a/src/elements/dyn_block.rs +++ b/src/elements/dyn_block.rs @@ -1,4 +1,4 @@ -use lines::Lines; +use crate::lines::Lines; use memchr::memchr2; #[cfg_attr(test, derive(PartialEq))] @@ -26,7 +26,7 @@ impl DynBlock { let mut lines = Lines::new(src); let (mut pre_cont_end, _, _) = lines.next()?; - while let Some((cont_end, end, line)) = lines.next() { + for (cont_end, end, line) in lines { if line.trim().eq_ignore_ascii_case("#+END:") { return Some(( &src[8..name].trim(), diff --git a/src/elements/list.rs b/src/elements/list.rs index 77dfd83..11101fc 100644 --- a/src/elements/list.rs +++ b/src/elements/list.rs @@ -1,4 +1,4 @@ -use lines::Lines; +use crate::lines::Lines; pub struct List; diff --git a/src/export/html.rs b/src/export/html.rs index a552721..25afc71 100644 --- a/src/export/html.rs +++ b/src/export/html.rs @@ -1,9 +1,11 @@ #![allow(unused_variables)] -use elements::Key; -use export::Handler; -use headline::Headline; -use objects::{Cookie, FnRef, InlineCall, InlineSrc, Link, Macros, RadioTarget, Snippet, Target}; +use crate::elements::Key; +use crate::export::Handler; +use crate::headline::Headline; +use crate::objects::{ + Cookie, FnRef, InlineCall, InlineSrc, Link, Macros, RadioTarget, Snippet, Target, +}; use std::io::{Result, Write}; pub struct HtmlHandler; diff --git a/src/export/mod.rs b/src/export/mod.rs index 3cad105..15dbfc8 100644 --- a/src/export/mod.rs +++ b/src/export/mod.rs @@ -2,10 +2,12 @@ mod html; pub use self::html::HtmlHandler; -use elements::Key; -use headline::Headline; -use objects::{Cookie, FnRef, InlineCall, InlineSrc, Link, Macros, RadioTarget, Snippet, Target}; -use parser::Parser; +use crate::elements::Key; +use crate::headline::Headline; +use crate::objects::{ + Cookie, FnRef, InlineCall, InlineSrc, Link, Macros, RadioTarget, Snippet, Target, +}; +use crate::parser::Parser; use std::io::{Result, Write}; pub trait Handler { @@ -85,7 +87,7 @@ impl<'a, W: Write, H: Handler> Render<'a, W, H> { } pub fn render(&mut self) -> Result<()> { - use parser::Event::*; + use crate::parser::Event::*; let w = &mut self.writer; let h = &mut self.handler; diff --git a/src/lib.rs b/src/lib.rs index f1110f2..a1e21c5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,18 +1,9 @@ -#[macro_use] -extern crate jetscii; -extern crate memchr; - #[macro_use] mod utils; -mod elements; -mod export; -mod headline; +pub mod elements; +pub mod export; +pub mod headline; mod lines; -mod objects; +pub mod objects; mod parser; - -pub use elements::*; -pub use export::{HtmlHandler, Render}; -pub use objects::*; -pub use parser::{Event, Parser}; diff --git a/src/objects/cookie.rs b/src/objects/cookie.rs index fd152f5..d255845 100644 --- a/src/objects/cookie.rs +++ b/src/objects/cookie.rs @@ -8,7 +8,7 @@ pub struct Cookie<'a> { impl<'a> Cookie<'a> { pub fn parse(src: &'a str) -> Option<(Cookie<'a>, usize)> { - debug_assert!(src.starts_with("[")); + debug_assert!(src.starts_with('[')); let num1 = memchr2(b'%', b'/', src.as_bytes()) .filter(|&i| src.as_bytes()[1..i].iter().all(|c| c.is_ascii_digit()))?; diff --git a/src/objects/fn_ref.rs b/src/objects/fn_ref.rs index bdffa90..1627eea 100644 --- a/src/objects/fn_ref.rs +++ b/src/objects/fn_ref.rs @@ -7,10 +7,6 @@ pub struct FnRef<'a> { definition: Option<&'a str>, } -fn valid_label(ch: &u8) -> bool { - ch.is_ascii_alphanumeric() || *ch == b'-' || *ch == b'_' -} - impl<'a> FnRef<'a> { pub fn parse(src: &'a str) -> Option<(FnRef<'a>, usize)> { debug_assert!(src.starts_with("[fn:")); @@ -18,21 +14,24 @@ impl<'a> FnRef<'a> { let bytes = src.as_bytes(); let label = memchr2(b']', b':', &bytes[4..]) .map(|i| i + 4) - .filter(|&i| bytes[4..i].iter().all(valid_label))?; + .filter(|&i| { + bytes[4..i] + .iter() + .all(|&c| c.is_ascii_alphanumeric() || c == b'-' || c == b'_') + })?; if bytes[label] == b':' { let mut pairs = 1; let def = memchr2_iter(b'[', b']', &bytes[label..]) .map(|i| i + label) - .filter(|&i| { + .find(|&i| { if bytes[i] == b'[' { pairs += 1; } else { pairs -= 1; } pairs == 0 - }) - .next()?; + })?; Some(( FnRef { diff --git a/src/objects/mod.rs b/src/objects/mod.rs index b47c861..f96f252 100644 --- a/src/objects/mod.rs +++ b/src/objects/mod.rs @@ -17,6 +17,7 @@ pub use self::link::Link; pub use self::macros::Macros; pub use self::snippet::Snippet; pub use self::target::{RadioTarget, Target}; +use jetscii::bytes; #[cfg_attr(test, derive(PartialEq, Debug))] pub enum Object<'a> { diff --git a/src/parser.rs b/src/parser.rs index 1a011db..196ec78 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -1,6 +1,6 @@ -use elements::*; -use headline::*; -use objects::*; +use crate::elements::*; +use crate::headline::*; +use crate::objects::*; #[cfg_attr(test, derive(PartialEq))] #[derive(Copy, Clone, Debug)]