commit
604dfc3d64
7 changed files with 25 additions and 32 deletions
|
@ -8,9 +8,10 @@ license = "MIT/Apache-2.0"
|
||||||
description = "The missing YAML 1.2 parser for rust"
|
description = "The missing YAML 1.2 parser for rust"
|
||||||
repository = "https://github.com/chyh1990/yaml-rust"
|
repository = "https://github.com/chyh1990/yaml-rust"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
linked-hash-map = ">=0.0.9, <0.6"
|
linked-hash-map = ">=0.0.9, <0.6"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
quickcheck = "0.7"
|
quickcheck = "0.9"
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use std::convert::From;
|
use std::convert::From;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::fmt::{self, Display};
|
use std::fmt::{self, Display};
|
||||||
use yaml::{Hash, Yaml};
|
use crate::yaml::{Hash, Yaml};
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
pub enum EmitError {
|
pub enum EmitError {
|
||||||
|
@ -10,14 +10,7 @@ pub enum EmitError {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Error for EmitError {
|
impl Error for EmitError {
|
||||||
fn description(&self) -> &str {
|
fn cause(&self) -> Option<&dyn Error> {
|
||||||
match *self {
|
|
||||||
EmitError::FmtError(ref err) => err.description(),
|
|
||||||
EmitError::BadHashmapKey => "bad hashmap key",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn cause(&self) -> Option<&Error> {
|
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,7 +31,7 @@ impl From<fmt::Error> for EmitError {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct YamlEmitter<'a> {
|
pub struct YamlEmitter<'a> {
|
||||||
writer: &'a mut fmt::Write,
|
writer: &'a mut dyn fmt::Write,
|
||||||
best_indent: usize,
|
best_indent: usize,
|
||||||
compact: bool,
|
compact: bool,
|
||||||
|
|
||||||
|
@ -48,7 +41,7 @@ pub struct YamlEmitter<'a> {
|
||||||
pub type EmitResult = Result<(), EmitError>;
|
pub type EmitResult = Result<(), EmitError>;
|
||||||
|
|
||||||
// from serialize::json
|
// from serialize::json
|
||||||
fn escape_str(wr: &mut fmt::Write, v: &str) -> Result<(), fmt::Error> {
|
fn escape_str(wr: &mut dyn fmt::Write, v: &str) -> Result<(), fmt::Error> {
|
||||||
wr.write_str("\"")?;
|
wr.write_str("\"")?;
|
||||||
|
|
||||||
let mut start = 0;
|
let mut start = 0;
|
||||||
|
@ -111,7 +104,7 @@ fn escape_str(wr: &mut fmt::Write, v: &str) -> Result<(), fmt::Error> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> YamlEmitter<'a> {
|
impl<'a> YamlEmitter<'a> {
|
||||||
pub fn new(writer: &'a mut fmt::Write) -> YamlEmitter {
|
pub fn new(writer: &'a mut dyn fmt::Write) -> YamlEmitter {
|
||||||
YamlEmitter {
|
YamlEmitter {
|
||||||
writer,
|
writer,
|
||||||
best_indent: 2,
|
best_indent: 2,
|
||||||
|
@ -316,12 +309,12 @@ fn need_quotes(string: &str) -> bool {
|
||||||
| '\"'
|
| '\"'
|
||||||
| '\''
|
| '\''
|
||||||
| '\\'
|
| '\\'
|
||||||
| '\0'...'\x06'
|
| '\0'..='\x06'
|
||||||
| '\t'
|
| '\t'
|
||||||
| '\n'
|
| '\n'
|
||||||
| '\r'
|
| '\r'
|
||||||
| '\x0e'...'\x1a'
|
| '\x0e'..='\x1a'
|
||||||
| '\x1c'...'\x1f' => true,
|
| '\x1c'..='\x1f' => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
})
|
})
|
||||||
|| [
|
|| [
|
||||||
|
@ -344,7 +337,7 @@ fn need_quotes(string: &str) -> bool {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
use YamlLoader;
|
use crate::YamlLoader;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_emit_simple() {
|
fn test_emit_simple() {
|
||||||
|
|
|
@ -52,10 +52,10 @@ pub mod scanner;
|
||||||
pub mod yaml;
|
pub mod yaml;
|
||||||
|
|
||||||
// reexport key APIs
|
// reexport key APIs
|
||||||
pub use emitter::{EmitError, YamlEmitter};
|
pub use crate::emitter::{EmitError, YamlEmitter};
|
||||||
pub use parser::Event;
|
pub use crate::parser::Event;
|
||||||
pub use scanner::ScanError;
|
pub use crate::scanner::ScanError;
|
||||||
pub use yaml::{Yaml, YamlLoader};
|
pub use crate::yaml::{Yaml, YamlLoader};
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use scanner::*;
|
use crate::scanner::*;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
#[derive(Clone, Copy, PartialEq, Debug, Eq)]
|
#[derive(Clone, Copy, PartialEq, Debug, Eq)]
|
||||||
|
|
|
@ -67,7 +67,7 @@ impl Error for ScanError {
|
||||||
self.info.as_ref()
|
self.info.as_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cause(&self) -> Option<&Error> {
|
fn cause(&self) -> Option<&dyn Error> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -199,7 +199,7 @@ fn is_digit(c: char) -> bool {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn is_alpha(c: char) -> bool {
|
fn is_alpha(c: char) -> bool {
|
||||||
match c {
|
match c {
|
||||||
'0'...'9' | 'a'...'z' | 'A'...'Z' => true,
|
'0'..='9' | 'a'..='z' | 'A'..='Z' => true,
|
||||||
'_' | '-' => true,
|
'_' | '-' => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
|
@ -211,9 +211,9 @@ fn is_hex(c: char) -> bool {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn as_hex(c: char) -> u32 {
|
fn as_hex(c: char) -> u32 {
|
||||||
match c {
|
match c {
|
||||||
'0'...'9' => (c as u32) - ('0' as u32),
|
'0'..='9' => (c as u32) - ('0' as u32),
|
||||||
'a'...'f' => (c as u32) - ('a' as u32) + 10,
|
'a'..='f' => (c as u32) - ('a' as u32) + 10,
|
||||||
'A'...'F' => (c as u32) - ('A' as u32) + 10,
|
'A'..='F' => (c as u32) - ('A' as u32) + 10,
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use linked_hash_map::LinkedHashMap;
|
use linked_hash_map::LinkedHashMap;
|
||||||
use parser::*;
|
use crate::parser::*;
|
||||||
use scanner::{Marker, ScanError, TScalarStyle, TokenType};
|
use crate::scanner::{Marker, ScanError, TScalarStyle, TokenType};
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use std::f64;
|
use std::f64;
|
||||||
use std::i64;
|
use std::i64;
|
||||||
|
@ -368,7 +368,7 @@ impl Iterator for YamlIter {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use std::f64;
|
use std::f64;
|
||||||
use yaml::*;
|
use crate::yaml::*;
|
||||||
#[test]
|
#[test]
|
||||||
fn test_coerce() {
|
fn test_coerce() {
|
||||||
let s = "---
|
let s = "---
|
||||||
|
|
|
@ -3,7 +3,6 @@ extern crate yaml_rust;
|
||||||
extern crate quickcheck;
|
extern crate quickcheck;
|
||||||
|
|
||||||
use quickcheck::TestResult;
|
use quickcheck::TestResult;
|
||||||
use std::error::Error;
|
|
||||||
use yaml_rust::{Yaml, YamlEmitter, YamlLoader};
|
use yaml_rust::{Yaml, YamlEmitter, YamlLoader};
|
||||||
|
|
||||||
quickcheck! {
|
quickcheck! {
|
||||||
|
@ -16,7 +15,7 @@ quickcheck! {
|
||||||
}
|
}
|
||||||
match YamlLoader::load_from_str(&out_str) {
|
match YamlLoader::load_from_str(&out_str) {
|
||||||
Ok(output) => TestResult::from_bool(output.len() == 1 && input == output[0]),
|
Ok(output) => TestResult::from_bool(output.len() == 1 && input == output[0]),
|
||||||
Err(err) => TestResult::error(err.description()),
|
Err(err) => TestResult::error(err.to_string()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue