Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allowing tags to be propagated for other events as well #180

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ branches:
- master

environment:
LLVM_VERSION: 9.0.1
LLVM_VERSION: 11.0.0
PLATFORM: x64
matrix:
- channel: stable
Expand Down
20 changes: 10 additions & 10 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ pub enum Event {
/// Value, style, anchor_id, tag
Scalar(String, TScalarStyle, usize, Option<TokenType>),
/// Anchor ID
SequenceStart(usize),
SequenceStart(usize, Option<TokenType>),
SequenceEnd,
/// Anchor ID
MappingStart(usize),
MappingStart(usize, Option<TokenType>),
MappingEnd,
}

Expand Down Expand Up @@ -233,11 +233,11 @@ impl<T: Iterator<Item = char>> Parser<T> {
recv.on_event(first_ev, mark);
Ok(())
}
Event::SequenceStart(_) => {
Event::SequenceStart(..) => {
recv.on_event(first_ev, mark);
self.load_sequence(recv)
}
Event::MappingStart(_) => {
Event::MappingStart(..) => {
recv.on_event(first_ev, mark);
self.load_mapping(recv)
}
Expand Down Expand Up @@ -497,7 +497,7 @@ impl<T: Iterator<Item = char>> Parser<T> {
match *self.peek_token()? {
Token(mark, TokenType::BlockEntry) if indentless_sequence => {
self.state = State::IndentlessSequenceEntry;
Ok((Event::SequenceStart(anchor_id), mark))
Ok((Event::SequenceStart(anchor_id, tag), mark))
}
Token(_, TokenType::Scalar(..)) => {
self.pop_state();
Expand All @@ -509,19 +509,19 @@ impl<T: Iterator<Item = char>> Parser<T> {
}
Token(mark, TokenType::FlowSequenceStart) => {
self.state = State::FlowSequenceFirstEntry;
Ok((Event::SequenceStart(anchor_id), mark))
Ok((Event::SequenceStart(anchor_id, tag), mark))
}
Token(mark, TokenType::FlowMappingStart) => {
self.state = State::FlowMappingFirstKey;
Ok((Event::MappingStart(anchor_id), mark))
Ok((Event::MappingStart(anchor_id, tag), mark))
}
Token(mark, TokenType::BlockSequenceStart) if block => {
self.state = State::BlockSequenceFirstEntry;
Ok((Event::SequenceStart(anchor_id), mark))
Ok((Event::SequenceStart(anchor_id, tag), mark))
}
Token(mark, TokenType::BlockMappingStart) if block => {
self.state = State::BlockMappingFirstKey;
Ok((Event::MappingStart(anchor_id), mark))
Ok((Event::MappingStart(anchor_id, tag), mark))
}
// ex 7.2, an empty scalar can follow a secondary tag
Token(mark, _) if tag.is_some() || anchor_id > 0 => {
Expand Down Expand Up @@ -718,7 +718,7 @@ impl<T: Iterator<Item = char>> Parser<T> {
Token(mark, TokenType::Key) => {
self.state = State::FlowSequenceEntryMappingKey;
self.skip();
Ok((Event::MappingStart(0), mark))
Ok((Event::MappingStart(0, None), mark))
}
_ => {
self.push_state(State::FlowSequenceEntry);
Expand Down
4 changes: 2 additions & 2 deletions src/yaml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ impl MarkedEventReceiver for YamlLoader {
_ => unreachable!(),
}
}
Event::SequenceStart(aid) => {
Event::SequenceStart(aid, _) => {
self.doc_stack.push((Yaml::Array(Vec::new()), aid));
}
Event::SequenceEnd => {
let node = self.doc_stack.pop().unwrap();
self.insert_new_node(node);
}
Event::MappingStart(aid) => {
Event::MappingStart(aid, _) => {
self.doc_stack.push((Yaml::Hash(Hash::new()), aid));
self.key_stack.push(Yaml::BadValue);
}
Expand Down
2 changes: 2 additions & 0 deletions tests/spec_test.rs.inc
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@ fn test_ex2_23_various_explicit_tags() {
assert_next!(v, TestEvent::OnScalar);
assert_next!(v, TestEvent::OnScalar);
assert_next!(v, TestEvent::OnScalar);
assert_next!(v, TestEvent::OnScalar);
assert_next!(v, TestEvent::OnScalar);
assert_next!(v, TestEvent::OnMapEnd);
assert_next!(v, TestEvent::OnDocumentEnd);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/specexamples.rs.inc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const EX2_18 : &'static str =
// TODO: 2.19 - 2.22 schema tags

const EX2_23 : &'static str =
"---\nnot-date: !!str 2002-04-28\n\npicture: !!binary |\n R0lGODlhDAAMAIQAAP//9/X\n 17unp5WZmZgAAAOfn515eXv\n Pz7Y6OjuDg4J+fn5OTk6enp\n 56enmleECcgggoBADs=\n\napplication specific tag: !something |\n The semantics of the tag\n above may be different for\n different documents.";
"---\nnot-date: !!str 2002-04-28\n\npicture: !!binary |\n R0lGODlhDAAMAIQAAP//9/X\n 17unp5WZmZgAAAOfn515eXv\n Pz7Y6OjuDg4J+fn5OTk6enp\n 56enmleECcgggoBADs=\n\napplication specific tag: !something |\n The semantics of the tag\n above may be different for\n different documents.\n\nscalar tag with value: !Ref reference\n";

const EX2_24 : &'static str =
"%TAG ! tag:clarkevans.com,2002:\n--- !shape\n # Use the ! handle for presenting\n # tag:clarkevans.com,2002:circle\n- !circle\n center: &ORIGIN {x: 73, y: 129}\n radius: 7\n- !line\n start: *ORIGIN\n finish: { x: 89, y: 102 }\n- !label\n start: *ORIGIN\n color: 0xFFEEBB\n text: Pretty vector drawing.";
Expand Down
2 changes: 2 additions & 0 deletions tests/specs/handler_spec_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,8 @@ TEST_F(HandlerSpecTest, Ex2_23_VariousExplicitTags) {
EXPECT_CALL(handler, OnScalar(_, "tag:yaml.org,2002:binary", 0, "R0lGODlhDAAMAIQAAP//9/X\n17unp5WZmZgAAAOfn515eXv\nPz7Y6OjuDg4J+fn5OTk6enp\n56enmleECcgggoBADs=\n"));
EXPECT_CALL(handler, OnScalar(_, "?", 0, "application specific tag"));
EXPECT_CALL(handler, OnScalar(_, "!something", 0, "The semantics of the tag\nabove may be different for\ndifferent documents."));
EXPECT_CALL(handler, OnScalar(_, "?", 0, "scalar tag with value"));
EXPECT_CALL(handler, OnScalar(_, "!Ref", 0, "reference"));
EXPECT_CALL(handler, OnMapEnd());
EXPECT_CALL(handler, OnDocumentEnd());
Parse(ex2_23);
Expand Down