chore: update to rust 2018
This commit is contained in:
parent
aa786e97c1
commit
c1154a1853
|
@ -1,10 +1,11 @@
|
||||||
[package]
|
[package]
|
||||||
name = "orgize"
|
name = "orgize"
|
||||||
version = "0.1.1"
|
version = "0.1.2"
|
||||||
authors = ["PoiScript <poiscript@gmail.com>"]
|
authors = ["PoiScript <poiscript@gmail.com>"]
|
||||||
description = "A Rust library for parsing orgmode files."
|
description = "A Rust library for parsing orgmode files."
|
||||||
repository = "https://github.com/PoiScript/orgize"
|
repository = "https://github.com/PoiScript/orgize"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
edition = "2018"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
keywords = ["orgmode","emacs","parser"]
|
keywords = ["orgmode","emacs","parser"]
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ _Section 2_
|
||||||
Alternatively, you can use the built-in render.
|
Alternatively, you can use the built-in render.
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
use orgize::{HtmlHandler, Render};
|
use orgize::export::{HtmlHandler, Render};
|
||||||
use std::io::Cursor;
|
use std::io::Cursor;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use lines::Lines;
|
use crate::lines::Lines;
|
||||||
use memchr::memchr2;
|
use memchr::memchr2;
|
||||||
|
|
||||||
#[cfg_attr(test, derive(PartialEq))]
|
#[cfg_attr(test, derive(PartialEq))]
|
||||||
|
@ -27,7 +27,7 @@ impl Block {
|
||||||
let end_line = format!(r"#+END_{}", name);
|
let end_line = format!(r"#+END_{}", name);
|
||||||
let mut pre_end = cont_beg;
|
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) {
|
if line.trim().eq_ignore_ascii_case(&end_line) {
|
||||||
return Some((name, args, cont_beg, pre_end, end));
|
return Some((name, args, cont_beg, pre_end, end));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use lines::Lines;
|
use crate::lines::Lines;
|
||||||
use memchr::memchr2;
|
use memchr::memchr2;
|
||||||
|
|
||||||
#[cfg_attr(test, derive(PartialEq))]
|
#[cfg_attr(test, derive(PartialEq))]
|
||||||
|
@ -26,7 +26,7 @@ impl DynBlock {
|
||||||
let mut lines = Lines::new(src);
|
let mut lines = Lines::new(src);
|
||||||
let (mut pre_cont_end, _, _) = lines.next()?;
|
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:") {
|
if line.trim().eq_ignore_ascii_case("#+END:") {
|
||||||
return Some((
|
return Some((
|
||||||
&src[8..name].trim(),
|
&src[8..name].trim(),
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use lines::Lines;
|
use crate::lines::Lines;
|
||||||
|
|
||||||
pub struct List;
|
pub struct List;
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
#![allow(unused_variables)]
|
#![allow(unused_variables)]
|
||||||
|
|
||||||
use elements::Key;
|
use crate::elements::Key;
|
||||||
use export::Handler;
|
use crate::export::Handler;
|
||||||
use headline::Headline;
|
use crate::headline::Headline;
|
||||||
use objects::{Cookie, FnRef, InlineCall, InlineSrc, Link, Macros, RadioTarget, Snippet, Target};
|
use crate::objects::{
|
||||||
|
Cookie, FnRef, InlineCall, InlineSrc, Link, Macros, RadioTarget, Snippet, Target,
|
||||||
|
};
|
||||||
use std::io::{Result, Write};
|
use std::io::{Result, Write};
|
||||||
|
|
||||||
pub struct HtmlHandler;
|
pub struct HtmlHandler;
|
||||||
|
|
|
@ -2,10 +2,12 @@ mod html;
|
||||||
|
|
||||||
pub use self::html::HtmlHandler;
|
pub use self::html::HtmlHandler;
|
||||||
|
|
||||||
use elements::Key;
|
use crate::elements::Key;
|
||||||
use headline::Headline;
|
use crate::headline::Headline;
|
||||||
use objects::{Cookie, FnRef, InlineCall, InlineSrc, Link, Macros, RadioTarget, Snippet, Target};
|
use crate::objects::{
|
||||||
use parser::Parser;
|
Cookie, FnRef, InlineCall, InlineSrc, Link, Macros, RadioTarget, Snippet, Target,
|
||||||
|
};
|
||||||
|
use crate::parser::Parser;
|
||||||
use std::io::{Result, Write};
|
use std::io::{Result, Write};
|
||||||
|
|
||||||
pub trait Handler<W: 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<()> {
|
pub fn render(&mut self) -> Result<()> {
|
||||||
use parser::Event::*;
|
use crate::parser::Event::*;
|
||||||
|
|
||||||
let w = &mut self.writer;
|
let w = &mut self.writer;
|
||||||
let h = &mut self.handler;
|
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]
|
#[macro_use]
|
||||||
mod utils;
|
mod utils;
|
||||||
|
|
||||||
mod elements;
|
pub mod elements;
|
||||||
mod export;
|
pub mod export;
|
||||||
mod headline;
|
pub mod headline;
|
||||||
mod lines;
|
mod lines;
|
||||||
mod objects;
|
pub mod objects;
|
||||||
mod parser;
|
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> {
|
impl<'a> Cookie<'a> {
|
||||||
pub fn parse(src: &'a str) -> Option<(Cookie<'a>, usize)> {
|
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())
|
let num1 = memchr2(b'%', b'/', src.as_bytes())
|
||||||
.filter(|&i| src.as_bytes()[1..i].iter().all(|c| c.is_ascii_digit()))?;
|
.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>,
|
definition: Option<&'a str>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn valid_label(ch: &u8) -> bool {
|
|
||||||
ch.is_ascii_alphanumeric() || *ch == b'-' || *ch == b'_'
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> FnRef<'a> {
|
impl<'a> FnRef<'a> {
|
||||||
pub fn parse(src: &'a str) -> Option<(FnRef<'a>, usize)> {
|
pub fn parse(src: &'a str) -> Option<(FnRef<'a>, usize)> {
|
||||||
debug_assert!(src.starts_with("[fn:"));
|
debug_assert!(src.starts_with("[fn:"));
|
||||||
|
@ -18,21 +14,24 @@ impl<'a> FnRef<'a> {
|
||||||
let bytes = src.as_bytes();
|
let bytes = src.as_bytes();
|
||||||
let label = memchr2(b']', b':', &bytes[4..])
|
let label = memchr2(b']', b':', &bytes[4..])
|
||||||
.map(|i| i + 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':' {
|
if bytes[label] == b':' {
|
||||||
let mut pairs = 1;
|
let mut pairs = 1;
|
||||||
let def = memchr2_iter(b'[', b']', &bytes[label..])
|
let def = memchr2_iter(b'[', b']', &bytes[label..])
|
||||||
.map(|i| i + label)
|
.map(|i| i + label)
|
||||||
.filter(|&i| {
|
.find(|&i| {
|
||||||
if bytes[i] == b'[' {
|
if bytes[i] == b'[' {
|
||||||
pairs += 1;
|
pairs += 1;
|
||||||
} else {
|
} else {
|
||||||
pairs -= 1;
|
pairs -= 1;
|
||||||
}
|
}
|
||||||
pairs == 0
|
pairs == 0
|
||||||
})
|
})?;
|
||||||
.next()?;
|
|
||||||
|
|
||||||
Some((
|
Some((
|
||||||
FnRef {
|
FnRef {
|
||||||
|
|
|
@ -17,6 +17,7 @@ pub use self::link::Link;
|
||||||
pub use self::macros::Macros;
|
pub use self::macros::Macros;
|
||||||
pub use self::snippet::Snippet;
|
pub use self::snippet::Snippet;
|
||||||
pub use self::target::{RadioTarget, Target};
|
pub use self::target::{RadioTarget, Target};
|
||||||
|
use jetscii::bytes;
|
||||||
|
|
||||||
#[cfg_attr(test, derive(PartialEq, Debug))]
|
#[cfg_attr(test, derive(PartialEq, Debug))]
|
||||||
pub enum Object<'a> {
|
pub enum Object<'a> {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use elements::*;
|
use crate::elements::*;
|
||||||
use headline::*;
|
use crate::headline::*;
|
||||||
use objects::*;
|
use crate::objects::*;
|
||||||
|
|
||||||
#[cfg_attr(test, derive(PartialEq))]
|
#[cfg_attr(test, derive(PartialEq))]
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
|
|
Loading…
Reference in a new issue