chore: update to rust 2018
This commit is contained in:
parent
aa786e97c1
commit
c1154a1853
|
@ -1,10 +1,11 @@
|
|||
[package]
|
||||
name = "orgize"
|
||||
version = "0.1.1"
|
||||
version = "0.1.2"
|
||||
authors = ["PoiScript <poiscript@gmail.com>"]
|
||||
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"]
|
||||
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use lines::Lines;
|
||||
use crate::lines::Lines;
|
||||
|
||||
pub struct List;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<W: Write> {
|
||||
|
@ -85,7 +87,7 @@ impl<'a, W: Write, H: Handler<W>> 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;
|
||||
|
|
17
src/lib.rs
17
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};
|
||||
|
|
|
@ -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()))?;
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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> {
|
||||
|
|
|
@ -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)]
|
||||
|
|
Loading…
Reference in a new issue