diff --git a/dyaml/node.d b/dyaml/node.d index 8333353..6d59e6d 100644 --- a/dyaml/node.d +++ b/dyaml/node.d @@ -168,7 +168,9 @@ struct Node Value value_; ///Start position of the node. Mark startMark_; - ///Tag of the node. + + package: + //Tag of the node. Is package as it is both written to and read all over D:YAML. Tag tag_; public: @@ -426,6 +428,9 @@ struct Node ///Is this node a user defined type? @property bool isUserType() const {return isType!YAMLObject;} + ///Return tag of the node. + @property string tag() const {return tag_.get;} + /** * Equality test. * @@ -1244,12 +1249,6 @@ struct Node */ @property bool isType(T)() const {return value_.type is typeid(T);} - //Return tag of the node. - @property Tag tag() const {return tag_;} - - //Set tag of the node. - @property void tag(Tag tag) {tag_ = tag;} - private: //Is the value an integer of some kind? alias isType!long isInt; diff --git a/dyaml/representer.d b/dyaml/representer.d index a865364..9ca7e2a 100644 --- a/dyaml/representer.d +++ b/dyaml/representer.d @@ -300,7 +300,7 @@ final class Representer new RepresenterException("No representer function for type " ~ type.toString() ~ " , cannot represent.")); Node result = representers_[type](data, this); - if(!data.tag.isNull()){result.tag = data.tag;} + if(!data.tag_.isNull()){result.tag_ = data.tag_;} return result; } @@ -375,7 +375,7 @@ Node representSysTime(ref Node node, Representer representer) Node representNodes(ref Node node, Representer representer) { auto nodes = node.get!(Node[]); - if(node.tag == Tag("tag:yaml.org,2002:set")) + if(node.tag_ == Tag("tag:yaml.org,2002:set")) { ///YAML sets are mapping with null values. Node.Pair[] pairs; @@ -385,7 +385,7 @@ Node representNodes(ref Node node, Representer representer) { pairs[idx] = Node.Pair(key, representNull(dummy, representer)); } - return representer.representMapping(node.tag.get, pairs); + return representer.representMapping(node.tag_.get, pairs); } else { @@ -423,15 +423,15 @@ Node representPairs(ref Node node, Representer representer) return nodes; } - if(node.tag == Tag("tag:yaml.org,2002:omap")) + if(node.tag_ == Tag("tag:yaml.org,2002:omap")) { enforce(!hasDuplicates(pairs), new RepresenterException("Duplicate entry in an ordered map")); - return representer.representSequence(node.tag.get, mapToSequence(pairs)); + return representer.representSequence(node.tag_.get, mapToSequence(pairs)); } - else if(node.tag == Tag("tag:yaml.org,2002:pairs")) + else if(node.tag_ == Tag("tag:yaml.org,2002:pairs")) { - return representer.representSequence(node.tag.get, mapToSequence(pairs)); + return representer.representSequence(node.tag_.get, mapToSequence(pairs)); } else { diff --git a/dyaml/serializer.d b/dyaml/serializer.d index de6f511..f318c36 100644 --- a/dyaml/serializer.d +++ b/dyaml/serializer.d @@ -196,16 +196,16 @@ struct Serializer Tag detectedTag = resolver_.resolve(NodeID.Scalar, Tag(null), value, true); Tag defaultTag = resolver_.resolve(NodeID.Scalar, Tag(null), value, false); - emitter_.emit(scalarEvent(Mark(), Mark(), aliased, node.tag, - [node.tag == detectedTag, node.tag == defaultTag], + emitter_.emit(scalarEvent(Mark(), Mark(), aliased, node.tag_, + [node.tag_ == detectedTag, node.tag_ == defaultTag], value, ScalarStyle.Invalid)); return; } if(node.isSequence) { auto defaultTag = resolver_.defaultSequenceTag; - bool implicit = node.tag == defaultTag; - emitter_.emit(sequenceStartEvent(Mark(), Mark(), aliased, node.tag, + bool implicit = node.tag_ == defaultTag; + emitter_.emit(sequenceStartEvent(Mark(), Mark(), aliased, node.tag_, implicit, CollectionStyle.Invalid)); foreach(ref Node item; node) { @@ -217,8 +217,8 @@ struct Serializer if(node.isMapping) { auto defaultTag = resolver_.defaultMappingTag; - bool implicit = node.tag == defaultTag; - emitter_.emit(mappingStartEvent(Mark(), Mark(), aliased, node.tag, + bool implicit = node.tag_ == defaultTag; + emitter_.emit(mappingStartEvent(Mark(), Mark(), aliased, node.tag_, implicit, CollectionStyle.Invalid)); foreach(ref Node key, ref Node value; node) { diff --git a/test/src/resolver.d b/test/src/resolver.d index 6dc6f30..ac079c2 100644 --- a/test/src/resolver.d +++ b/test/src/resolver.d @@ -40,7 +40,7 @@ void testImplicitResolver(bool verbose, string dataFilename, string detectFilena foreach(ref Node scalar; node) { assert(scalar.isScalar); - assert(scalar.tag.get == correctTag); + assert(scalar.tag == correctTag); } }