remove trailing space
This commit is contained in:
parent
6e8a78b965
commit
87539f852d
5 changed files with 24 additions and 31 deletions
|
@ -29,14 +29,13 @@
|
||||||
//! let docs = YamlLoader::load_from_str("[1, 2, 3]").unwrap();
|
//! let docs = YamlLoader::load_from_str("[1, 2, 3]").unwrap();
|
||||||
//! let doc = &docs[0]; // select the first document
|
//! let doc = &docs[0]; // select the first document
|
||||||
//! assert_eq!(doc[0].as_i64().unwrap(), 1); // access elements by index
|
//! assert_eq!(doc[0].as_i64().unwrap(), 1); // access elements by index
|
||||||
//!
|
//!
|
||||||
//! let mut out_str = String::new();
|
//! let mut out_str = String::new();
|
||||||
//! let mut emitter = YamlEmitter::new(&mut out_str);
|
//! let mut emitter = YamlEmitter::new(&mut out_str);
|
||||||
//! emitter.dump(doc).unwrap(); // dump the YAML object to a String
|
//! emitter.dump(doc).unwrap(); // dump the YAML object to a String
|
||||||
//!
|
//!
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
|
|
||||||
pub mod yaml;
|
pub mod yaml;
|
||||||
pub mod scanner;
|
pub mod scanner;
|
||||||
pub mod parser;
|
pub mod parser;
|
||||||
|
|
|
@ -102,7 +102,7 @@ impl<T: Iterator<Item=char>> Parser<T> {
|
||||||
if self.token.is_none() {
|
if self.token.is_none() {
|
||||||
match self.scanner.get_error() {
|
match self.scanner.get_error() {
|
||||||
None =>
|
None =>
|
||||||
return Err(ScanError::new(self.scanner.mark(),
|
return Err(ScanError::new(self.scanner.mark(),
|
||||||
"unexpected eof")),
|
"unexpected eof")),
|
||||||
Some(e) => return Err(e),
|
Some(e) => return Err(e),
|
||||||
}
|
}
|
||||||
|
@ -179,7 +179,7 @@ impl<T: Iterator<Item=char>> Parser<T> {
|
||||||
fn load_node<R: EventReceiver>(&mut self, first_ev: &Event, recv: &mut R)
|
fn load_node<R: EventReceiver>(&mut self, first_ev: &Event, recv: &mut R)
|
||||||
-> Result<(), ScanError> {
|
-> Result<(), ScanError> {
|
||||||
match *first_ev {
|
match *first_ev {
|
||||||
Event::Alias(..) => {
|
Event::Alias(..) => {
|
||||||
Ok(())
|
Ok(())
|
||||||
},
|
},
|
||||||
Event::Scalar(..) => {
|
Event::Scalar(..) => {
|
||||||
|
@ -600,7 +600,7 @@ impl<T: Iterator<Item=char>> Parser<T> {
|
||||||
self.skip();
|
self.skip();
|
||||||
let tok = try!(self.peek());
|
let tok = try!(self.peek());
|
||||||
match tok.1 {
|
match tok.1 {
|
||||||
TokenType::FlowEntryToken
|
TokenType::FlowEntryToken
|
||||||
| TokenType::FlowMappingEndToken => { },
|
| TokenType::FlowMappingEndToken => { },
|
||||||
_ => {
|
_ => {
|
||||||
self.push_state(State::FlowMappingKey);
|
self.push_state(State::FlowMappingKey);
|
||||||
|
@ -765,4 +765,3 @@ impl<T: Iterator<Item=char>> Parser<T> {
|
||||||
Ok(Event::MappingEnd)
|
Ok(Event::MappingEnd)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,7 @@ impl Error for ScanError {
|
||||||
|
|
||||||
impl fmt::Display for ScanError {
|
impl fmt::Display for ScanError {
|
||||||
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||||
self.info.fmt(formatter)
|
self.info.fmt(formatter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -590,12 +590,12 @@ impl<T: Iterator<Item=char>> Scanner<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if string.is_empty() {
|
if string.is_empty() {
|
||||||
return Err(ScanError::new(start_mark,
|
return Err(ScanError::new(start_mark,
|
||||||
"while scanning a directive, could not find expected directive name"));
|
"while scanning a directive, could not find expected directive name"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if !is_blankz(self.ch()) {
|
if !is_blankz(self.ch()) {
|
||||||
return Err(ScanError::new(start_mark,
|
return Err(ScanError::new(start_mark,
|
||||||
"while scanning a directive, found unexpected non-alphabetical character"));
|
"while scanning a directive, found unexpected non-alphabetical character"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -685,7 +685,7 @@ impl<T: Iterator<Item=char>> Scanner<T> {
|
||||||
|
|
||||||
self.skip();
|
self.skip();
|
||||||
} else {
|
} else {
|
||||||
// The tag has either the '!suffix' or the '!handle!suffix'
|
// The tag has either the '!suffix' or the '!handle!suffix'
|
||||||
handle = try!(self.scan_tag_handle(false, &start_mark));
|
handle = try!(self.scan_tag_handle(false, &start_mark));
|
||||||
// Check if it is, indeed, handle.
|
// Check if it is, indeed, handle.
|
||||||
if handle.len() >= 2 && handle.starts_with('!') && handle.ends_with('!') {
|
if handle.len() >= 2 && handle.starts_with('!') && handle.ends_with('!') {
|
||||||
|
@ -802,7 +802,7 @@ impl<T: Iterator<Item=char>> Scanner<T> {
|
||||||
loop {
|
loop {
|
||||||
self.lookahead(3);
|
self.lookahead(3);
|
||||||
|
|
||||||
if !(self.ch() == '%'
|
if !(self.ch() == '%'
|
||||||
&& is_hex(self.buffer[1])
|
&& is_hex(self.buffer[1])
|
||||||
&& is_hex(self.buffer[2])) {
|
&& is_hex(self.buffer[2])) {
|
||||||
return Err(ScanError::new(*mark,
|
return Err(ScanError::new(*mark,
|
||||||
|
@ -961,7 +961,7 @@ impl<T: Iterator<Item=char>> Scanner<T> {
|
||||||
self.tokens.push_back(Token(start_mark, TokenType::BlockEntryToken));
|
self.tokens.push_back(Token(start_mark, TokenType::BlockEntryToken));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fetch_document_indicator(&mut self, t: TokenType) -> ScanResult {
|
fn fetch_document_indicator(&mut self, t: TokenType) -> ScanResult {
|
||||||
self.unroll_indent(-1);
|
self.unroll_indent(-1);
|
||||||
try!(self.remove_simple_key());
|
try!(self.remove_simple_key());
|
||||||
|
@ -1068,7 +1068,7 @@ impl<T: Iterator<Item=char>> Scanner<T> {
|
||||||
}
|
}
|
||||||
// Scan the leading line breaks and determine the indentation level if needed.
|
// Scan the leading line breaks and determine the indentation level if needed.
|
||||||
try!(self.block_scalar_breaks(&mut indent, &mut trailing_breaks));
|
try!(self.block_scalar_breaks(&mut indent, &mut trailing_breaks));
|
||||||
|
|
||||||
self.lookahead(1);
|
self.lookahead(1);
|
||||||
|
|
||||||
let start_mark = self.mark;
|
let start_mark = self.mark;
|
||||||
|
@ -1138,7 +1138,7 @@ impl<T: Iterator<Item=char>> Scanner<T> {
|
||||||
// Check for a tab character messing the intendation.
|
// Check for a tab character messing the intendation.
|
||||||
if (*indent == 0 || self.mark.col < *indent)
|
if (*indent == 0 || self.mark.col < *indent)
|
||||||
&& self.buffer[0] == '\t' {
|
&& self.buffer[0] == '\t' {
|
||||||
return Err(ScanError::new(self.mark,
|
return Err(ScanError::new(self.mark,
|
||||||
"while scanning a block scalar, found a tab character where an intendation space is expected"));
|
"while scanning a block scalar, found a tab character where an intendation space is expected"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1197,12 +1197,12 @@ impl<T: Iterator<Item=char>> Scanner<T> {
|
||||||
(self.buffer[1] == '.') &&
|
(self.buffer[1] == '.') &&
|
||||||
(self.buffer[2] == '.')) &&
|
(self.buffer[2] == '.')) &&
|
||||||
is_blankz(self.buffer[3]) {
|
is_blankz(self.buffer[3]) {
|
||||||
return Err(ScanError::new(start_mark,
|
return Err(ScanError::new(start_mark,
|
||||||
"while scanning a quoted scalar, found unexpected document indicator"));
|
"while scanning a quoted scalar, found unexpected document indicator"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if is_z(self.ch()) {
|
if is_z(self.ch()) {
|
||||||
return Err(ScanError::new(start_mark,
|
return Err(ScanError::new(start_mark,
|
||||||
"while scanning a quoted scalar, found unexpected end of stream"));
|
"while scanning a quoted scalar, found unexpected end of stream"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1507,7 +1507,7 @@ impl<T: Iterator<Item=char>> Scanner<T> {
|
||||||
// insert simple key
|
// insert simple key
|
||||||
let tok = Token(sk.mark, TokenType::KeyToken);
|
let tok = Token(sk.mark, TokenType::KeyToken);
|
||||||
let tokens_parsed = self.tokens_parsed;
|
let tokens_parsed = self.tokens_parsed;
|
||||||
self.insert_token(sk.token_number - tokens_parsed, tok);
|
self.insert_token(sk.token_number - tokens_parsed, tok);
|
||||||
|
|
||||||
// Add the BLOCK-MAPPING-START token if needed.
|
// Add the BLOCK-MAPPING-START token if needed.
|
||||||
self.roll_indent(sk.mark.col, Some(sk.token_number),
|
self.roll_indent(sk.mark.col, Some(sk.token_number),
|
||||||
|
@ -1653,7 +1653,7 @@ macro_rules! end {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_explicit_scalar() {
|
fn test_explicit_scalar() {
|
||||||
let s =
|
let s =
|
||||||
"---
|
"---
|
||||||
'a scalar'
|
'a scalar'
|
||||||
...
|
...
|
||||||
|
@ -1669,7 +1669,7 @@ macro_rules! end {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_multiple_documents() {
|
fn test_multiple_documents() {
|
||||||
let s =
|
let s =
|
||||||
"
|
"
|
||||||
'a scalar'
|
'a scalar'
|
||||||
---
|
---
|
||||||
|
@ -1706,7 +1706,7 @@ macro_rules! end {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_a_flow_mapping() {
|
fn test_a_flow_mapping() {
|
||||||
let s =
|
let s =
|
||||||
"
|
"
|
||||||
{
|
{
|
||||||
a simple key: a value, # Note that the KEY token is produced.
|
a simple key: a value, # Note that the KEY token is produced.
|
||||||
|
@ -1733,7 +1733,7 @@ macro_rules! end {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_block_sequences() {
|
fn test_block_sequences() {
|
||||||
let s =
|
let s =
|
||||||
"
|
"
|
||||||
- item 1
|
- item 1
|
||||||
- item 2
|
- item 2
|
||||||
|
@ -1776,7 +1776,7 @@ macro_rules! end {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_block_mappings() {
|
fn test_block_mappings() {
|
||||||
let s =
|
let s =
|
||||||
"
|
"
|
||||||
a simple key: a value # The KEY token is produced here.
|
a simple key: a value # The KEY token is produced here.
|
||||||
? a complex key
|
? a complex key
|
||||||
|
@ -1985,4 +1985,3 @@ key:
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,14 +8,14 @@ use scanner::{TScalarStyle, ScanError, TokenType};
|
||||||
|
|
||||||
/// An YAML node is store as this `Yaml` enumeration, it provides an easy way to
|
/// An YAML node is store as this `Yaml` enumeration, it provides an easy way to
|
||||||
/// access your YAML document.
|
/// access your YAML document.
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// use yaml_rust::Yaml;
|
/// use yaml_rust::Yaml;
|
||||||
/// let foo = Yaml::from_str("-123"); // convert the string to the appropriate YAML type
|
/// let foo = Yaml::from_str("-123"); // convert the string to the appropriate YAML type
|
||||||
/// assert_eq!(foo.as_i64().unwrap(), -123);
|
/// assert_eq!(foo.as_i64().unwrap(), -123);
|
||||||
///
|
///
|
||||||
/// // iterator over an Array
|
/// // iterator over an Array
|
||||||
/// let vec = Yaml::Array(vec![Yaml::Integer(1), Yaml::Integer(2)]);
|
/// let vec = Yaml::Array(vec![Yaml::Integer(1), Yaml::Integer(2)]);
|
||||||
/// for v in vec.as_vec().unwrap() {
|
/// for v in vec.as_vec().unwrap() {
|
||||||
|
@ -272,8 +272,6 @@ impl Index<usize> for Yaml {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use yaml::*;
|
use yaml::*;
|
||||||
|
@ -317,7 +315,7 @@ a7: 你好
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_multi_doc() {
|
fn test_multi_doc() {
|
||||||
let s =
|
let s =
|
||||||
"
|
"
|
||||||
'a scalar'
|
'a scalar'
|
||||||
---
|
---
|
||||||
|
@ -382,4 +380,3 @@ a7: 你好
|
||||||
assert!(doc[20].is_badvalue());
|
assert!(doc[20].is_badvalue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -71,4 +71,3 @@ include!("spec_test.rs.inc");
|
||||||
//#[test]
|
//#[test]
|
||||||
//fn test_hc_alias() {
|
//fn test_hc_alias() {
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue