Merge pull request #114 from Herringway/rawnode-removal

remove Node.rawNode and just use the constructor instead
merged-on-behalf-of: unknown
This commit is contained in:
The Dlang Bot 2018-04-25 07:31:38 +02:00 committed by GitHub
commit b44f96bd9f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 36 deletions

View file

@ -291,13 +291,17 @@ final class Constructor
{ {
static if(is(U : ScalarStyle)) static if(is(U : ScalarStyle))
{ {
return Node.rawNode((*delegates!T)[tag](node), start, tag, auto newNode = Node((*delegates!T)[tag](node), tag);
style, CollectionStyle.Invalid); newNode.startMark_ = start;
newNode.scalarStyle = style;
return newNode;
} }
else static if(is(U : CollectionStyle)) else static if(is(U : CollectionStyle))
{ {
return Node.rawNode((*delegates!T)[tag](node), start, tag, auto newNode = Node((*delegates!T)[tag](node), tag);
ScalarStyle.Invalid, style); newNode.startMark_ = start;
newNode.collectionStyle = style;
return newNode;
} }
else static assert(false); else static assert(false);
} }

View file

@ -193,7 +193,7 @@ struct Node
Value.allowed!T; Value.allowed!T;
} }
private: package:
// Stored value. // Stored value.
Value value_; Value value_;
// Start position of the node. // Start position of the node.
@ -1766,28 +1766,6 @@ struct Node
} }
package: package:
// Construct a node from raw data.
//
// Params: value = Value of the node.
// startMark = Start position of the node in file.
// tag = Tag of the node.
// scalarStyle = Scalar style of the node.
// collectionStyle = Collection style of the node.
//
// Returns: Constructed node.
static Node rawNode(Value value, const Mark startMark, const string tag,
const ScalarStyle scalarStyle,
const CollectionStyle collectionStyle) @safe
{
Node node;
node.setValue(value);
node.startMark_ = startMark;
node.tag_ = tag;
node.scalarStyle = scalarStyle;
node.collectionStyle = collectionStyle;
return node;
}
// Construct Node.Value from user defined type. // Construct Node.Value from user defined type.
static Value userValue(T)(T value) @trusted static Value userValue(T)(T value) @trusted

View file

@ -238,11 +238,12 @@ final class Representer
* Returns: The represented node. * Returns: The represented node.
*/ */
Node representScalar(string tag, string scalar, Node representScalar(string tag, string scalar,
ScalarStyle style = ScalarStyle.Invalid) @trusted ScalarStyle style = ScalarStyle.Invalid) @safe
{ {
if(style == ScalarStyle.Invalid){style = defaultScalarStyle_;} if(style == ScalarStyle.Invalid){style = defaultScalarStyle_;}
return Node.rawNode(Node.Value(scalar), Mark(), tag, style, auto newNode = Node(scalar, tag);
CollectionStyle.Invalid); newNode.scalarStyle = style;
return newNode;
} }
/// ///
@safe unittest @safe unittest
@ -291,7 +292,7 @@ final class Representer
* Throws: $(D RepresenterException) if a child could not be represented. * Throws: $(D RepresenterException) if a child could not be represented.
*/ */
Node representSequence(string tag, Node[] sequence, Node representSequence(string tag, Node[] sequence,
CollectionStyle style = CollectionStyle.Invalid) @trusted CollectionStyle style = CollectionStyle.Invalid) @safe
{ {
Node[] value; Node[] value;
value.length = sequence.length; value.length = sequence.length;
@ -314,8 +315,9 @@ final class Representer
? defaultCollectionStyle_ ? defaultCollectionStyle_
: bestStyle; : bestStyle;
} }
return Node.rawNode(Node.Value(value), Mark(), tag, auto newNode = Node(value, tag);
ScalarStyle.Invalid, style); newNode.collectionStyle = style;
return newNode;
} }
/// ///
@safe unittest @safe unittest
@ -365,7 +367,7 @@ final class Representer
* Throws: $(D RepresenterException) if a child could not be represented. * Throws: $(D RepresenterException) if a child could not be represented.
*/ */
Node representMapping(string tag, Node.Pair[] pairs, Node representMapping(string tag, Node.Pair[] pairs,
CollectionStyle style = CollectionStyle.Invalid) @trusted CollectionStyle style = CollectionStyle.Invalid) @safe
{ {
Node.Pair[] value; Node.Pair[] value;
value.length = pairs.length; value.length = pairs.length;
@ -396,8 +398,9 @@ final class Representer
? defaultCollectionStyle_ ? defaultCollectionStyle_
: bestStyle; : bestStyle;
} }
return Node.rawNode(Node.Value(value), Mark(), tag, auto newNode = Node(value, tag);
ScalarStyle.Invalid, style); newNode.collectionStyle = style;
return newNode;
} }
/// ///
@safe unittest @safe unittest