From ee7ef53563b200b2682a57e9448a6431ac7f5b7a Mon Sep 17 00:00:00 2001 From: Yuheng Chen Date: Wed, 27 May 2015 23:18:38 +0800 Subject: [PATCH] Add flow_sequence_entry_mapping --- parser/src/parser.rs | 53 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/parser/src/parser.rs b/parser/src/parser.rs index c72b786..9bffdad 100644 --- a/parser/src/parser.rs +++ b/parser/src/parser.rs @@ -230,6 +230,10 @@ impl> Parser { State::IndentlessSequenceEntry => self.indentless_sequence_entry(), + State::FlowSequenceEntryMappingKey => self.flow_sequence_entry_mapping_key(), + State::FlowSequenceEntryMappingValue => self.flow_sequence_entry_mapping_value(), + State::FlowSequenceEntryMappingEnd => self.flow_sequence_entry_mapping_end(), + _ => unimplemented!() } } @@ -606,6 +610,55 @@ impl> Parser { } } + fn flow_sequence_entry_mapping_key(&mut self) -> ParseResult { + let tok = try!(self.peek()); + + match tok.1 { + TokenType::ValueToken + | TokenType::FlowEntryToken + | TokenType::FlowSequenceEndToken => { + self.skip(); + self.state = State::FlowSequenceEntryMappingValue; + Ok(Event::empty_scalar()) + }, + _ => { + self.push_state(State::FlowSequenceEntryMappingValue); + self.parse_node(false, false) + } + } + } + + fn flow_sequence_entry_mapping_value(&mut self) -> ParseResult { + let tok = try!(self.peek()); + + match tok.1 { + TokenType::ValueToken => { + self.skip(); + let tok = try!(self.peek()); + self.state = State::FlowSequenceEntryMappingValue; + match tok.1 { + TokenType::FlowEntryToken + | TokenType::FlowSequenceEndToken => { + self.state = State::FlowSequenceEntryMappingEnd; + Ok(Event::empty_scalar()) + }, + _ => { + self.push_state(State::FlowSequenceEntryMappingEnd); + self.parse_node(false, false) + } + } + }, + _ => { + self.state = State::FlowSequenceEntryMappingEnd; + Ok(Event::empty_scalar()) + } + } + } + + fn flow_sequence_entry_mapping_end(&mut self) -> ParseResult { + self.state = State::FlowSequenceEntry; + Ok(Event::MappingEnd) + } } #[cfg(test)]