Add empty_scalar()

This commit is contained in:
Yuheng Chen 2015-05-24 14:29:10 +08:00
parent d03dec2197
commit 31a26b4a35

View file

@ -43,6 +43,12 @@ pub enum Event {
MappingEnd MappingEnd
} }
impl Event {
fn empty_scalar() -> Event {
Event::Scalar(String::new())
}
}
#[derive(Debug)] #[derive(Debug)]
pub struct Parser<T> { pub struct Parser<T> {
scanner: Scanner<T>, scanner: Scanner<T>,
@ -265,7 +271,7 @@ impl<T: Iterator<Item=char>> Parser<T> {
|TokenType::StreamEndToken => { |TokenType::StreamEndToken => {
self.pop_state(); self.pop_state();
// empty scalar // empty scalar
Ok(Event::Scalar(String::new())) Ok(Event::empty_scalar())
}, },
_ => { _ => {
self.parse_node(true, false) self.parse_node(true, false)
@ -324,7 +330,7 @@ impl<T: Iterator<Item=char>> Parser<T> {
=> { => {
self.state = State::BlockMappingValue; self.state = State::BlockMappingValue;
// empty scalar // empty scalar
Ok(Event::Scalar(String::new())) Ok(Event::empty_scalar())
} }
_ => { _ => {
self.push_state(State::BlockMappingValue); self.push_state(State::BlockMappingValue);
@ -354,7 +360,7 @@ impl<T: Iterator<Item=char>> Parser<T> {
=> { => {
self.state = State::BlockMappingValue; self.state = State::BlockMappingValue;
// empty scalar // empty scalar
Ok(Event::Scalar(String::new())) Ok(Event::empty_scalar())
} }
_ => { _ => {
self.push_state(State::BlockMappingKey); self.push_state(State::BlockMappingKey);
@ -365,7 +371,7 @@ impl<T: Iterator<Item=char>> Parser<T> {
_ => { _ => {
self.state = State::BlockMappingKey; self.state = State::BlockMappingKey;
// empty scalar // empty scalar
Ok(Event::Scalar(String::new())) Ok(Event::empty_scalar())
} }
} }
} }
@ -432,7 +438,7 @@ impl<T: Iterator<Item=char>> Parser<T> {
match tok.1 { match tok.1 {
TokenType::BlockEntryToken | TokenType::BlockEndToken => { TokenType::BlockEntryToken | TokenType::BlockEndToken => {
self.state = State::BlockSequenceEntry; self.state = State::BlockSequenceEntry;
Ok(Event::Scalar(String::new())) Ok(Event::empty_scalar())
}, },
_ => { _ => {
self.push_state(State::BlockSequenceEntry); self.push_state(State::BlockSequenceEntry);