Grammar in rustdoc

This commit is contained in:
David Tolnay 2016-03-10 01:55:21 -08:00
parent afc7d0e24e
commit 6d28d041cf

View file

@ -7,7 +7,7 @@ use std::mem;
use parser::*; use parser::*;
use scanner::{TScalarStyle, ScanError, TokenType}; use scanner::{TScalarStyle, ScanError, TokenType};
/// An YAML node is store as this `Yaml` enumeration, it provides an easy way to /// A YAML node is stored as this `Yaml` enumeration, which provides an easy way to
/// access your YAML document. /// access your YAML document.
/// ///
/// # Examples /// # Examples
@ -17,7 +17,7 @@ use scanner::{TScalarStyle, ScanError, TokenType};
/// 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 /// // iterate 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() {
/// assert!(v.as_i64().is_some()); /// assert!(v.as_i64().is_some());
@ -25,26 +25,26 @@ use scanner::{TScalarStyle, ScanError, TokenType};
/// ``` /// ```
#[derive(Clone, PartialEq, PartialOrd, Debug, Eq, Ord)] #[derive(Clone, PartialEq, PartialOrd, Debug, Eq, Ord)]
pub enum Yaml { pub enum Yaml {
/// float types are stored as String, and parsed on demand. /// Float types are stored as String and parsed on demand.
/// Note that f64 does NOT implement Eq trait and can NOT be stored in BTreeMap /// Note that f64 does NOT implement Eq trait and can NOT be stored in BTreeMap.
Real(string::String), Real(string::String),
/// Yaml int is stored as i64. /// YAML int is stored as i64.
Integer(i64), Integer(i64),
/// Yaml scalar. /// YAML scalar.
String(string::String), String(string::String),
/// Yaml bool, e.g. `true` or `false`. /// YAML bool, e.g. `true` or `false`.
Boolean(bool), Boolean(bool),
/// Yaml array, can be access as a `Vec`. /// YAML array, can be accessed as a `Vec`.
Array(self::Array), Array(self::Array),
/// Yaml hash, can be access as a `BTreeMap`. /// YAML hash, can be accessed as a `BTreeMap`.
Hash(self::Hash), Hash(self::Hash),
/// Alias, not fully supported yet. /// Alias, not fully supported yet.
Alias(usize), Alias(usize),
/// Yaml bool, e.g. `null` or `~`. /// YAML null, e.g. `null` or `~`.
Null, Null,
/// Access non-exist node by Index trait will return `BadValue`. /// Accessing a nonexistent node via the Index trait returns `BadValue`. This
/// This simplifies error handling of user. Invalid type conversion /// simplifies error handling in the calling code. Invalid type conversion also
/// also return `BadValue`. /// returns `BadValue`.
BadValue, BadValue,
} }
@ -250,13 +250,13 @@ impl Yaml {
// This function falls back to Yaml::String if nothing else matches. // This function falls back to Yaml::String if nothing else matches.
pub fn from_str(v: &str) -> Yaml { pub fn from_str(v: &str) -> Yaml {
if v.starts_with("0x") { if v.starts_with("0x") {
let n = i64::from_str_radix(&v[2..], 16); let n = i64::from_str_radix(&v[2..], 16);
if n.is_ok() { if n.is_ok() {
return Yaml::Integer(n.unwrap()); return Yaml::Integer(n.unwrap());
} }
} }
if v.starts_with("0o") { if v.starts_with("0o") {
let n = i64::from_str_radix(&v[2..], 8); let n = i64::from_str_radix(&v[2..], 8);
if n.is_ok() { if n.is_ok() {
return Yaml::Integer(n.unwrap()); return Yaml::Integer(n.unwrap());
} }