String representation of a Node's tag can now be accessed by the

user.
This commit is contained in:
Ferdinand Majerech 2011-10-20 15:48:21 +02:00
parent fb814c66c2
commit 33a376b038
4 changed files with 20 additions and 21 deletions

View file

@ -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;

View file

@ -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
{

View file

@ -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)
{

View file

@ -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);
}
}