From ab0e2c0519a37632fc34f97d2b87a59b8d2c83ac Mon Sep 17 00:00:00 2001 From: Cameron Ross Date: Tue, 12 Jun 2018 02:56:33 -0300 Subject: [PATCH] remove redundant implicit_2 (#155) remove redundant implicit_2 merged-on-behalf-of: BBasile --- source/dyaml/emitter.d | 2 +- source/dyaml/event.d | 8 ++------ source/dyaml/parser.d | 7 +++---- source/dyaml/serializer.d | 4 +--- source/dyaml/test/emitter.d | 4 ++-- 5 files changed, 9 insertions(+), 16 deletions(-) diff --git a/source/dyaml/emitter.d b/source/dyaml/emitter.d index 0df59a5..4e9eda7 100644 --- a/source/dyaml/emitter.d +++ b/source/dyaml/emitter.d @@ -796,7 +796,7 @@ struct Emitter { if(style_ == ScalarStyle.Invalid){style_ = chooseScalarStyle();} if((!canonical_ || (tag is null)) && - (style_ == ScalarStyle.Plain ? event_.implicit : event_.implicit_2)) + (style_ == ScalarStyle.Plain ? event_.implicit : !event_.implicit && (tag is null))) { preparedTag_ = null; return; diff --git a/source/dyaml/event.d b/source/dyaml/event.d index 2732e6f..9c4190b 100644 --- a/source/dyaml/event.d +++ b/source/dyaml/event.d @@ -12,7 +12,6 @@ module dyaml.event; import std.array; import std.conv; -import std.typecons; import dyaml.encoding; import dyaml.exception; @@ -81,8 +80,6 @@ struct Event */ bool explicitDocument; } - ///TODO figure this out - Unknown, used by PyYAML with Scalar events. - bool implicit_2; ///Encoding of the stream, if this is a StreamStart. Encoding encoding; ///Collection style, if this is a SequenceStart or MappingStart. @@ -234,7 +231,7 @@ Event documentEndEvent(const Mark start, const Mark end, const bool explicit) pu /// value = String value of the scalar. /// style = Scalar style. Event scalarEvent(const Mark start, const Mark end, const string anchor, const string tag, - const Tuple!(bool, bool) implicit, const string value, + const bool implicit, const string value, const ScalarStyle style = ScalarStyle.Invalid) @safe pure nothrow @nogc { Event result; @@ -247,7 +244,6 @@ Event scalarEvent(const Mark start, const Mark end, const string anchor, const s result.id = EventID.Scalar; result.scalarStyle = style; - result.implicit = implicit[0]; - result.implicit_2 = implicit[1]; + result.implicit = implicit; return result; } diff --git a/source/dyaml/parser.d b/source/dyaml/parser.d index 44437d6..415ac7e 100644 --- a/source/dyaml/parser.d +++ b/source/dyaml/parser.d @@ -465,10 +465,9 @@ final class Parser : cast(string)token.value; implicit = (token.style == ScalarStyle.Plain && tag is null) || tag == "!"; - bool implicit_2 = (!implicit) && tag is null; state_ = popState(); return scalarEvent(startMark, token.endMark, anchor, tag, - tuple(implicit, implicit_2), value, token.style); + implicit, value, token.style); } if(scanner_.checkToken(TokenID.FlowSequenceStart)) @@ -512,7 +511,7 @@ final class Parser //Empty scalars are allowed even if a tag or an anchor is specified. return scalarEvent(startMark, endMark, anchor, tag, - tuple(implicit, false) , ""); + implicit , ""); } const token = scanner_.peekToken(); @@ -935,6 +934,6 @@ final class Parser ///Return an empty scalar. Event processEmptyScalar(const Mark mark) @safe pure nothrow const @nogc { - return scalarEvent(mark, mark, null, null, tuple(true, false), ""); + return scalarEvent(mark, mark, null, null, true, ""); } } diff --git a/source/dyaml/serializer.d b/source/dyaml/serializer.d index c69772a..bb10390 100644 --- a/source/dyaml/serializer.d +++ b/source/dyaml/serializer.d @@ -182,12 +182,10 @@ struct Serializer assert(node.isType!string, "Scalar node type must be string before serialized"); auto value = node.as!string; const detectedTag = resolver_.resolve(NodeID.Scalar, null, value, true); - const defaultTag = resolver_.resolve(NodeID.Scalar, null, value, false); bool isDetected = node.tag_ == detectedTag; - bool isDefault = node.tag_ == defaultTag; emitter_.emit(scalarEvent(Mark(), Mark(), aliased, node.tag_, - tuple(isDetected, isDefault), value, node.scalarStyle)); + isDetected, value, node.scalarStyle)); return; } if(node.isSequence) diff --git a/source/dyaml/test/emitter.d b/source/dyaml/test/emitter.d index d1fb3c0..c92181c 100644 --- a/source/dyaml/test/emitter.d +++ b/source/dyaml/test/emitter.d @@ -56,7 +56,7 @@ bool compareEvents(Event[] events1, Event[] events2) @system if(e1.id == EventID.Scalar) { //Different scalar tag (if applicable). - if(![e1.implicit, e1.implicit_2, e2.implicit, e2.implicit_2].canFind(true) + if(!(e1.implicit || e2.implicit) && e1.tag != e2.tag) { return false; @@ -157,7 +157,7 @@ void testEmitterStyles(string dataFilename, string canonicalFilename) @system if(event.id == EventID.Scalar) { event = scalarEvent(Mark(), Mark(), event.anchor, event.tag, - tuple(event.implicit, event.implicit_2), + event.implicit, event.value, style); } else if(event.id == EventID.SequenceStart)