From b3c34c4f29c4846d8eb5d31f7ee4a6ec3378a685 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 27 Feb 2016 15:29:34 -0800 Subject: [PATCH] Remove common suffix from TokenType enum See https://github.com/Manishearth/rust-clippy/wiki#enum_variant_names --- parser/src/parser.rs | 132 +++++++------- parser/src/scanner.rs | 410 +++++++++++++++++++++--------------------- parser/src/yaml.rs | 2 +- 3 files changed, 272 insertions(+), 272 deletions(-) diff --git a/parser/src/parser.rs b/parser/src/parser.rs index 9a11abf..a6cdf73 100644 --- a/parser/src/parser.rs +++ b/parser/src/parser.rs @@ -270,7 +270,7 @@ impl> Parser { let tok = try!(self.peek()); match tok.1 { - TokenType::StreamStartToken(_) => { + TokenType::StreamStart(_) => { self.state = State::ImplicitDocumentStart; self.skip(); Ok(Event::StreamStart) @@ -285,7 +285,7 @@ impl> Parser { if !implicit { loop { match tok.1 { - TokenType::DocumentEndToken => { + TokenType::DocumentEnd => { self.skip(); tok = try!(self.peek()); }, @@ -295,14 +295,14 @@ impl> Parser { } match tok.1 { - TokenType::StreamEndToken => { + TokenType::StreamEnd => { self.state = State::End; self.skip(); return Ok(Event::StreamEnd); }, - TokenType::VersionDirectiveToken(..) - | TokenType::TagDirectiveToken(..) - | TokenType::DocumentStartToken => { + TokenType::VersionDirective(..) + | TokenType::TagDirective(..) + | TokenType::DocumentStart => { // explicit document self._explict_document_start() }, @@ -323,14 +323,14 @@ impl> Parser { loop { let tok = try!(self.peek()); match tok.1 { - TokenType::VersionDirectiveToken(_, _) => { + TokenType::VersionDirective(_, _) => { // XXX parsing with warning according to spec //if major != 1 || minor > 2 { // return Err(ScanError::new(tok.0, // "found incompatible YAML document")); //} }, - TokenType::TagDirectiveToken(..) => { + TokenType::TagDirective(..) => { // TODO add tag directive }, _ => break @@ -344,7 +344,7 @@ impl> Parser { fn _explict_document_start(&mut self) -> ParseResult { try!(self.parser_process_directives()); let tok = try!(self.peek()); - if tok.1 != TokenType::DocumentStartToken { + if tok.1 != TokenType::DocumentStart { return Err(ScanError::new(tok.0, "did not find expected ")); } self.push_state(State::DocumentEnd); @@ -356,11 +356,11 @@ impl> Parser { fn document_content(&mut self) -> ParseResult { let tok = try!(self.peek()); match tok.1 { - TokenType::VersionDirectiveToken(..) - |TokenType::TagDirectiveToken(..) - |TokenType::DocumentStartToken - |TokenType::DocumentEndToken - |TokenType::StreamEndToken => { + TokenType::VersionDirective(..) + |TokenType::TagDirective(..) + |TokenType::DocumentStart + |TokenType::DocumentEnd + |TokenType::StreamEnd => { self.pop_state(); // empty scalar Ok(Event::empty_scalar()) @@ -377,7 +377,7 @@ impl> Parser { let _start_mark = tok.0; match tok.1 { - TokenType::DocumentEndToken => { + TokenType::DocumentEnd => { self.skip(); _implicit = false; } @@ -406,7 +406,7 @@ impl> Parser { let mut anchor_id = 0; let mut tag = None; match tok.1 { - TokenType::AliasToken(name) => { + TokenType::Alias(name) => { self.pop_state(); self.skip(); match self.anchors.get(&name) { @@ -414,21 +414,21 @@ impl> Parser { Some(id) => return Ok(Event::Alias(*id)) } }, - TokenType::AnchorToken(name) => { + TokenType::Anchor(name) => { anchor_id = try!(self.register_anchor(&name, &tok.0)); self.skip(); tok = try!(self.peek()); - if let TokenType::TagToken(_, _) = tok.1 { + if let TokenType::Tag(_, _) = tok.1 { tag = Some(tok.1); self.skip(); tok = try!(self.peek()); } }, - TokenType::TagToken(..) => { + TokenType::Tag(..) => { tag = Some(tok.1); self.skip(); tok = try!(self.peek()); - if let TokenType::AnchorToken(name) = tok.1 { + if let TokenType::Anchor(name) = tok.1 { anchor_id = try!(self.register_anchor(&name, &tok.0)); self.skip(); tok = try!(self.peek()); @@ -437,28 +437,28 @@ impl> Parser { _ => {} } match tok.1 { - TokenType::BlockEntryToken if indentless_sequence => { + TokenType::BlockEntry if indentless_sequence => { self.state = State::IndentlessSequenceEntry; Ok(Event::SequenceStart(anchor_id)) }, - TokenType::ScalarToken(style, v) => { + TokenType::Scalar(style, v) => { self.pop_state(); self.skip(); Ok(Event::Scalar(v, style, anchor_id, tag)) }, - TokenType::FlowSequenceStartToken => { + TokenType::FlowSequenceStart => { self.state = State::FlowSequenceFirstEntry; Ok(Event::SequenceStart(anchor_id)) }, - TokenType::FlowMappingStartToken => { + TokenType::FlowMappingStart => { self.state = State::FlowMappingFirstKey; Ok(Event::MappingStart(anchor_id)) }, - TokenType::BlockSequenceStartToken if block => { + TokenType::BlockSequenceStart if block => { self.state = State::BlockSequenceFirstEntry; Ok(Event::SequenceStart(anchor_id)) }, - TokenType::BlockMappingStartToken if block => { + TokenType::BlockMappingStart if block => { self.state = State::BlockMappingFirstKey; Ok(Event::MappingStart(anchor_id)) }, @@ -472,7 +472,7 @@ impl> Parser { } fn block_mapping_key(&mut self, first: bool) -> ParseResult { - // skip BlockMappingStartToken + // skip BlockMappingStart if first { let _ = try!(self.peek()); //self.marks.push(tok.0); @@ -480,13 +480,13 @@ impl> Parser { } let tok = try!(self.peek()); match tok.1 { - TokenType::KeyToken => { + TokenType::Key => { self.skip(); let tok = try!(self.peek()); match tok.1 { - TokenType::KeyToken - | TokenType::ValueToken - | TokenType::BlockEndToken + TokenType::Key + | TokenType::Value + | TokenType::BlockEnd => { self.state = State::BlockMappingValue; // empty scalar @@ -499,11 +499,11 @@ impl> Parser { } }, // XXX(chenyh): libyaml failed to parse spec 1.2, ex8.18 - TokenType::ValueToken => { + TokenType::Value => { self.state = State::BlockMappingValue; Ok(Event::empty_scalar()) }, - TokenType::BlockEndToken => { + TokenType::BlockEnd => { self.pop_state(); self.skip(); Ok(Event::MappingEnd) @@ -517,11 +517,11 @@ impl> Parser { fn block_mapping_value(&mut self) -> ParseResult { let tok = try!(self.peek()); match tok.1 { - TokenType::ValueToken => { + TokenType::Value => { self.skip(); let tok = try!(self.peek()); match tok.1 { - TokenType::KeyToken | TokenType::ValueToken | TokenType::BlockEndToken + TokenType::Key | TokenType::Value | TokenType::BlockEnd => { self.state = State::BlockMappingKey; // empty scalar @@ -548,9 +548,9 @@ impl> Parser { } let mut tok = try!(self.peek()); - if tok.1 != TokenType::FlowMappingEndToken { + if tok.1 != TokenType::FlowMappingEnd { if !first { - if tok.1 == TokenType::FlowEntryToken { + if tok.1 == TokenType::FlowEntry { self.skip(); tok = try!(self.peek()); } else { @@ -559,13 +559,13 @@ impl> Parser { } } - if tok.1 == TokenType::KeyToken { + if tok.1 == TokenType::Key { self.skip(); tok = try!(self.peek()); match tok.1 { - TokenType::ValueToken - | TokenType::FlowEntryToken - | TokenType::FlowMappingEndToken => { + TokenType::Value + | TokenType::FlowEntry + | TokenType::FlowMappingEnd => { self.state = State::FlowMappingValue; return Ok(Event::empty_scalar()); }, @@ -575,10 +575,10 @@ impl> Parser { } } // XXX libyaml fail ex 7.3, empty key - } else if tok.1 == TokenType::ValueToken { + } else if tok.1 == TokenType::Value { self.state = State::FlowMappingValue; return Ok(Event::empty_scalar()); - } else if tok.1 != TokenType::FlowMappingEndToken { + } else if tok.1 != TokenType::FlowMappingEnd { self.push_state(State::FlowMappingEmptyValue); return self.parse_node(false, false); } @@ -596,12 +596,12 @@ impl> Parser { return Ok(Event::empty_scalar()); } - if tok.1 == TokenType::ValueToken { + if tok.1 == TokenType::Value { self.skip(); let tok = try!(self.peek()); match tok.1 { - TokenType::FlowEntryToken - | TokenType::FlowMappingEndToken => { }, + TokenType::FlowEntry + | TokenType::FlowMappingEnd => { }, _ => { self.push_state(State::FlowMappingKey); return self.parse_node(false, false); @@ -614,7 +614,7 @@ impl> Parser { } fn flow_sequence_entry(&mut self, first: bool) -> ParseResult { - // skip FlowMappingStartToken + // skip FlowMappingStart if first { let _ = try!(self.peek()); //self.marks.push(tok.0); @@ -622,12 +622,12 @@ impl> Parser { } let mut tok = try!(self.peek()); match tok.1 { - TokenType::FlowSequenceEndToken => { + TokenType::FlowSequenceEnd => { self.pop_state(); self.skip(); return Ok(Event::SequenceEnd); }, - TokenType::FlowEntryToken if !first => { + TokenType::FlowEntry if !first => { self.skip(); tok = try!(self.peek()); }, @@ -638,12 +638,12 @@ impl> Parser { _ => { /* next */ } } match tok.1 { - TokenType::FlowSequenceEndToken => { + TokenType::FlowSequenceEnd => { self.pop_state(); self.skip(); Ok(Event::SequenceEnd) }, - TokenType::KeyToken => { + TokenType::Key => { self.state = State::FlowSequenceEntryMappingKey; self.skip(); Ok(Event::MappingStart(0)) @@ -657,7 +657,7 @@ impl> Parser { fn indentless_sequence_entry(&mut self) -> ParseResult { let mut tok = try!(self.peek()); - if tok.1 != TokenType::BlockEntryToken { + if tok.1 != TokenType::BlockEntry { self.pop_state(); return Ok(Event::SequenceEnd); } @@ -665,10 +665,10 @@ impl> Parser { self.skip(); tok = try!(self.peek()); match tok.1 { - TokenType::BlockEntryToken - | TokenType::KeyToken - | TokenType::ValueToken - | TokenType::BlockEndToken => { + TokenType::BlockEntry + | TokenType::Key + | TokenType::Value + | TokenType::BlockEnd => { self.state = State::IndentlessSequenceEntry; Ok(Event::empty_scalar()) }, @@ -688,17 +688,17 @@ impl> Parser { } let mut tok = try!(self.peek()); match tok.1 { - TokenType::BlockEndToken => { + TokenType::BlockEnd => { self.pop_state(); self.skip(); Ok(Event::SequenceEnd) }, - TokenType::BlockEntryToken => { + TokenType::BlockEntry => { self.skip(); tok = try!(self.peek()); match tok.1 { - TokenType::BlockEntryToken - | TokenType::BlockEndToken => { + TokenType::BlockEntry + | TokenType::BlockEnd => { self.state = State::BlockSequenceEntry; Ok(Event::empty_scalar()) }, @@ -719,9 +719,9 @@ impl> Parser { let tok = try!(self.peek()); match tok.1 { - TokenType::ValueToken - | TokenType::FlowEntryToken - | TokenType::FlowSequenceEndToken => { + TokenType::Value + | TokenType::FlowEntry + | TokenType::FlowSequenceEnd => { self.skip(); self.state = State::FlowSequenceEntryMappingValue; Ok(Event::empty_scalar()) @@ -737,13 +737,13 @@ impl> Parser { let tok = try!(self.peek()); match tok.1 { - TokenType::ValueToken => { + TokenType::Value => { self.skip(); let tok = try!(self.peek()); self.state = State::FlowSequenceEntryMappingValue; match tok.1 { - TokenType::FlowEntryToken - | TokenType::FlowSequenceEndToken => { + TokenType::FlowEntry + | TokenType::FlowSequenceEnd => { self.state = State::FlowSequenceEntryMappingEnd; Ok(Event::empty_scalar()) }, diff --git a/parser/src/scanner.rs b/parser/src/scanner.rs index 4cfe2bc..16c3b61 100644 --- a/parser/src/scanner.rs +++ b/parser/src/scanner.rs @@ -71,30 +71,30 @@ impl fmt::Display for ScanError { #[derive(Clone, PartialEq, Debug, Eq)] pub enum TokenType { NoToken, - StreamStartToken(TEncoding), - StreamEndToken, + StreamStart(TEncoding), + StreamEnd, /// major, minor - VersionDirectiveToken(u32, u32), + VersionDirective(u32, u32), /// handle, prefix - TagDirectiveToken(String, String), - DocumentStartToken, - DocumentEndToken, - BlockSequenceStartToken, - BlockMappingStartToken, - BlockEndToken, - FlowSequenceStartToken, - FlowSequenceEndToken, - FlowMappingStartToken, - FlowMappingEndToken, - BlockEntryToken, - FlowEntryToken, - KeyToken, - ValueToken, - AliasToken(String), - AnchorToken(String), + TagDirective(String, String), + DocumentStart, + DocumentEnd, + BlockSequenceStart, + BlockMappingStart, + BlockEnd, + FlowSequenceStart, + FlowSequenceEnd, + FlowMappingStart, + FlowMappingEnd, + BlockEntry, + FlowEntry, + Key, + Value, + Alias(String), + Anchor(String), /// handle, suffix - TagToken(String, String), - ScalarToken(TScalarStyle, String) + Tag(String, String), + Scalar(TScalarStyle, String) } #[derive(Clone, PartialEq, Debug, Eq)] @@ -348,7 +348,7 @@ impl> Scanner { && self.buffer[1] == '-' && self.buffer[2] == '-' && is_blankz(self.buffer[3]) { - try!(self.fetch_document_indicator(TokenType::DocumentStartToken)); + try!(self.fetch_document_indicator(TokenType::DocumentStart)); return Ok(()); } @@ -357,17 +357,17 @@ impl> Scanner { && self.buffer[1] == '.' && self.buffer[2] == '.' && is_blankz(self.buffer[3]) { - try!(self.fetch_document_indicator(TokenType::DocumentEndToken)); + try!(self.fetch_document_indicator(TokenType::DocumentEnd)); return Ok(()); } let c = self.buffer[0]; let nc = self.buffer[1]; match c { - '[' => self.fetch_flow_collection_start(TokenType::FlowSequenceStartToken), - '{' => self.fetch_flow_collection_start(TokenType::FlowMappingStartToken), - ']' => self.fetch_flow_collection_end(TokenType::FlowSequenceEndToken), - '}' => self.fetch_flow_collection_end(TokenType::FlowMappingEndToken), + '[' => self.fetch_flow_collection_start(TokenType::FlowSequenceStart), + '{' => self.fetch_flow_collection_start(TokenType::FlowMappingStart), + ']' => self.fetch_flow_collection_end(TokenType::FlowSequenceEnd), + '}' => self.fetch_flow_collection_end(TokenType::FlowMappingEnd), ',' => self.fetch_flow_entry(), '-' if is_blankz(nc) => self.fetch_block_entry(), '?' if self.flow_level > 0 || is_blankz(nc) => self.fetch_key(), @@ -405,7 +405,7 @@ impl> Scanner { self.tokens_parsed += 1; match t.1 { - TokenType::StreamEndToken => self.stream_end_produced = true, + TokenType::StreamEnd => self.stream_end_produced = true, _ => {} } Ok(Some(t)) @@ -473,7 +473,7 @@ impl> Scanner { self.indent = -1; self.stream_start_produced = true; self.allow_simple_key(); - self.tokens.push_back(Token(mark, TokenType::StreamStartToken(TEncoding::Utf8))); + self.tokens.push_back(Token(mark, TokenType::StreamStart(TEncoding::Utf8))); self.simple_keys.push(SimpleKey::new(Marker::new(0,0,0))); } @@ -488,7 +488,7 @@ impl> Scanner { try!(self.remove_simple_key()); self.disallow_simple_key(); - self.tokens.push_back(Token(self.mark, TokenType::StreamEndToken)); + self.tokens.push_back(Token(self.mark, TokenType::StreamEnd)); Ok(()) } @@ -526,7 +526,7 @@ impl> Scanner { self.lookahead(1); } // XXX return an empty TagDirective token - Token(start_mark, TokenType::TagDirectiveToken(String::new(), String::new())) + Token(start_mark, TokenType::TagDirective(String::new(), String::new())) // return Err(ScanError::new(start_mark, // "while scanning a directive, found unknown directive name")) } @@ -578,7 +578,7 @@ impl> Scanner { let minor = try!(self.scan_version_directive_number(mark)); - Ok(Token(*mark, TokenType::VersionDirectiveToken(major, minor))) + Ok(Token(*mark, TokenType::VersionDirective(major, minor))) } fn scan_directive_name(&mut self) -> Result { @@ -652,7 +652,7 @@ impl> Scanner { Err(ScanError::new(*mark, "while scanning TAG, did not find expected whitespace or line break")) } else { - Ok(Token(*mark, TokenType::TagDirectiveToken(handle, prefix))) + Ok(Token(*mark, TokenType::TagDirective(handle, prefix))) } } @@ -710,7 +710,7 @@ impl> Scanner { self.lookahead(1); if is_blankz(self.ch()) { // XXX: ex 7.2, an empty scalar can follow a secondary tag - Ok(Token(start_mark, TokenType::TagToken(handle, suffix))) + Ok(Token(start_mark, TokenType::Tag(handle, suffix))) } else { Err(ScanError::new(start_mark, "while scanning a tag, did not find expected whitespace or line break")) @@ -883,9 +883,9 @@ impl> Scanner { } if alias { - Ok(Token(start_mark, TokenType::AliasToken(string))) + Ok(Token(start_mark, TokenType::Alias(string))) } else { - Ok(Token(start_mark, TokenType::AnchorToken(string))) + Ok(Token(start_mark, TokenType::Anchor(string))) } } @@ -924,7 +924,7 @@ impl> Scanner { let start_mark = self.mark; self.skip(); - self.tokens.push_back(Token(start_mark, TokenType::FlowEntryToken)); + self.tokens.push_back(Token(start_mark, TokenType::FlowEntry)); Ok(()) } @@ -949,7 +949,7 @@ impl> Scanner { let mark = self.mark; // generate BLOCK-SEQUENCE-START if indented - self.roll_indent(mark.col, None, TokenType::BlockSequenceStartToken, mark); + self.roll_indent(mark.col, None, TokenType::BlockSequenceStart, mark); } else { // - * only allowed in block unreachable!(); @@ -960,7 +960,7 @@ impl> Scanner { let start_mark = self.mark; self.skip(); - self.tokens.push_back(Token(start_mark, TokenType::BlockEntryToken)); + self.tokens.push_back(Token(start_mark, TokenType::BlockEntry)); Ok(()) } @@ -1119,9 +1119,9 @@ impl> Scanner { } if literal { - Ok(Token(start_mark, TokenType::ScalarToken(TScalarStyle::Literal, string))) + Ok(Token(start_mark, TokenType::Scalar(TScalarStyle::Literal, string))) } else { - Ok(Token(start_mark, TokenType::ScalarToken(TScalarStyle::Foled, string))) + Ok(Token(start_mark, TokenType::Scalar(TScalarStyle::Foled, string))) } } @@ -1353,9 +1353,9 @@ impl> Scanner { self.skip(); if single { - Ok(Token(start_mark, TokenType::ScalarToken(TScalarStyle::SingleQuoted, string))) + Ok(Token(start_mark, TokenType::Scalar(TScalarStyle::SingleQuoted, string))) } else { - Ok(Token(start_mark, TokenType::ScalarToken(TScalarStyle::DoubleQuoted, string))) + Ok(Token(start_mark, TokenType::Scalar(TScalarStyle::DoubleQuoted, string))) } } @@ -1477,7 +1477,7 @@ impl> Scanner { self.allow_simple_key(); } - Ok(Token(start_mark, TokenType::ScalarToken(TScalarStyle::Plain, string))) + Ok(Token(start_mark, TokenType::Scalar(TScalarStyle::Plain, string))) } fn fetch_key(&mut self) -> ScanResult { @@ -1488,7 +1488,7 @@ impl> Scanner { return Err(ScanError::new(self.mark, "mapping keys are not allowed in this context")); } self.roll_indent(start_mark.col, None, - TokenType::BlockMappingStartToken, start_mark); + TokenType::BlockMappingStart, start_mark); } try!(self.remove_simple_key()); @@ -1500,7 +1500,7 @@ impl> Scanner { } self.skip(); - self.tokens.push_back(Token(start_mark, TokenType::KeyToken)); + self.tokens.push_back(Token(start_mark, TokenType::Key)); Ok(()) } @@ -1509,13 +1509,13 @@ impl> Scanner { let start_mark = self.mark; if sk.possible { // insert simple key - let tok = Token(sk.mark, TokenType::KeyToken); + let tok = Token(sk.mark, TokenType::Key); let tokens_parsed = self.tokens_parsed; self.insert_token(sk.token_number - tokens_parsed, tok); // Add the BLOCK-MAPPING-START token if needed. self.roll_indent(sk.mark.col, Some(sk.token_number), - TokenType::BlockMappingStartToken, start_mark); + TokenType::BlockMappingStart, start_mark); self.simple_keys.last_mut().unwrap().possible = false; self.disallow_simple_key(); @@ -1528,7 +1528,7 @@ impl> Scanner { } self.roll_indent(start_mark.col, None, - TokenType::BlockMappingStartToken, start_mark); + TokenType::BlockMappingStart, start_mark); } if self.flow_level == 0 { @@ -1538,7 +1538,7 @@ impl> Scanner { } } self.skip(); - self.tokens.push_back(Token(start_mark, TokenType::ValueToken)); + self.tokens.push_back(Token(start_mark, TokenType::Value)); Ok(()) } @@ -1565,7 +1565,7 @@ impl> Scanner { return; } while self.indent > col { - self.tokens.push_back(Token(self.mark, TokenType::BlockEndToken)); + self.tokens.push_back(Token(self.mark, TokenType::BlockEnd)); self.indent = self.indents.pop().unwrap(); } } @@ -1620,7 +1620,7 @@ macro_rules! next_scalar { ($p:ident, $tk:expr, $v:expr) => {{ let tok = $p.next().unwrap(); match tok.1 { - ScalarToken(style, ref v) => { + Scalar(style, ref v) => { assert_eq!(style, $tk); assert_eq!(v, $v); }, @@ -1640,8 +1640,8 @@ macro_rules! end { fn test_empty() { let s = ""; let mut p = Scanner::new(s.chars()); - next!(p, StreamStartToken(..)); - next!(p, StreamEndToken); + next!(p, StreamStart(..)); + next!(p, StreamEnd); end!(p); } @@ -1649,9 +1649,9 @@ macro_rules! end { fn test_scalar() { let s = "a scalar"; let mut p = Scanner::new(s.chars()); - next!(p, StreamStartToken(..)); - next!(p, ScalarToken(TScalarStyle::Plain, _)); - next!(p, StreamEndToken); + next!(p, StreamStart(..)); + next!(p, Scalar(TScalarStyle::Plain, _)); + next!(p, StreamEnd); end!(p); } @@ -1663,11 +1663,11 @@ macro_rules! end { ... "; let mut p = Scanner::new(s.chars()); - next!(p, StreamStartToken(..)); - next!(p, DocumentStartToken); - next!(p, ScalarToken(TScalarStyle::SingleQuoted, _)); - next!(p, DocumentEndToken); - next!(p, StreamEndToken); + next!(p, StreamStart(..)); + next!(p, DocumentStart); + next!(p, Scalar(TScalarStyle::SingleQuoted, _)); + next!(p, DocumentEnd); + next!(p, StreamEnd); end!(p); } @@ -1682,13 +1682,13 @@ macro_rules! end { 'a scalar' "; let mut p = Scanner::new(s.chars()); - next!(p, StreamStartToken(..)); - next!(p, ScalarToken(TScalarStyle::SingleQuoted, _)); - next!(p, DocumentStartToken); - next!(p, ScalarToken(TScalarStyle::SingleQuoted, _)); - next!(p, DocumentStartToken); - next!(p, ScalarToken(TScalarStyle::SingleQuoted, _)); - next!(p, StreamEndToken); + next!(p, StreamStart(..)); + next!(p, Scalar(TScalarStyle::SingleQuoted, _)); + next!(p, DocumentStart); + next!(p, Scalar(TScalarStyle::SingleQuoted, _)); + next!(p, DocumentStart); + next!(p, Scalar(TScalarStyle::SingleQuoted, _)); + next!(p, StreamEnd); end!(p); } @@ -1696,15 +1696,15 @@ macro_rules! end { fn test_a_flow_sequence() { let s = "[item 1, item 2, item 3]"; let mut p = Scanner::new(s.chars()); - next!(p, StreamStartToken(..)); - next!(p, FlowSequenceStartToken); + next!(p, StreamStart(..)); + next!(p, FlowSequenceStart); next_scalar!(p, TScalarStyle::Plain, "item 1"); - next!(p, FlowEntryToken); - next!(p, ScalarToken(TScalarStyle::Plain, _)); - next!(p, FlowEntryToken); - next!(p, ScalarToken(TScalarStyle::Plain, _)); - next!(p, FlowSequenceEndToken); - next!(p, StreamEndToken); + next!(p, FlowEntry); + next!(p, Scalar(TScalarStyle::Plain, _)); + next!(p, FlowEntry); + next!(p, Scalar(TScalarStyle::Plain, _)); + next!(p, FlowSequenceEnd); + next!(p, StreamEnd); end!(p); } @@ -1718,20 +1718,20 @@ macro_rules! end { } "; let mut p = Scanner::new(s.chars()); - next!(p, StreamStartToken(..)); - next!(p, FlowMappingStartToken); - next!(p, KeyToken); - next!(p, ScalarToken(TScalarStyle::Plain, _)); - next!(p, ValueToken); - next!(p, ScalarToken(TScalarStyle::Plain, _)); - next!(p, FlowEntryToken); - next!(p, KeyToken); + next!(p, StreamStart(..)); + next!(p, FlowMappingStart); + next!(p, Key); + next!(p, Scalar(TScalarStyle::Plain, _)); + next!(p, Value); + next!(p, Scalar(TScalarStyle::Plain, _)); + next!(p, FlowEntry); + next!(p, Key); next_scalar!(p, TScalarStyle::Plain, "a complex key"); - next!(p, ValueToken); - next!(p, ScalarToken(TScalarStyle::Plain, _)); - next!(p, FlowEntryToken); - next!(p, FlowMappingEndToken); - next!(p, StreamEndToken); + next!(p, Value); + next!(p, Scalar(TScalarStyle::Plain, _)); + next!(p, FlowEntry); + next!(p, FlowMappingEnd); + next!(p, StreamEnd); end!(p); } @@ -1749,32 +1749,32 @@ macro_rules! end { key 2: value 2 "; let mut p = Scanner::new(s.chars()); - next!(p, StreamStartToken(..)); - next!(p, BlockSequenceStartToken); - next!(p, BlockEntryToken); + next!(p, StreamStart(..)); + next!(p, BlockSequenceStart); + next!(p, BlockEntry); next_scalar!(p, TScalarStyle::Plain, "item 1"); - next!(p, BlockEntryToken); + next!(p, BlockEntry); next_scalar!(p, TScalarStyle::Plain, "item 2"); - next!(p, BlockEntryToken); - next!(p, BlockSequenceStartToken); - next!(p, BlockEntryToken); + next!(p, BlockEntry); + next!(p, BlockSequenceStart); + next!(p, BlockEntry); next_scalar!(p, TScalarStyle::Plain, "item 3.1"); - next!(p, BlockEntryToken); + next!(p, BlockEntry); next_scalar!(p, TScalarStyle::Plain, "item 3.2"); - next!(p, BlockEndToken); - next!(p, BlockEntryToken); - next!(p, BlockMappingStartToken); - next!(p, KeyToken); + next!(p, BlockEnd); + next!(p, BlockEntry); + next!(p, BlockMappingStart); + next!(p, Key); next_scalar!(p, TScalarStyle::Plain, "key 1"); - next!(p, ValueToken); + next!(p, Value); next_scalar!(p, TScalarStyle::Plain, "value 1"); - next!(p, KeyToken); + next!(p, Key); next_scalar!(p, TScalarStyle::Plain, "key 2"); - next!(p, ValueToken); + next!(p, Value); next_scalar!(p, TScalarStyle::Plain, "value 2"); - next!(p, BlockEndToken); - next!(p, BlockEndToken); - next!(p, StreamEndToken); + next!(p, BlockEnd); + next!(p, BlockEnd); + next!(p, StreamEnd); end!(p); } @@ -1793,40 +1793,40 @@ a sequence: - item 2 "; let mut p = Scanner::new(s.chars()); - next!(p, StreamStartToken(..)); - next!(p, BlockMappingStartToken); - next!(p, KeyToken); - next!(p, ScalarToken(_, _)); - next!(p, ValueToken); - next!(p, ScalarToken(_, _)); - next!(p, KeyToken); - next!(p, ScalarToken(_, _)); - next!(p, ValueToken); - next!(p, ScalarToken(_, _)); - next!(p, KeyToken); - next!(p, ScalarToken(_, _)); - next!(p, ValueToken); // libyaml comment seems to be wrong - next!(p, BlockMappingStartToken); - next!(p, KeyToken); - next!(p, ScalarToken(_, _)); - next!(p, ValueToken); - next!(p, ScalarToken(_, _)); - next!(p, KeyToken); - next!(p, ScalarToken(_, _)); - next!(p, ValueToken); - next!(p, ScalarToken(_, _)); - next!(p, BlockEndToken); - next!(p, KeyToken); - next!(p, ScalarToken(_, _)); - next!(p, ValueToken); - next!(p, BlockSequenceStartToken); - next!(p, BlockEntryToken); - next!(p, ScalarToken(_, _)); - next!(p, BlockEntryToken); - next!(p, ScalarToken(_, _)); - next!(p, BlockEndToken); - next!(p, BlockEndToken); - next!(p, StreamEndToken); + next!(p, StreamStart(..)); + next!(p, BlockMappingStart); + next!(p, Key); + next!(p, Scalar(_, _)); + next!(p, Value); + next!(p, Scalar(_, _)); + next!(p, Key); + next!(p, Scalar(_, _)); + next!(p, Value); + next!(p, Scalar(_, _)); + next!(p, Key); + next!(p, Scalar(_, _)); + next!(p, Value); // libyaml comment seems to be wrong + next!(p, BlockMappingStart); + next!(p, Key); + next!(p, Scalar(_, _)); + next!(p, Value); + next!(p, Scalar(_, _)); + next!(p, Key); + next!(p, Scalar(_, _)); + next!(p, Value); + next!(p, Scalar(_, _)); + next!(p, BlockEnd); + next!(p, Key); + next!(p, Scalar(_, _)); + next!(p, Value); + next!(p, BlockSequenceStart); + next!(p, BlockEntry); + next!(p, Scalar(_, _)); + next!(p, BlockEntry); + next!(p, Scalar(_, _)); + next!(p, BlockEnd); + next!(p, BlockEnd); + next!(p, StreamEnd); end!(p); } @@ -1840,17 +1840,17 @@ key: - item 2 "; let mut p = Scanner::new(s.chars()); - next!(p, StreamStartToken(..)); - next!(p, BlockMappingStartToken); - next!(p, KeyToken); + next!(p, StreamStart(..)); + next!(p, BlockMappingStart); + next!(p, Key); next_scalar!(p, TScalarStyle::Plain, "key"); - next!(p, ValueToken); - next!(p, BlockEntryToken); + next!(p, Value); + next!(p, BlockEntry); next_scalar!(p, TScalarStyle::Plain, "item 1"); - next!(p, BlockEntryToken); + next!(p, BlockEntry); next_scalar!(p, TScalarStyle::Plain, "item 2"); - next!(p, BlockEndToken); - next!(p, StreamEndToken); + next!(p, BlockEnd); + next!(p, StreamEnd); end!(p); } @@ -1866,35 +1866,35 @@ key: : complex value "; let mut p = Scanner::new(s.chars()); - next!(p, StreamStartToken(..)); - next!(p, BlockSequenceStartToken); - next!(p, BlockEntryToken); - next!(p, BlockSequenceStartToken); - next!(p, BlockEntryToken); + next!(p, StreamStart(..)); + next!(p, BlockSequenceStart); + next!(p, BlockEntry); + next!(p, BlockSequenceStart); + next!(p, BlockEntry); next_scalar!(p, TScalarStyle::Plain, "item 1"); - next!(p, BlockEntryToken); + next!(p, BlockEntry); next_scalar!(p, TScalarStyle::Plain, "item 2"); - next!(p, BlockEndToken); - next!(p, BlockEntryToken); - next!(p, BlockMappingStartToken); - next!(p, KeyToken); + next!(p, BlockEnd); + next!(p, BlockEntry); + next!(p, BlockMappingStart); + next!(p, Key); next_scalar!(p, TScalarStyle::Plain, "key 1"); - next!(p, ValueToken); + next!(p, Value); next_scalar!(p, TScalarStyle::Plain, "value 1"); - next!(p, KeyToken); + next!(p, Key); next_scalar!(p, TScalarStyle::Plain, "key 2"); - next!(p, ValueToken); + next!(p, Value); next_scalar!(p, TScalarStyle::Plain, "value 2"); - next!(p, BlockEndToken); - next!(p, BlockEntryToken); - next!(p, BlockMappingStartToken); - next!(p, KeyToken); + next!(p, BlockEnd); + next!(p, BlockEntry); + next!(p, BlockMappingStart); + next!(p, Key); next_scalar!(p, TScalarStyle::Plain, "complex key"); - next!(p, ValueToken); + next!(p, Value); next_scalar!(p, TScalarStyle::Plain, "complex value"); - next!(p, BlockEndToken); - next!(p, BlockEndToken); - next!(p, StreamEndToken); + next!(p, BlockEnd); + next!(p, BlockEnd); + next!(p, StreamEnd); end!(p); } @@ -1910,32 +1910,32 @@ key: key 2: value 2 "; let mut p = Scanner::new(s.chars()); - next!(p, StreamStartToken(..)); - next!(p, BlockMappingStartToken); - next!(p, KeyToken); + next!(p, StreamStart(..)); + next!(p, BlockMappingStart); + next!(p, Key); next_scalar!(p, TScalarStyle::Plain, "a sequence"); - next!(p, ValueToken); - next!(p, BlockSequenceStartToken); - next!(p, BlockEntryToken); + next!(p, Value); + next!(p, BlockSequenceStart); + next!(p, BlockEntry); next_scalar!(p, TScalarStyle::Plain, "item 1"); - next!(p, BlockEntryToken); + next!(p, BlockEntry); next_scalar!(p, TScalarStyle::Plain, "item 2"); - next!(p, BlockEndToken); - next!(p, KeyToken); + next!(p, BlockEnd); + next!(p, Key); next_scalar!(p, TScalarStyle::Plain, "a mapping"); - next!(p, ValueToken); - next!(p, BlockMappingStartToken); - next!(p, KeyToken); + next!(p, Value); + next!(p, BlockMappingStart); + next!(p, Key); next_scalar!(p, TScalarStyle::Plain, "key 1"); - next!(p, ValueToken); + next!(p, Value); next_scalar!(p, TScalarStyle::Plain, "value 1"); - next!(p, KeyToken); + next!(p, Key); next_scalar!(p, TScalarStyle::Plain, "key 2"); - next!(p, ValueToken); + next!(p, Value); next_scalar!(p, TScalarStyle::Plain, "value 2"); - next!(p, BlockEndToken); - next!(p, BlockEndToken); - next!(p, StreamEndToken); + next!(p, BlockEnd); + next!(p, BlockEnd); + next!(p, StreamEnd); end!(p); } @@ -1949,17 +1949,17 @@ key: } "; let mut p = Scanner::new(s.chars()); - next!(p, StreamStartToken(..)); - next!(p, FlowMappingStartToken); - next!(p, KeyToken); + next!(p, StreamStart(..)); + next!(p, FlowMappingStart); + next!(p, Key); next_scalar!(p, TScalarStyle::Plain, "foo"); - next!(p, ValueToken); - next!(p, FlowEntryToken); - next!(p, ValueToken); + next!(p, Value); + next!(p, FlowEntry); + next!(p, Value); next_scalar!(p, TScalarStyle::Plain, "bar"); - next!(p, FlowEntryToken); - next!(p, FlowMappingEndToken); - next!(p, StreamEndToken); + next!(p, FlowEntry); + next!(p, FlowMappingEnd); + next!(p, StreamEnd); end!(p); } @@ -1967,15 +1967,15 @@ key: fn test_scanner_cr() { let s = "---\r\n- tok1\r\n- tok2"; let mut p = Scanner::new(s.chars()); - next!(p, StreamStartToken(..)); - next!(p, DocumentStartToken); - next!(p, BlockSequenceStartToken); - next!(p, BlockEntryToken); + next!(p, StreamStart(..)); + next!(p, DocumentStart); + next!(p, BlockSequenceStart); + next!(p, BlockEntry); next_scalar!(p, TScalarStyle::Plain, "tok1"); - next!(p, BlockEntryToken); + next!(p, BlockEntry); next_scalar!(p, TScalarStyle::Plain, "tok2"); - next!(p, BlockEndToken); - next!(p, StreamEndToken); + next!(p, BlockEnd); + next!(p, StreamEnd); end!(p); } diff --git a/parser/src/yaml.rs b/parser/src/yaml.rs index 45f2fb8..d63e357 100644 --- a/parser/src/yaml.rs +++ b/parser/src/yaml.rs @@ -96,7 +96,7 @@ impl EventReceiver for YamlLoader { Yaml::String(v.clone()) } else { match tag { - &Some(TokenType::TagToken(ref handle, ref suffix)) => { + &Some(TokenType::Tag(ref handle, ref suffix)) => { // XXX tag:yaml.org,2002: if handle == "!!" { match suffix.as_ref() {