String representation of a Node's tag can now be accessed by the
user.
This commit is contained in:
parent
fb814c66c2
commit
33a376b038
13
dyaml/node.d
13
dyaml/node.d
|
@ -168,7 +168,9 @@ struct Node
|
||||||
Value value_;
|
Value value_;
|
||||||
///Start position of the node.
|
///Start position of the node.
|
||||||
Mark startMark_;
|
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_;
|
Tag tag_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -426,6 +428,9 @@ struct Node
|
||||||
///Is this node a user defined type?
|
///Is this node a user defined type?
|
||||||
@property bool isUserType() const {return isType!YAMLObject;}
|
@property bool isUserType() const {return isType!YAMLObject;}
|
||||||
|
|
||||||
|
///Return tag of the node.
|
||||||
|
@property string tag() const {return tag_.get;}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Equality test.
|
* Equality test.
|
||||||
*
|
*
|
||||||
|
@ -1244,12 +1249,6 @@ struct Node
|
||||||
*/
|
*/
|
||||||
@property bool isType(T)() const {return value_.type is typeid(T);}
|
@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:
|
private:
|
||||||
//Is the value an integer of some kind?
|
//Is the value an integer of some kind?
|
||||||
alias isType!long isInt;
|
alias isType!long isInt;
|
||||||
|
|
|
@ -300,7 +300,7 @@ final class Representer
|
||||||
new RepresenterException("No representer function for type "
|
new RepresenterException("No representer function for type "
|
||||||
~ type.toString() ~ " , cannot represent."));
|
~ type.toString() ~ " , cannot represent."));
|
||||||
Node result = representers_[type](data, this);
|
Node result = representers_[type](data, this);
|
||||||
if(!data.tag.isNull()){result.tag = data.tag;}
|
if(!data.tag_.isNull()){result.tag_ = data.tag_;}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -375,7 +375,7 @@ Node representSysTime(ref Node node, Representer representer)
|
||||||
Node representNodes(ref Node node, Representer representer)
|
Node representNodes(ref Node node, Representer representer)
|
||||||
{
|
{
|
||||||
auto nodes = node.get!(Node[]);
|
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.
|
///YAML sets are mapping with null values.
|
||||||
Node.Pair[] pairs;
|
Node.Pair[] pairs;
|
||||||
|
@ -385,7 +385,7 @@ Node representNodes(ref Node node, Representer representer)
|
||||||
{
|
{
|
||||||
pairs[idx] = Node.Pair(key, representNull(dummy, representer));
|
pairs[idx] = Node.Pair(key, representNull(dummy, representer));
|
||||||
}
|
}
|
||||||
return representer.representMapping(node.tag.get, pairs);
|
return representer.representMapping(node.tag_.get, pairs);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -423,15 +423,15 @@ Node representPairs(ref Node node, Representer representer)
|
||||||
return nodes;
|
return nodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(node.tag == Tag("tag:yaml.org,2002:omap"))
|
if(node.tag_ == Tag("tag:yaml.org,2002:omap"))
|
||||||
{
|
{
|
||||||
enforce(!hasDuplicates(pairs),
|
enforce(!hasDuplicates(pairs),
|
||||||
new RepresenterException("Duplicate entry in an ordered map"));
|
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
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -196,16 +196,16 @@ struct Serializer
|
||||||
Tag detectedTag = resolver_.resolve(NodeID.Scalar, Tag(null), value, true);
|
Tag detectedTag = resolver_.resolve(NodeID.Scalar, Tag(null), value, true);
|
||||||
Tag defaultTag = resolver_.resolve(NodeID.Scalar, Tag(null), value, false);
|
Tag defaultTag = resolver_.resolve(NodeID.Scalar, Tag(null), value, false);
|
||||||
|
|
||||||
emitter_.emit(scalarEvent(Mark(), Mark(), aliased, node.tag,
|
emitter_.emit(scalarEvent(Mark(), Mark(), aliased, node.tag_,
|
||||||
[node.tag == detectedTag, node.tag == defaultTag],
|
[node.tag_ == detectedTag, node.tag_ == defaultTag],
|
||||||
value, ScalarStyle.Invalid));
|
value, ScalarStyle.Invalid));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(node.isSequence)
|
if(node.isSequence)
|
||||||
{
|
{
|
||||||
auto defaultTag = resolver_.defaultSequenceTag;
|
auto defaultTag = resolver_.defaultSequenceTag;
|
||||||
bool implicit = node.tag == defaultTag;
|
bool implicit = node.tag_ == defaultTag;
|
||||||
emitter_.emit(sequenceStartEvent(Mark(), Mark(), aliased, node.tag,
|
emitter_.emit(sequenceStartEvent(Mark(), Mark(), aliased, node.tag_,
|
||||||
implicit, CollectionStyle.Invalid));
|
implicit, CollectionStyle.Invalid));
|
||||||
foreach(ref Node item; node)
|
foreach(ref Node item; node)
|
||||||
{
|
{
|
||||||
|
@ -217,8 +217,8 @@ struct Serializer
|
||||||
if(node.isMapping)
|
if(node.isMapping)
|
||||||
{
|
{
|
||||||
auto defaultTag = resolver_.defaultMappingTag;
|
auto defaultTag = resolver_.defaultMappingTag;
|
||||||
bool implicit = node.tag == defaultTag;
|
bool implicit = node.tag_ == defaultTag;
|
||||||
emitter_.emit(mappingStartEvent(Mark(), Mark(), aliased, node.tag,
|
emitter_.emit(mappingStartEvent(Mark(), Mark(), aliased, node.tag_,
|
||||||
implicit, CollectionStyle.Invalid));
|
implicit, CollectionStyle.Invalid));
|
||||||
foreach(ref Node key, ref Node value; node)
|
foreach(ref Node key, ref Node value; node)
|
||||||
{
|
{
|
||||||
|
|
|
@ -40,7 +40,7 @@ void testImplicitResolver(bool verbose, string dataFilename, string detectFilena
|
||||||
foreach(ref Node scalar; node)
|
foreach(ref Node scalar; node)
|
||||||
{
|
{
|
||||||
assert(scalar.isScalar);
|
assert(scalar.isScalar);
|
||||||
assert(scalar.tag.get == correctTag);
|
assert(scalar.tag == correctTag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue