Import YamlDotNet.

This commit is contained in:
2022-12-12 22:23:49 +08:00
parent f559cea826
commit 1477e907e6
462 changed files with 27142 additions and 0 deletions

View File

@@ -0,0 +1,111 @@
// This file is part of YamlDotNet - A .NET library for YAML.
// Copyright (c) Antoine Aubry and contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to do
// so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using YamlDotNet.Core;
namespace YamlDotNet.RepresentationModel
{
/// <summary>
/// Manages the state of a <see cref="YamlDocument" /> while it is loading.
/// </summary>
internal class DocumentLoadingState
{
private readonly IDictionary<AnchorName, YamlNode> anchors = new Dictionary<AnchorName, YamlNode>();
private readonly IList<YamlNode> nodesWithUnresolvedAliases = new List<YamlNode>();
/// <summary>
/// Adds the specified node to the anchor list.
/// </summary>
/// <param name="node">The node.</param>
public void AddAnchor(YamlNode node)
{
if (node.Anchor.IsEmpty)
{
throw new ArgumentException("The specified node does not have an anchor");
}
if (anchors.ContainsKey(node.Anchor))
{
anchors[node.Anchor] = node;
}
else
{
anchors.Add(node.Anchor, node);
}
}
/// <summary>
/// Gets the node with the specified anchor.
/// </summary>
/// <param name="anchor">The anchor.</param>
/// <param name="start">The start position.</param>
/// <param name="end">The end position.</param>
/// <returns></returns>
/// <exception cref="AnchorNotFoundException">if there is no node with that anchor.</exception>
public YamlNode GetNode(AnchorName anchor, Mark start, Mark end)
{
if (anchors.TryGetValue(anchor, out var target))
{
return target;
}
else
{
throw new AnchorNotFoundException(start, end, $"The anchor '{anchor}' does not exists");
}
}
/// <summary>
/// Gets the node with the specified anchor.
/// </summary>
/// <param name="anchor">The anchor.</param>
/// <param name="node">The node that was retrieved.</param>
/// <returns>true if the anchor was found; otherwise false.</returns>
public bool TryGetNode(AnchorName anchor, [NotNullWhen(true)] out YamlNode? node)
{
return anchors.TryGetValue(anchor, out node);
}
/// <summary>
/// Adds the specified node to the collection of nodes with unresolved aliases.
/// </summary>
/// <param name="node">
/// The <see cref="YamlNode"/> that has unresolved aliases.
/// </param>
public void AddNodeWithUnresolvedAliases(YamlNode node)
{
nodesWithUnresolvedAliases.Add(node);
}
/// <summary>
/// Resolves the aliases that could not be resolved while loading the document.
/// </summary>
public void ResolveAliases()
{
foreach (var node in nodesWithUnresolvedAliases)
{
node.ResolveAliases(this);
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 76a242df6680b9742a2670bde85baa6e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,38 @@
// This file is part of YamlDotNet - A .NET library for YAML.
// Copyright (c) Antoine Aubry and contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to do
// so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
using System.Collections.Generic;
using YamlDotNet.Core;
namespace YamlDotNet.RepresentationModel
{
/// <summary>
/// Holds state that is used when emitting a stream.
/// </summary>
internal class EmitterState
{
/// <summary>
/// Gets the already emitted anchors.
/// </summary>
/// <value>The emitted anchors.</value>
public HashSet<AnchorName> EmittedAnchors { get; } = new HashSet<AnchorName>();
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c3761b6b22a04a24fade56273bbb3c5b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,69 @@
// This file is part of YamlDotNet - A .NET library for YAML.
// Copyright (c) Antoine Aubry and contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to do
// so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
namespace YamlDotNet.RepresentationModel
{
/// <summary>
/// Defines the method needed to be able to visit Yaml elements.
/// </summary>
public interface IYamlVisitor
{
/// <summary>
/// Visits a <see cref="YamlStream"/>.
/// </summary>
/// <param name="stream">
/// The <see cref="YamlStream"/> that is being visited.
/// </param>
void Visit(YamlStream stream);
/// <summary>
/// Visits a <see cref="YamlDocument"/>.
/// </summary>
/// <param name="document">
/// The <see cref="YamlDocument"/> that is being visited.
/// </param>
void Visit(YamlDocument document);
/// <summary>
/// Visits a <see cref="YamlScalarNode"/>.
/// </summary>
/// <param name="scalar">
/// The <see cref="YamlScalarNode"/> that is being visited.
/// </param>
void Visit(YamlScalarNode scalar);
/// <summary>
/// Visits a <see cref="YamlSequenceNode"/>.
/// </summary>
/// <param name="sequence">
/// The <see cref="YamlSequenceNode"/> that is being visited.
/// </param>
void Visit(YamlSequenceNode sequence);
/// <summary>
/// Visits a <see cref="YamlMappingNode"/>.
/// </summary>
/// <param name="mapping">
/// The <see cref="YamlMappingNode"/> that is being visited.
/// </param>
void Visit(YamlMappingNode mapping);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e12b6dd8690a6674696c7a997fdbd895
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,136 @@
// This file is part of YamlDotNet - A .NET library for YAML.
// Copyright (c) Antoine Aubry and contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to do
// so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
using System;
using System.IO;
using YamlDotNet.Core;
using YamlDotNet.Core.Events;
namespace YamlDotNet.RepresentationModel
{
/// <summary>
/// Represents a LibYAML event stream.
/// </summary>
public class LibYamlEventStream
{
private readonly IParser parser;
/// <summary>
/// Initializes a new instance of the <see cref="LibYamlEventStream"/> class
/// from the specified <see cref="IParser"/>.
/// </summary>
public LibYamlEventStream(IParser iParser)
{
parser = iParser ?? throw new ArgumentNullException(nameof(iParser));
}
public void WriteTo(TextWriter textWriter)
{
while (parser.MoveNext())
{
switch (parser.Current)
{
case AnchorAlias anchorAlias:
textWriter.Write("=ALI *");
textWriter.Write(anchorAlias.Value);
break;
case DocumentEnd documentEnd:
textWriter.Write("-DOC");
if (!documentEnd.IsImplicit)
{
textWriter.Write(" ...");
}
break;
case DocumentStart documentStart:
textWriter.Write("+DOC");
if (!documentStart.IsImplicit)
{
textWriter.Write(" ---");
}
break;
case MappingEnd _:
textWriter.Write("-MAP");
break;
case MappingStart mappingStart:
textWriter.Write("+MAP");
WriteAnchorAndTag(textWriter, mappingStart);
break;
case Scalar scalar:
textWriter.Write("=VAL");
WriteAnchorAndTag(textWriter, scalar);
switch (scalar.Style)
{
case ScalarStyle.DoubleQuoted: textWriter.Write(" \""); break;
case ScalarStyle.SingleQuoted: textWriter.Write(" '"); break;
case ScalarStyle.Folded: textWriter.Write(" >"); break;
case ScalarStyle.Literal: textWriter.Write(" |"); break;
default: textWriter.Write(" :"); break;
}
foreach (var character in scalar.Value)
{
switch (character)
{
case '\b': textWriter.Write("\\b"); break;
case '\t': textWriter.Write("\\t"); break;
case '\n': textWriter.Write("\\n"); break;
case '\r': textWriter.Write("\\r"); break;
case '\\': textWriter.Write("\\\\"); break;
default: textWriter.Write(character); break;
}
}
break;
case SequenceEnd _:
textWriter.Write("-SEQ");
break;
case SequenceStart sequenceStart:
textWriter.Write("+SEQ");
WriteAnchorAndTag(textWriter, sequenceStart);
break;
case StreamEnd _:
textWriter.Write("-STR");
break;
case StreamStart _:
textWriter.Write("+STR");
break;
}
textWriter.WriteLine();
}
}
private void WriteAnchorAndTag(TextWriter textWriter, NodeEvent nodeEvent)
{
if (!nodeEvent.Anchor.IsEmpty)
{
textWriter.Write(" &");
textWriter.Write(nodeEvent.Anchor);
}
if (!nodeEvent.Tag.IsEmpty)
{
textWriter.Write(" <");
textWriter.Write(nodeEvent.Tag.Value);
textWriter.Write(">");
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a2468528a04d1c74f8301b7e6326e3ae
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,120 @@
// This file is part of YamlDotNet - A .NET library for YAML.
// Copyright (c) Antoine Aubry and contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to do
// so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
using System;
using System.Collections.Generic;
using YamlDotNet.Core;
namespace YamlDotNet.RepresentationModel
{
/// <summary>
/// Represents an alias node in the YAML document.
/// </summary>
internal class YamlAliasNode : YamlNode
{
/// <summary>
/// Initializes a new instance of the <see cref="YamlAliasNode"/> class.
/// </summary>
/// <param name="anchor">The anchor.</param>
internal YamlAliasNode(AnchorName anchor)
{
Anchor = anchor;
}
/// <summary>
/// Resolves the aliases that could not be resolved when the node was created.
/// </summary>
/// <param name="state">The state of the document.</param>
internal override void ResolveAliases(DocumentLoadingState state)
{
throw new NotSupportedException("Resolving an alias on an alias node does not make sense");
}
/// <summary>
/// Saves the current node to the specified emitter.
/// </summary>
/// <param name="emitter">The emitter where the node is to be saved.</param>
/// <param name="state">The state.</param>
internal override void Emit(IEmitter emitter, EmitterState state)
{
throw new NotSupportedException("A YamlAliasNode is an implementation detail and should never be saved.");
}
/// <summary>
/// Accepts the specified visitor by calling the appropriate Visit method on it.
/// </summary>
/// <param name="visitor">
/// A <see cref="IYamlVisitor"/>.
/// </param>
public override void Accept(IYamlVisitor visitor)
{
throw new NotSupportedException("A YamlAliasNode is an implementation detail and should never be visited.");
}
/// <summary />
public override bool Equals(object? obj)
{
return obj is YamlAliasNode other
&& Equals(other)
&& Equals(Anchor, other.Anchor);
}
/// <summary>
/// Serves as a hash function for a particular type.
/// </summary>
/// <returns>
/// A hash code for the current <see cref="T:System.Object"/>.
/// </returns>
public override int GetHashCode()
{
return base.GetHashCode();
}
/// <summary>
/// Returns a <see cref="string"/> that represents this instance.
/// </summary>
/// <returns>
/// A <see cref="string"/> that represents this instance.
/// </returns>
internal override string ToString(RecursionLevel level)
{
return "*" + Anchor;
}
/// <summary>
/// Recursively enumerates all the nodes from the document, starting on the current node,
/// and throwing <see cref="MaximumRecursionLevelReachedException"/>
/// if <see cref="RecursionLevel.Maximum"/> is reached.
/// </summary>
internal override IEnumerable<YamlNode> SafeAllNodes(RecursionLevel level)
{
yield return this;
}
/// <summary>
/// Gets the type of node.
/// </summary>
public override YamlNodeType NodeType
{
get { return YamlNodeType.Alias; }
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 72c7427f0fab35849b7545d301debcd5
timeCreated: 1427145264
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,211 @@
// This file is part of YamlDotNet - A .NET library for YAML.
// Copyright (c) Antoine Aubry and contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to do
// so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using YamlDotNet.Core;
using YamlDotNet.Core.Events;
namespace YamlDotNet.RepresentationModel
{
/// <summary>
/// Represents an YAML document.
/// </summary>
public class YamlDocument
{
/// <summary>
/// Gets or sets the root node.
/// </summary>
/// <value>The root node.</value>
public YamlNode RootNode { get; private set; }
/// <summary>
/// Initializes a new instance of the <see cref="YamlDocument"/> class.
/// </summary>
public YamlDocument(YamlNode rootNode)
{
RootNode = rootNode;
}
/// <summary>
/// Initializes a new instance of the <see cref="YamlDocument"/> class with a single scalar node.
/// </summary>
public YamlDocument(string rootNode)
{
RootNode = new YamlScalarNode(rootNode);
}
/// <summary>
/// Initializes a new instance of the <see cref="YamlDocument"/> class.
/// </summary>
internal YamlDocument(IParser parser)
{
var state = new DocumentLoadingState();
parser.Consume<DocumentStart>();
while (!parser.TryConsume<DocumentEnd>(out var _))
{
Debug.Assert(RootNode == null);
RootNode = YamlNode.ParseNode(parser, state);
if (RootNode is YamlAliasNode)
{
throw new YamlException("A document cannot contain only an alias");
}
}
state.ResolveAliases();
// Throw should not happen unless the parser has a bug
RootNode = RootNode ?? throw new ArgumentException("Atempted to parse an empty document");
}
/// <summary>
/// Visitor that assigns anchors to nodes that are referenced more than once.
/// Existing anchors are preserved as much as possible.
/// </summary>
private class AnchorAssigningVisitor : YamlVisitorBase
{
private readonly HashSet<AnchorName> existingAnchors = new HashSet<AnchorName>();
/// <summary>
/// Key: Node, Value: IsDuplicate
/// </summary>
private readonly Dictionary<YamlNode, bool> visitedNodes = new Dictionary<YamlNode, bool>();
public void AssignAnchors(YamlDocument document)
{
existingAnchors.Clear();
visitedNodes.Clear();
document.Accept(this);
var random = new Random();
foreach (var visitedNode in visitedNodes)
{
if (visitedNode.Value)
{
AnchorName anchor;
// If the existing anchor is not already used, we can have it
if (!visitedNode.Key.Anchor.IsEmpty && !existingAnchors.Contains(visitedNode.Key.Anchor))
{
anchor = visitedNode.Key.Anchor;
}
else
{
do
{
anchor = new AnchorName(random.Next().ToString(CultureInfo.InvariantCulture));
} while (existingAnchors.Contains(anchor));
}
existingAnchors.Add(anchor);
visitedNode.Key.Anchor = anchor;
}
}
}
/// <summary>
/// Returns whether the visited node is a duplicate.
/// </summary>
private bool VisitNodeAndFindDuplicates(YamlNode node)
{
if (visitedNodes.TryGetValue(node, out var isDuplicate))
{
if (!isDuplicate)
{
visitedNodes[node] = true;
}
return !isDuplicate;
}
else
{
visitedNodes.Add(node, false);
return false;
}
}
public override void Visit(YamlScalarNode scalar)
{
VisitNodeAndFindDuplicates(scalar);
}
public override void Visit(YamlMappingNode mapping)
{
if (!VisitNodeAndFindDuplicates(mapping))
{
base.Visit(mapping);
}
}
public override void Visit(YamlSequenceNode sequence)
{
if (!VisitNodeAndFindDuplicates(sequence))
{
base.Visit(sequence);
}
}
}
private void AssignAnchors()
{
var visitor = new AnchorAssigningVisitor();
visitor.AssignAnchors(this);
}
internal void Save(IEmitter emitter, bool assignAnchors = true)
{
if (assignAnchors)
{
AssignAnchors();
}
emitter.Emit(new DocumentStart());
RootNode.Save(emitter, new EmitterState());
emitter.Emit(new DocumentEnd(false));
}
/// <summary>
/// Accepts the specified visitor by calling the appropriate Visit method on it.
/// </summary>
/// <param name="visitor">
/// A <see cref="IYamlVisitor"/>.
/// </param>
public void Accept(IYamlVisitor visitor)
{
visitor.Visit(this);
}
/// <summary>
/// Gets all nodes from the document.
/// <see cref="MaximumRecursionLevelReachedException"/> is thrown if an infinite recursion is detected.
/// </summary>
public IEnumerable<YamlNode> AllNodes
{
get
{
return RootNode.AllNodes;
}
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: aa500eae79de1e8429a325722afbf4e8
timeCreated: 1427145265
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 283c72dc1a159584988a79dd9d0a0a93
timeCreated: 1427145263
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,236 @@
// This file is part of YamlDotNet - A .NET library for YAML.
// Copyright (c) Antoine Aubry and contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to do
// so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
using System;
using System.Collections.Generic;
using System.Linq;
using YamlDotNet.Core;
using YamlDotNet.Core.Events;
namespace YamlDotNet.RepresentationModel
{
/// <summary>
/// Represents a single node in the YAML document.
/// </summary>
public abstract class YamlNode
{
private const int MaximumRecursionLevel = 1000;
internal const string MaximumRecursionLevelReachedToStringValue = "WARNING! INFINITE RECURSION!";
/// <summary>
/// Gets or sets the anchor of the node.
/// </summary>
/// <value>The anchor.</value>
public AnchorName Anchor { get; set; }
/// <summary>
/// Gets or sets the tag of the node.
/// </summary>
/// <value>The tag.</value>
public TagName Tag { get; set; }
/// <summary>
/// Gets the position in the input stream where the event that originated the node starts.
/// </summary>
public Mark Start { get; private set; } = Mark.Empty;
/// <summary>
/// Gets the position in the input stream where the event that originated the node ends.
/// </summary>
public Mark End { get; private set; } = Mark.Empty;
/// <summary>
/// Loads the specified event.
/// </summary>
/// <param name="yamlEvent">The event.</param>
/// <param name="state">The state of the document.</param>
internal void Load(NodeEvent yamlEvent, DocumentLoadingState state)
{
Tag = yamlEvent.Tag;
if (!yamlEvent.Anchor.IsEmpty)
{
Anchor = yamlEvent.Anchor;
state.AddAnchor(this);
}
Start = yamlEvent.Start;
End = yamlEvent.End;
}
/// <summary>
/// Parses the node represented by the next event in <paramref name="parser" />.
/// </summary>
/// <returns>Returns the node that has been parsed.</returns>
internal static YamlNode ParseNode(IParser parser, DocumentLoadingState state)
{
if (parser.Accept<Scalar>(out var _))
{
return new YamlScalarNode(parser, state);
}
if (parser.Accept<SequenceStart>(out var _))
{
return new YamlSequenceNode(parser, state);
}
if (parser.Accept<MappingStart>(out var _))
{
return new YamlMappingNode(parser, state);
}
if (parser.TryConsume<AnchorAlias>(out var alias))
{
return state.TryGetNode(alias.Value, out var node) ? node : new YamlAliasNode(alias.Value);
}
throw new ArgumentException("The current event is of an unsupported type.", nameof(parser));
}
/// <summary>
/// Resolves the aliases that could not be resolved when the node was created.
/// </summary>
/// <param name="state">The state of the document.</param>
internal abstract void ResolveAliases(DocumentLoadingState state);
/// <summary>
/// Saves the current node to the specified emitter.
/// </summary>
/// <param name="emitter">The emitter where the node is to be saved.</param>
/// <param name="state">The state.</param>
internal void Save(IEmitter emitter, EmitterState state)
{
if (!Anchor.IsEmpty && !state.EmittedAnchors.Add(Anchor))
{
emitter.Emit(new AnchorAlias(Anchor));
}
else
{
Emit(emitter, state);
}
}
/// <summary>
/// Saves the current node to the specified emitter.
/// </summary>
/// <param name="emitter">The emitter where the node is to be saved.</param>
/// <param name="state">The state.</param>
internal abstract void Emit(IEmitter emitter, EmitterState state);
/// <summary>
/// Accepts the specified visitor by calling the appropriate Visit method on it.
/// </summary>
/// <param name="visitor">
/// A <see cref="IYamlVisitor"/>.
/// </param>
public abstract void Accept(IYamlVisitor visitor);
public override string ToString()
{
var level = new RecursionLevel(MaximumRecursionLevel);
return ToString(level);
}
internal abstract string ToString(RecursionLevel level);
/// <summary>
/// Gets all nodes from the document, starting on the current node.
/// <see cref="MaximumRecursionLevelReachedException"/> is thrown if an infinite recursion is detected.
/// </summary>
public IEnumerable<YamlNode> AllNodes
{
get
{
var level = new RecursionLevel(MaximumRecursionLevel);
return SafeAllNodes(level);
}
}
/// <summary>
/// When implemented, recursively enumerates all the nodes from the document, starting on the current node.
/// If <see cref="RecursionLevel.Maximum"/> is reached, a <see cref="MaximumRecursionLevelReachedException"/> is thrown
/// instead of continuing and crashing with a <see cref="StackOverflowException"/>.
/// </summary>
internal abstract IEnumerable<YamlNode> SafeAllNodes(RecursionLevel level);
/// <summary>
/// Gets the type of node.
/// </summary>
public abstract YamlNodeType NodeType
{
get;
}
/// <summary>
/// Performs an implicit conversion from <see cref="string"/> to <see cref="YamlNode"/>.
/// </summary>
/// <param name="value">The value.</param>
/// <returns>The result of the conversion.</returns>
public static implicit operator YamlNode(string value)
{
return new YamlScalarNode(value);
}
/// <summary>
/// Performs an implicit conversion from string[] to <see cref="YamlNode"/>.
/// </summary>
/// <param name="sequence">The value.</param>
/// <returns>The result of the conversion.</returns>
public static implicit operator YamlNode(string[] sequence)
{
return new YamlSequenceNode(sequence.Select(i => (YamlNode)i));
}
/// <summary>
/// Converts a <see cref="YamlScalarNode" /> to a string by returning its value.
/// </summary>
public static explicit operator string?(YamlNode node)
{
return node is YamlScalarNode scalar
? scalar.Value
: throw new ArgumentException($"Attempted to convert a '{node.NodeType}' to string. This conversion is valid only for Scalars.");
}
/// <summary>
/// Gets the nth element in a <see cref="YamlSequenceNode" />.
/// </summary>
public YamlNode this[int index]
{
get
{
return this is YamlSequenceNode sequence
? sequence.Children[index]
: throw new ArgumentException($"Accessed '{NodeType}' with an invalid index: {index}. Only Sequences can be indexed by number.");
}
}
/// <summary>
/// Gets the value associated with a key in a <see cref="YamlMappingNode" />.
/// </summary>
public YamlNode this[YamlNode key]
{
get
{
return this is YamlMappingNode mapping
? mapping.Children[key]
: throw new ArgumentException($"Accessed '{NodeType}' with an invalid index: {key}. Only Mappings can be indexed by key.");
}
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: b80625eae8f97124f832aed15c4c6b57
timeCreated: 1427145265
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,48 @@
// This file is part of YamlDotNet - A .NET library for YAML.
// Copyright (c) Antoine Aubry and contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to do
// so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
namespace YamlDotNet.RepresentationModel
{
/// <summary>
/// Comparer that is based on identity comparisons.
/// </summary>
public sealed class YamlNodeIdentityEqualityComparer : IEqualityComparer<YamlNode>
{
#region IEqualityComparer<YamlNode> Members
/// <summary />
public bool Equals([AllowNull] YamlNode x, [AllowNull] YamlNode y)
{
return ReferenceEquals(x, y);
}
/// <summary />
public int GetHashCode(YamlNode obj)
{
return obj.GetHashCode();
}
#endregion
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 70ec622c4d503a448ba4d5410c55d8bd
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,49 @@
// This file is part of YamlDotNet - A .NET library for YAML.
// Copyright (c) Antoine Aubry and contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to do
// so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
namespace YamlDotNet.RepresentationModel
{
/// <summary>
/// Specifies the type of node in the representation model.
/// </summary>
public enum YamlNodeType
{
/// <summary>
/// The node is a <see cref="YamlAliasNode"/>.
/// </summary>
Alias,
/// <summary>
/// The node is a <see cref="YamlMappingNode"/>.
/// </summary>
Mapping,
/// <summary>
/// The node is a <see cref="YamlScalarNode"/>.
/// </summary>
Scalar,
/// <summary>
/// The node is a <see cref="YamlSequenceNode"/>.
/// </summary>
Sequence
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6fedd304363f0ee4a9d32ea69940e2c9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,180 @@
// This file is part of YamlDotNet - A .NET library for YAML.
// Copyright (c) Antoine Aubry and contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to do
// so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using YamlDotNet.Core;
using YamlDotNet.Core.Events;
using YamlDotNet.Serialization;
using static YamlDotNet.Core.HashCode;
namespace YamlDotNet.RepresentationModel
{
/// <summary>
/// Represents a scalar node in the YAML document.
/// </summary>
[DebuggerDisplay("{Value}")]
public sealed class YamlScalarNode : YamlNode, IYamlConvertible
{
/// <summary>
/// Gets or sets the value of the node.
/// </summary>
/// <value>The value.</value>
public string? Value { get; set; }
/// <summary>
/// Gets or sets the style of the node.
/// </summary>
/// <value>The style.</value>
public ScalarStyle Style { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="YamlScalarNode"/> class.
/// </summary>
internal YamlScalarNode(IParser parser, DocumentLoadingState state)
{
Load(parser, state);
}
private void Load(IParser parser, DocumentLoadingState state)
{
var scalar = parser.Consume<Scalar>();
Load(scalar, state);
Value = scalar.Value;
Style = scalar.Style;
}
/// <summary>
/// Initializes a new instance of the <see cref="YamlScalarNode"/> class.
/// </summary>
public YamlScalarNode()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="YamlScalarNode"/> class.
/// </summary>
/// <param name="value">The value.</param>
public YamlScalarNode(string? value)
{
this.Value = value;
}
/// <summary>
/// Resolves the aliases that could not be resolved when the node was created.
/// </summary>
/// <param name="state">The state of the document.</param>
internal override void ResolveAliases(DocumentLoadingState state)
{
throw new NotSupportedException("Resolving an alias on a scalar node does not make sense");
}
/// <summary>
/// Saves the current node to the specified emitter.
/// </summary>
/// <param name="emitter">The emitter where the node is to be saved.</param>
/// <param name="state">The state.</param>
internal override void Emit(IEmitter emitter, EmitterState state)
{
emitter.Emit(new Scalar(Anchor, Tag, Value ?? string.Empty, Style, Tag.IsEmpty, false));
}
/// <summary>
/// Accepts the specified visitor by calling the appropriate Visit method on it.
/// </summary>
/// <param name="visitor">
/// A <see cref="IYamlVisitor"/>.
/// </param>
public override void Accept(IYamlVisitor visitor)
{
visitor.Visit(this);
}
/// <summary />
public override bool Equals(object? obj)
{
return obj is YamlScalarNode other
&& Equals(Tag, other.Tag)
&& Equals(Value, other.Value);
}
/// <summary>
/// Serves as a hash function for a particular type.
/// </summary>
/// <returns>
/// A hash code for the current <see cref="T:System.Object"/>.
/// </returns>
public override int GetHashCode()
{
return CombineHashCodes(Tag, Value);
}
/// <summary>
/// Performs an explicit conversion from <see cref="YamlScalarNode"/> to <see cref="string"/>.
/// </summary>
/// <param name="value">The value.</param>
/// <returns>The result of the conversion.</returns>
public static explicit operator string?(YamlScalarNode value)
{
return value.Value;
}
/// <summary>
/// Returns a <see cref="string"/> that represents this instance.
/// </summary>
/// <returns>
/// A <see cref="string"/> that represents this instance.
/// </returns>
internal override string ToString(RecursionLevel level)
{
return Value ?? string.Empty;
}
/// <summary>
/// Recursively enumerates all the nodes from the document, starting on the current node,
/// and throwing <see cref="MaximumRecursionLevelReachedException"/>
/// if <see cref="RecursionLevel.Maximum"/> is reached.
/// </summary>
internal override IEnumerable<YamlNode> SafeAllNodes(RecursionLevel level)
{
yield return this;
}
/// <summary>
/// Gets the type of node.
/// </summary>
public override YamlNodeType NodeType
{
get { return YamlNodeType.Scalar; }
}
void IYamlConvertible.Read(IParser parser, Type expectedType, ObjectDeserializer nestedObjectDeserializer)
{
Load(parser, new DocumentLoadingState());
}
void IYamlConvertible.Write(IEmitter emitter, ObjectSerializer nestedObjectSerializer)
{
Emit(emitter, new EmitterState());
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: d8152305d4536da4c91eb19aa04b401c
timeCreated: 1427145266
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 58e9eea9b495b2f478b639f1d20a8951
timeCreated: 1427145264
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,172 @@
// This file is part of YamlDotNet - A .NET library for YAML.
// Copyright (c) Antoine Aubry and contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to do
// so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
using System.Collections.Generic;
using System.IO;
using YamlDotNet.Core;
using YamlDotNet.Core.Events;
namespace YamlDotNet.RepresentationModel
{
/// <summary>
/// Represents an YAML stream.
/// </summary>
public class YamlStream : IEnumerable<YamlDocument>
{
private readonly IList<YamlDocument> documents = new List<YamlDocument>();
/// <summary>
/// Gets the documents inside the stream.
/// </summary>
/// <value>The documents.</value>
public IList<YamlDocument> Documents
{
get
{
return documents;
}
}
/// <summary>
/// Initializes a new instance of the <see cref="YamlStream"/> class.
/// </summary>
public YamlStream()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="YamlStream"/> class.
/// </summary>
public YamlStream(params YamlDocument[] documents)
: this((IEnumerable<YamlDocument>)documents)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="YamlStream"/> class.
/// </summary>
public YamlStream(IEnumerable<YamlDocument> documents)
{
foreach (var document in documents)
{
this.documents.Add(document);
}
}
/// <summary>
/// Adds the specified document to the <see cref="Documents"/> collection.
/// </summary>
/// <param name="document">The document.</param>
public void Add(YamlDocument document)
{
documents.Add(document);
}
/// <summary>
/// Loads the stream from the specified input.
/// </summary>
/// <param name="input">The input.</param>
public void Load(TextReader input)
{
Load(new Parser(input));
}
/// <summary>
/// Loads the stream from the specified <see cref="IParser"/>.
/// </summary>
public void Load(IParser parser)
{
documents.Clear();
parser.Consume<StreamStart>();
while (!parser.TryConsume<StreamEnd>(out var _))
{
var document = new YamlDocument(parser);
documents.Add(document);
}
}
/// <summary>
/// Saves the stream to the specified output.
/// </summary>
/// <param name="output">The output.</param>
public void Save(TextWriter output)
{
Save(output, true);
}
/// <summary>
/// Saves the stream to the specified output.
/// </summary>
/// <param name="output">The output.</param>
/// <param name="assignAnchors">Indicates whether or not to assign node anchors.</param>
public void Save(TextWriter output, bool assignAnchors)
{
Save(new Emitter(output), assignAnchors);
}
/// <summary>
/// Saves the stream to the specified emitter.
/// </summary>
/// <param name="emitter">The emitter.</param>
/// <param name="assignAnchors">Indicates whether or not to assign node anchors.</param>
public void Save(IEmitter emitter, bool assignAnchors)
{
emitter.Emit(new StreamStart());
foreach (var document in documents)
{
document.Save(emitter, assignAnchors);
}
emitter.Emit(new StreamEnd());
}
/// <summary>
/// Accepts the specified visitor by calling the appropriate Visit method on it.
/// </summary>
/// <param name="visitor">
/// A <see cref="IYamlVisitor"/>.
/// </param>
public void Accept(IYamlVisitor visitor)
{
visitor.Visit(this);
}
#region IEnumerable<YamlDocument> Members
/// <summary />
public IEnumerator<YamlDocument> GetEnumerator()
{
return documents.GetEnumerator();
}
#endregion
#region IEnumerable Members
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
#endregion
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 8da956833fe9bb440be293c2b18b1e29
timeCreated: 1427145265
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,233 @@
// This file is part of YamlDotNet - A .NET library for YAML.
// Copyright (c) Antoine Aubry and contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to do
// so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
using System;
namespace YamlDotNet.RepresentationModel
{
/// <summary>
/// Abstract implementation of <see cref="IYamlVisitor"/> that knows how to walk a complete Yaml object model.
/// </summary>
[Obsolete("Use YamlVisitorBase")]
public abstract class YamlVisitor : IYamlVisitor
{
/// <summary>
/// Called when this object is visiting a <see cref="YamlStream"/>.
/// </summary>
/// <param name="stream">
/// The <see cref="YamlStream"/> that is being visited.
/// </param>
protected virtual void Visit(YamlStream stream)
{
// Do nothing.
}
/// <summary>
/// Called after this object finishes visiting a <see cref="YamlStream"/>.
/// </summary>
/// <param name="stream">
/// The <see cref="YamlStream"/> that has been visited.
/// </param>
protected virtual void Visited(YamlStream stream)
{
// Do nothing.
}
/// <summary>
/// Called when this object is visiting a <see cref="YamlDocument"/>.
/// </summary>
/// <param name="document">
/// The <see cref="YamlDocument"/> that is being visited.
/// </param>
protected virtual void Visit(YamlDocument document)
{
// Do nothing.
}
/// <summary>
/// Called after this object finishes visiting a <see cref="YamlDocument"/>.
/// </summary>
/// <param name="document">
/// The <see cref="YamlDocument"/> that has been visited.
/// </param>
protected virtual void Visited(YamlDocument document)
{
// Do nothing.
}
/// <summary>
/// Called when this object is visiting a <see cref="YamlScalarNode"/>.
/// </summary>
/// <param name="scalar">
/// The <see cref="YamlScalarNode"/> that is being visited.
/// </param>
protected virtual void Visit(YamlScalarNode scalar)
{
// Do nothing.
}
/// <summary>
/// Called after this object finishes visiting a <see cref="YamlScalarNode"/>.
/// </summary>
/// <param name="scalar">
/// The <see cref="YamlScalarNode"/> that has been visited.
/// </param>
protected virtual void Visited(YamlScalarNode scalar)
{
// Do nothing.
}
/// <summary>
/// Called when this object is visiting a <see cref="YamlSequenceNode"/>.
/// </summary>
/// <param name="sequence">
/// The <see cref="YamlSequenceNode"/> that is being visited.
/// </param>
protected virtual void Visit(YamlSequenceNode sequence)
{
// Do nothing.
}
/// <summary>
/// Called after this object finishes visiting a <see cref="YamlSequenceNode"/>.
/// </summary>
/// <param name="sequence">
/// The <see cref="YamlSequenceNode"/> that has been visited.
/// </param>
protected virtual void Visited(YamlSequenceNode sequence)
{
// Do nothing.
}
/// <summary>
/// Called when this object is visiting a <see cref="YamlMappingNode"/>.
/// </summary>
/// <param name="mapping">
/// The <see cref="YamlMappingNode"/> that is being visited.
/// </param>
protected virtual void Visit(YamlMappingNode mapping)
{
// Do nothing.
}
/// <summary>
/// Called after this object finishes visiting a <see cref="YamlMappingNode"/>.
/// </summary>
/// <param name="mapping">
/// The <see cref="YamlMappingNode"/> that has been visited.
/// </param>
protected virtual void Visited(YamlMappingNode mapping)
{
// Do nothing.
}
/// <summary>
/// Visits every child of a <see cref="YamlStream"/>.
/// </summary>
/// <param name="stream">
/// The <see cref="YamlStream"/> that is being visited.
/// </param>
protected virtual void VisitChildren(YamlStream stream)
{
foreach (var document in stream.Documents)
{
document.Accept(this);
}
}
/// <summary>
/// Visits every child of a <see cref="YamlDocument"/>.
/// </summary>
/// <param name="document">
/// The <see cref="YamlDocument"/> that is being visited.
/// </param>
protected virtual void VisitChildren(YamlDocument document)
{
if (document.RootNode != null)
{
document.RootNode.Accept(this);
}
}
/// <summary>
/// Visits every child of a <see cref="YamlSequenceNode"/>.
/// </summary>
/// <param name="sequence">
/// The <see cref="YamlSequenceNode"/> that is being visited.
/// </param>
protected virtual void VisitChildren(YamlSequenceNode sequence)
{
foreach (var node in sequence.Children)
{
node.Accept(this);
}
}
/// <summary>
/// Visits every child of a <see cref="YamlMappingNode"/>.
/// </summary>
/// <param name="mapping">
/// The <see cref="YamlMappingNode"/> that is being visited.
/// </param>
protected virtual void VisitChildren(YamlMappingNode mapping)
{
foreach (var pair in mapping.Children)
{
pair.Key.Accept(this);
pair.Value.Accept(this);
}
}
void IYamlVisitor.Visit(YamlStream stream)
{
Visit(stream);
VisitChildren(stream);
Visited(stream);
}
void IYamlVisitor.Visit(YamlDocument document)
{
Visit(document);
VisitChildren(document);
Visited(document);
}
void IYamlVisitor.Visit(YamlScalarNode scalar)
{
Visit(scalar);
Visited(scalar);
}
void IYamlVisitor.Visit(YamlSequenceNode sequence)
{
Visit(sequence);
VisitChildren(sequence);
Visited(sequence);
}
void IYamlVisitor.Visit(YamlMappingNode mapping)
{
Visit(mapping);
VisitChildren(mapping);
Visited(mapping);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f0c6d456c0cd3544f98e1dac39bf17ed
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,151 @@
// This file is part of YamlDotNet - A .NET library for YAML.
// Copyright (c) Antoine Aubry and contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to do
// so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
namespace YamlDotNet.RepresentationModel
{
/// <summary>
/// Abstract implementation of <see cref="IYamlVisitor"/> that knows how to walk a complete YAML object model.
/// </summary>
public abstract class YamlVisitorBase : IYamlVisitor
{
/// <summary>
/// Called when this object is visiting a <see cref="YamlStream"/>.
/// </summary>
/// <param name="stream">
/// The <see cref="YamlStream"/> that is being visited.
/// </param>
public virtual void Visit(YamlStream stream)
{
VisitChildren(stream);
}
/// <summary>
/// Called when this object is visiting a <see cref="YamlDocument"/>.
/// </summary>
/// <param name="document">
/// The <see cref="YamlDocument"/> that is being visited.
/// </param>
public virtual void Visit(YamlDocument document)
{
VisitChildren(document);
}
/// <summary>
/// Called when this object is visiting a <see cref="YamlScalarNode"/>.
/// </summary>
/// <param name="scalar">
/// The <see cref="YamlScalarNode"/> that is being visited.
/// </param>
public virtual void Visit(YamlScalarNode scalar)
{
// Do nothing.
}
/// <summary>
/// Called when this object is visiting a <see cref="YamlSequenceNode"/>.
/// </summary>
/// <param name="sequence">
/// The <see cref="YamlSequenceNode"/> that is being visited.
/// </param>
public virtual void Visit(YamlSequenceNode sequence)
{
VisitChildren(sequence);
}
/// <summary>
/// Called when this object is visiting a <see cref="YamlMappingNode"/>.
/// </summary>
/// <param name="mapping">
/// The <see cref="YamlMappingNode"/> that is being visited.
/// </param>
public virtual void Visit(YamlMappingNode mapping)
{
VisitChildren(mapping);
}
/// <summary>
/// Called when this object is visiting a key-value pair.
/// </summary>
/// <param name="key">The left (key) <see cref="YamlNode"/> that is being visited.</param>
/// <param name="value">The right (value) <see cref="YamlNode"/> that is being visited.</param>
protected virtual void VisitPair(YamlNode key, YamlNode value)
{
key.Accept(this);
value.Accept(this);
}
/// <summary>
/// Visits every child of a <see cref="YamlStream"/>.
/// </summary>
/// <param name="stream">
/// The <see cref="YamlStream"/> that is being visited.
/// </param>
protected virtual void VisitChildren(YamlStream stream)
{
foreach (var document in stream.Documents)
{
document.Accept(this);
}
}
/// <summary>
/// Visits every child of a <see cref="YamlDocument"/>.
/// </summary>
/// <param name="document">
/// The <see cref="YamlDocument"/> that is being visited.
/// </param>
protected virtual void VisitChildren(YamlDocument document)
{
if (document.RootNode != null)
{
document.RootNode.Accept(this);
}
}
/// <summary>
/// Visits every child of a <see cref="YamlSequenceNode"/>.
/// </summary>
/// <param name="sequence">
/// The <see cref="YamlSequenceNode"/> that is being visited.
/// </param>
protected virtual void VisitChildren(YamlSequenceNode sequence)
{
foreach (var node in sequence.Children)
{
node.Accept(this);
}
}
/// <summary>
/// Visits every child of a <see cref="YamlMappingNode"/>.
/// </summary>
/// <param name="mapping">
/// The <see cref="YamlMappingNode"/> that is being visited.
/// </param>
protected virtual void VisitChildren(YamlMappingNode mapping)
{
foreach (var pair in mapping.Children)
{
VisitPair(pair.Key, pair.Value);
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2776bd25d70b784469150ddda10b614e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: