diff options
Diffstat (limited to 'src/ext_depends/D-YAML/source/dyaml/event.d')
-rw-r--r-- | src/ext_depends/D-YAML/source/dyaml/event.d | 152 |
1 files changed, 126 insertions, 26 deletions
diff --git a/src/ext_depends/D-YAML/source/dyaml/event.d b/src/ext_depends/D-YAML/source/dyaml/event.d index f4a747f..36638e3 100644 --- a/src/ext_depends/D-YAML/source/dyaml/event.d +++ b/src/ext_depends/D-YAML/source/dyaml/event.d @@ -10,6 +10,7 @@ */ module dyaml.event; +import std.algorithm; import std.array; import std.conv; @@ -43,42 +44,30 @@ enum EventID : ubyte */ struct Event { - @disable int opCmp(ref Event); - ///Value of the event, if any. string value; ///Start position of the event in file/stream. Mark startMark; ///End position of the event in file/stream. Mark endMark; - union - { - struct - { - ///Anchor of the event, if any. - string _anchor; - ///Tag of the event, if any. - string _tag; - } - ///Tag directives, if this is a DocumentStart. - //TagDirectives tagDirectives; - TagDirective[] _tagDirectives; - } + ///Anchor of the event, if any. + string _anchor; + ///Tag of the event, if any. + string _tag; + ///Tag directives, if this is a DocumentStart. + TagDirective[] _tagDirectives; ///Event type. EventID id = EventID.invalid; ///Style of scalar event, if this is a scalar event. ScalarStyle scalarStyle = ScalarStyle.invalid; - union - { - ///Should the tag be implicitly resolved? - bool implicit; - /** - * Is this document event explicit? - * - * Used if this is a DocumentStart or DocumentEnd. - */ - bool explicitDocument; - } + ///Should the tag be implicitly resolved? + bool implicit; + /** + * Is this document event explicit? + * + * Used if this is a DocumentStart or DocumentEnd. + */ + alias explicitDocument = implicit; ///Collection style, if this is a SequenceStart or MappingStart. CollectionStyle collectionStyle = CollectionStyle.invalid; @@ -102,6 +91,117 @@ struct Event assert(id == EventID.documentStart, "Only DocumentStart events have tag directives."); return _tagDirectives; } + void toString(W)(ref W writer) const + { + import std.algorithm.iteration : substitute; + import std.format : formattedWrite; + import std.range : put; + final switch (id) + { + case EventID.scalar: + put(writer, "=VAL "); + if (anchor != "") + { + writer.formattedWrite!"&%s " (anchor); + } + if (tag != "") + { + writer.formattedWrite!"<%s> " (tag); + } + final switch(scalarStyle) + { + case ScalarStyle.singleQuoted: + put(writer, "'"); + break; + case ScalarStyle.doubleQuoted: + put(writer, "\""); + break; + case ScalarStyle.literal: + put(writer, "|"); + break; + case ScalarStyle.folded: + put(writer, ">"); + break; + case ScalarStyle.invalid: //default to plain + case ScalarStyle.plain: + put(writer, ":"); + break; + } + if (value != "") + { + writer.formattedWrite!"%s"(value.substitute("\n", "\\n", `\`, `\\`, "\r", "\\r", "\t", "\\t", "\b", "\\b")); + } + break; + case EventID.streamStart: + put(writer, "+STR"); + break; + case EventID.documentStart: + put(writer, "+DOC"); + if (explicitDocument) + { + put(writer, " ---"); + } + break; + case EventID.mappingStart: + put(writer, "+MAP"); + if (collectionStyle == CollectionStyle.flow) + { + put(writer, " {}"); + } + if (anchor != "") + { + put(writer, " &"); + put(writer, anchor); + } + if (tag != "") + { + put(writer, " <"); + put(writer, tag); + put(writer, ">"); + } + break; + case EventID.sequenceStart: + put(writer, "+SEQ"); + if (collectionStyle == CollectionStyle.flow) + { + put(writer, " []"); + } + if (anchor != "") + { + put(writer, " &"); + put(writer, anchor); + } + if (tag != "") + { + put(writer, " <"); + put(writer, tag); + put(writer, ">"); + } + break; + case EventID.streamEnd: + put(writer, "-STR"); + break; + case EventID.documentEnd: + put(writer, "-DOC"); + if (explicitDocument) + { + put(writer, " ..."); + } + break; + case EventID.mappingEnd: + put(writer, "-MAP"); + break; + case EventID.sequenceEnd: + put(writer, "-SEQ"); + break; + case EventID.alias_: + put(writer, "=ALI *"); + put(writer, anchor); + break; + case EventID.invalid: + assert(0, "Invalid EventID produced"); + } + } } /** |