diff --git a/YamlDotNet.Core/Constants.cs b/YamlDotNet.Core/Constants.cs
index ef522b0..d128666 100644
--- a/YamlDotNet.Core/Constants.cs
+++ b/YamlDotNet.Core/Constants.cs
@@ -19,26 +19,26 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
-using System;
-using YamlDotNet.Core.Tokens;
-
-namespace YamlDotNet.Core
-{
- ///
- /// Defines constants thar relate to the YAML specification.
- ///
- internal static class Constants
- {
- public static readonly TagDirective[] DefaultTagDirectives = new[]
- {
- new TagDirective("!", "!"),
- new TagDirective("!!", "tag:yaml.org,2002:"),
- };
-
- public const int MajorVersion = 1;
- public const int MinorVersion = 1;
-
- public const char HandleCharacter = '!';
- public const string DefaultHandle = "!";
- }
+using System;
+using YamlDotNet.Core.Tokens;
+
+namespace YamlDotNet.Core
+{
+ ///
+ /// Defines constants thar relate to the YAML specification.
+ ///
+ internal static class Constants
+ {
+ public static readonly TagDirective[] DefaultTagDirectives = new[]
+ {
+ new TagDirective("!", "!"),
+ new TagDirective("!!", "tag:yaml.org,2002:"),
+ };
+
+ public const int MajorVersion = 1;
+ public const int MinorVersion = 1;
+
+ public const char HandleCharacter = '!';
+ public const string DefaultHandle = "!";
+ }
}
\ No newline at end of file
diff --git a/YamlDotNet.Core/Emitter.cs b/YamlDotNet.Core/Emitter.cs
index 00ceebb..93a6ac2 100644
--- a/YamlDotNet.Core/Emitter.cs
+++ b/YamlDotNet.Core/Emitter.cs
@@ -764,7 +764,7 @@ namespace YamlDotNet.Core
{
WriteIndicator("...", true, false, false);
WriteIndent();
- }
+ }
state = EmitterState.YAML_EMIT_END_STATE;
}
@@ -1861,4 +1861,4 @@ namespace YamlDotNet.Core
}
}
}
-}
+}
diff --git a/YamlDotNet.Core/Events/AnchorAlias.cs b/YamlDotNet.Core/Events/AnchorAlias.cs
index af36540..75f4fc0 100644
--- a/YamlDotNet.Core/Events/AnchorAlias.cs
+++ b/YamlDotNet.Core/Events/AnchorAlias.cs
@@ -29,10 +29,10 @@ namespace YamlDotNet.Core.Events
///
public class AnchorAlias : ParsingEvent, IAnchorAlias
{
- ///
+ ///
/// Gets a value indicating the variation of depth caused by this event.
/// The value can be either -1, 0 or 1. For start events, it will be 1,
- /// for end events, it will be -1, and for the remaining events, it will be 0.
+ /// for end events, it will be -1, and for the remaining events, it will be 0.
///
public override int NestingIncrease {
get {
diff --git a/YamlDotNet.Core/Events/DocumentEnd.cs b/YamlDotNet.Core/Events/DocumentEnd.cs
index 3e84ae7..5b38df1 100644
--- a/YamlDotNet.Core/Events/DocumentEnd.cs
+++ b/YamlDotNet.Core/Events/DocumentEnd.cs
@@ -29,10 +29,10 @@ namespace YamlDotNet.Core.Events
///
public class DocumentEnd : ParsingEvent, IDocumentEnd
{
- ///
+ ///
/// Gets a value indicating the variation of depth caused by this event.
/// The value can be either -1, 0 or 1. For start events, it will be 1,
- /// for end events, it will be -1, and for the remaining events, it will be 0.
+ /// for end events, it will be -1, and for the remaining events, it will be 0.
///
public override int NestingIncrease {
get {
diff --git a/YamlDotNet.Core/Events/DocumentStart.cs b/YamlDotNet.Core/Events/DocumentStart.cs
index 0da4686..cda89ed 100644
--- a/YamlDotNet.Core/Events/DocumentStart.cs
+++ b/YamlDotNet.Core/Events/DocumentStart.cs
@@ -30,10 +30,10 @@ namespace YamlDotNet.Core.Events
///
public class DocumentStart : ParsingEvent, IDocumentStart
{
- ///
+ ///
/// Gets a value indicating the variation of depth caused by this event.
/// The value can be either -1, 0 or 1. For start events, it will be 1,
- /// for end events, it will be -1, and for the remaining events, it will be 0.
+ /// for end events, it will be -1, and for the remaining events, it will be 0.
///
public override int NestingIncrease {
get {
diff --git a/YamlDotNet.Core/Events/EventType.cs b/YamlDotNet.Core/Events/EventType.cs
index d6780f9..f1ecb4e 100644
--- a/YamlDotNet.Core/Events/EventType.cs
+++ b/YamlDotNet.Core/Events/EventType.cs
@@ -19,68 +19,68 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
-using System;
-
-namespace YamlDotNet.Core.Events
-{
- ///
- /// Defines the event types. This allows for simpler type comparisons.
- ///
- internal enum EventType
- {
- ///
- /// An empty event.
- ///
- YAML_NO_EVENT,
-
- ///
- /// A STREAM-START event.
- ///
- YAML_STREAM_START_EVENT,
-
- ///
- /// A STREAM-END event.
- ///
- YAML_STREAM_END_EVENT,
-
- ///
- /// A DOCUMENT-START event.
- ///
- YAML_DOCUMENT_START_EVENT,
-
- ///
- /// A DOCUMENT-END event.
- ///
- YAML_DOCUMENT_END_EVENT,
-
- ///
- /// An ALIAS event.
- ///
- YAML_ALIAS_EVENT,
-
- ///
- /// A SCALAR event.
- ///
- YAML_SCALAR_EVENT,
-
- ///
- /// A SEQUENCE-START event.
- ///
- YAML_SEQUENCE_START_EVENT,
-
- ///
- /// A SEQUENCE-END event.
- ///
- YAML_SEQUENCE_END_EVENT,
-
- ///
- /// A MAPPING-START event.
- ///
- YAML_MAPPING_START_EVENT,
-
- ///
- /// A MAPPING-END event.
- ///
- YAML_MAPPING_END_EVENT,
- }
-}
+using System;
+
+namespace YamlDotNet.Core.Events
+{
+ ///
+ /// Defines the event types. This allows for simpler type comparisons.
+ ///
+ internal enum EventType
+ {
+ ///
+ /// An empty event.
+ ///
+ YAML_NO_EVENT,
+
+ ///
+ /// A STREAM-START event.
+ ///
+ YAML_STREAM_START_EVENT,
+
+ ///
+ /// A STREAM-END event.
+ ///
+ YAML_STREAM_END_EVENT,
+
+ ///
+ /// A DOCUMENT-START event.
+ ///
+ YAML_DOCUMENT_START_EVENT,
+
+ ///
+ /// A DOCUMENT-END event.
+ ///
+ YAML_DOCUMENT_END_EVENT,
+
+ ///
+ /// An ALIAS event.
+ ///
+ YAML_ALIAS_EVENT,
+
+ ///
+ /// A SCALAR event.
+ ///
+ YAML_SCALAR_EVENT,
+
+ ///
+ /// A SEQUENCE-START event.
+ ///
+ YAML_SEQUENCE_START_EVENT,
+
+ ///
+ /// A SEQUENCE-END event.
+ ///
+ YAML_SEQUENCE_END_EVENT,
+
+ ///
+ /// A MAPPING-START event.
+ ///
+ YAML_MAPPING_START_EVENT,
+
+ ///
+ /// A MAPPING-END event.
+ ///
+ YAML_MAPPING_END_EVENT,
+ }
+}
diff --git a/YamlDotNet.Core/Events/MappingEnd.cs b/YamlDotNet.Core/Events/MappingEnd.cs
index 1d13c03..7406463 100644
--- a/YamlDotNet.Core/Events/MappingEnd.cs
+++ b/YamlDotNet.Core/Events/MappingEnd.cs
@@ -28,10 +28,10 @@ namespace YamlDotNet.Core.Events
///
public class MappingEnd : ParsingEvent, IMappingEnd
{
- ///
+ ///
/// Gets a value indicating the variation of depth caused by this event.
/// The value can be either -1, 0 or 1. For start events, it will be 1,
- /// for end events, it will be -1, and for the remaining events, it will be 0.
+ /// for end events, it will be -1, and for the remaining events, it will be 0.
///
public override int NestingIncrease {
get {
diff --git a/YamlDotNet.Core/Events/MappingStart.cs b/YamlDotNet.Core/Events/MappingStart.cs
index 2c4d5c9..7c98cbd 100644
--- a/YamlDotNet.Core/Events/MappingStart.cs
+++ b/YamlDotNet.Core/Events/MappingStart.cs
@@ -29,10 +29,10 @@ namespace YamlDotNet.Core.Events
///
public class MappingStart : NodeEvent, IMappingStart
{
- ///
+ ///
/// Gets a value indicating the variation of depth caused by this event.
/// The value can be either -1, 0 or 1. For start events, it will be 1,
- /// for end events, it will be -1, and for the remaining events, it will be 0.
+ /// for end events, it will be -1, and for the remaining events, it will be 0.
///
public override int NestingIncrease {
get {
diff --git a/YamlDotNet.Core/Events/MappingStyle.cs b/YamlDotNet.Core/Events/MappingStyle.cs
index 320963d..007531e 100644
--- a/YamlDotNet.Core/Events/MappingStyle.cs
+++ b/YamlDotNet.Core/Events/MappingStyle.cs
@@ -19,28 +19,28 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
-using System;
-
-namespace YamlDotNet.Core.Events
-{
- ///
- /// Specifies the style of a mapping.
- ///
- public enum MappingStyle
- {
- ///
- /// Let the emitter choose the style.
- ///
- Any,
-
- ///
- /// The block mapping style.
- ///
- Block,
-
- ///
- /// The flow mapping style.
- ///
- Flow
- }
+using System;
+
+namespace YamlDotNet.Core.Events
+{
+ ///
+ /// Specifies the style of a mapping.
+ ///
+ public enum MappingStyle
+ {
+ ///
+ /// Let the emitter choose the style.
+ ///
+ Any,
+
+ ///
+ /// The block mapping style.
+ ///
+ Block,
+
+ ///
+ /// The flow mapping style.
+ ///
+ Flow
+ }
}
\ No newline at end of file
diff --git a/YamlDotNet.Core/Events/ParsingEvent.cs b/YamlDotNet.Core/Events/ParsingEvent.cs
index 08641ff..b45a57a 100644
--- a/YamlDotNet.Core/Events/ParsingEvent.cs
+++ b/YamlDotNet.Core/Events/ParsingEvent.cs
@@ -19,66 +19,66 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
-using System;
-
-namespace YamlDotNet.Core.Events
-{
- ///
- /// Base class for parsing events.
- ///
- public abstract class ParsingEvent : IParsingEvent
- {
- ///
+using System;
+
+namespace YamlDotNet.Core.Events
+{
+ ///
+ /// Base class for parsing events.
+ ///
+ public abstract class ParsingEvent : IParsingEvent
+ {
+ ///
/// Gets a value indicating the variation of depth caused by this event.
/// The value can be either -1, 0 or 1. For start events, it will be 1,
- /// for end events, it will be -1, and for the remaining events, it will be 0.
+ /// for end events, it will be -1, and for the remaining events, it will be 0.
///
public abstract int NestingIncrease {
get;
}
-
- ///
- /// Gets the event type, which allows for simpler type comparisons.
- ///
- internal abstract EventType Type {
- get;
- }
-
- private readonly Mark start;
-
- ///
- /// Gets the position in the input stream where the event starts.
- ///
- public Mark Start
- {
- get
- {
- return start;
- }
- }
-
- private readonly Mark end;
-
- ///
- /// Gets the position in the input stream where the event ends.
- ///
- public Mark End
- {
- get
- {
- return end;
- }
- }
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The start position of the event.
- /// The end position of the event.
- internal ParsingEvent(Mark start, Mark end)
- {
- this.start = start;
- this.end = end;
- }
- }
+
+ ///
+ /// Gets the event type, which allows for simpler type comparisons.
+ ///
+ internal abstract EventType Type {
+ get;
+ }
+
+ private readonly Mark start;
+
+ ///
+ /// Gets the position in the input stream where the event starts.
+ ///
+ public Mark Start
+ {
+ get
+ {
+ return start;
+ }
+ }
+
+ private readonly Mark end;
+
+ ///
+ /// Gets the position in the input stream where the event ends.
+ ///
+ public Mark End
+ {
+ get
+ {
+ return end;
+ }
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The start position of the event.
+ /// The end position of the event.
+ internal ParsingEvent(Mark start, Mark end)
+ {
+ this.start = start;
+ this.end = end;
+ }
+ }
}
\ No newline at end of file
diff --git a/YamlDotNet.Core/Events/Scalar.cs b/YamlDotNet.Core/Events/Scalar.cs
index ca499aa..fc4757d 100644
--- a/YamlDotNet.Core/Events/Scalar.cs
+++ b/YamlDotNet.Core/Events/Scalar.cs
@@ -29,10 +29,10 @@ namespace YamlDotNet.Core.Events
///
public class Scalar : NodeEvent, IScalar
{
- ///
+ ///
/// Gets a value indicating the variation of depth caused by this event.
/// The value can be either -1, 0 or 1. For start events, it will be 1,
- /// for end events, it will be -1, and for the remaining events, it will be 0.
+ /// for end events, it will be -1, and for the remaining events, it will be 0.
///
public override int NestingIncrease {
get {
diff --git a/YamlDotNet.Core/Events/SequenceEnd.cs b/YamlDotNet.Core/Events/SequenceEnd.cs
index c6a4a94..2e36ee4 100644
--- a/YamlDotNet.Core/Events/SequenceEnd.cs
+++ b/YamlDotNet.Core/Events/SequenceEnd.cs
@@ -28,10 +28,10 @@ namespace YamlDotNet.Core.Events
///
public class SequenceEnd : ParsingEvent, ISequenceEnd
{
- ///
+ ///
/// Gets a value indicating the variation of depth caused by this event.
/// The value can be either -1, 0 or 1. For start events, it will be 1,
- /// for end events, it will be -1, and for the remaining events, it will be 0.
+ /// for end events, it will be -1, and for the remaining events, it will be 0.
///
public override int NestingIncrease {
get {
diff --git a/YamlDotNet.Core/Events/SequenceStart.cs b/YamlDotNet.Core/Events/SequenceStart.cs
index 42adacf..eb200a4 100644
--- a/YamlDotNet.Core/Events/SequenceStart.cs
+++ b/YamlDotNet.Core/Events/SequenceStart.cs
@@ -29,10 +29,10 @@ namespace YamlDotNet.Core.Events
///
public class SequenceStart : NodeEvent, ISequenceStart
{
- ///
+ ///
/// Gets a value indicating the variation of depth caused by this event.
/// The value can be either -1, 0 or 1. For start events, it will be 1,
- /// for end events, it will be -1, and for the remaining events, it will be 0.
+ /// for end events, it will be -1, and for the remaining events, it will be 0.
///
public override int NestingIncrease {
get {
diff --git a/YamlDotNet.Core/Events/SequenceStyle.cs b/YamlDotNet.Core/Events/SequenceStyle.cs
index 1891c43..2d43b58 100644
--- a/YamlDotNet.Core/Events/SequenceStyle.cs
+++ b/YamlDotNet.Core/Events/SequenceStyle.cs
@@ -19,28 +19,28 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
-using System;
-
-namespace YamlDotNet.Core.Events
-{
- ///
- /// Specifies the style of a sequence.
- ///
- public enum SequenceStyle
- {
- ///
- /// Let the emitter choose the style.
- ///
- Any,
-
- ///
- /// The block sequence style.
- ///
- Block,
-
- ///
- /// The flow sequence style.
- ///
- Flow
- }
+using System;
+
+namespace YamlDotNet.Core.Events
+{
+ ///
+ /// Specifies the style of a sequence.
+ ///
+ public enum SequenceStyle
+ {
+ ///
+ /// Let the emitter choose the style.
+ ///
+ Any,
+
+ ///
+ /// The block sequence style.
+ ///
+ Block,
+
+ ///
+ /// The flow sequence style.
+ ///
+ Flow
+ }
}
\ No newline at end of file
diff --git a/YamlDotNet.Core/Events/StreamEnd.cs b/YamlDotNet.Core/Events/StreamEnd.cs
index 02e7c2d..500f3e6 100644
--- a/YamlDotNet.Core/Events/StreamEnd.cs
+++ b/YamlDotNet.Core/Events/StreamEnd.cs
@@ -28,10 +28,10 @@ namespace YamlDotNet.Core.Events
///
public class StreamEnd : ParsingEvent, IStreamEnd
{
- ///
+ ///
/// Gets a value indicating the variation of depth caused by this event.
/// The value can be either -1, 0 or 1. For start events, it will be 1,
- /// for end events, it will be -1, and for the remaining events, it will be 0.
+ /// for end events, it will be -1, and for the remaining events, it will be 0.
///
public override int NestingIncrease {
get {
diff --git a/YamlDotNet.Core/Events/StreamStart.cs b/YamlDotNet.Core/Events/StreamStart.cs
index 9a696f8..cdaab0d 100644
--- a/YamlDotNet.Core/Events/StreamStart.cs
+++ b/YamlDotNet.Core/Events/StreamStart.cs
@@ -28,10 +28,10 @@ namespace YamlDotNet.Core.Events
///
public class StreamStart : ParsingEvent, IStreamStart
{
- ///
+ ///
/// Gets a value indicating the variation of depth caused by this event.
/// The value can be either -1, 0 or 1. For start events, it will be 1,
- /// for end events, it will be -1, and for the remaining events, it will be 0.
+ /// for end events, it will be -1, and for the remaining events, it will be 0.
///
public override int NestingIncrease {
get {
diff --git a/YamlDotNet.Core/FakeList.cs b/YamlDotNet.Core/FakeList.cs
index fca214e..3b08292 100644
--- a/YamlDotNet.Core/FakeList.cs
+++ b/YamlDotNet.Core/FakeList.cs
@@ -19,60 +19,60 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
-using System;
-using System.Collections.Generic;
-
-namespace YamlDotNet.Core
-{
- ///
- /// Implements an indexer through an IEnumerator<T>.
- ///
- public class FakeList
- {
- private readonly IEnumerator collection;
- private int currentIndex = -1;
-
- ///
- /// Initializes a new instance of FakeList<T>.
- ///
- /// The enumerator to use to implement the indexer.
- public FakeList(IEnumerator collection)
- {
- this.collection = collection;
- }
-
- ///
- /// Initializes a new instance of FakeList<T>.
- ///
- /// The collection to use to implement the indexer.
- public FakeList(IEnumerable collection)
- : this(collection.GetEnumerator())
- {
- }
-
- ///
- /// Gets the element at the specified index.
- ///
- ///
- /// If index is greater or equal than the last used index, this operation is O(index - lastIndex),
- /// else this operation is O(index).
- ///
- public T this[int index] {
- get {
- if(index < currentIndex) {
- collection.Reset();
- currentIndex = -1;
- }
-
- while(currentIndex < index) {
- if(!collection.MoveNext()) {
- throw new ArgumentOutOfRangeException("index");
- }
- ++currentIndex;
- }
-
- return collection.Current;
- }
- }
- }
+using System;
+using System.Collections.Generic;
+
+namespace YamlDotNet.Core
+{
+ ///
+ /// Implements an indexer through an IEnumerator<T>.
+ ///
+ public class FakeList
+ {
+ private readonly IEnumerator collection;
+ private int currentIndex = -1;
+
+ ///
+ /// Initializes a new instance of FakeList<T>.
+ ///
+ /// The enumerator to use to implement the indexer.
+ public FakeList(IEnumerator collection)
+ {
+ this.collection = collection;
+ }
+
+ ///
+ /// Initializes a new instance of FakeList<T>.
+ ///
+ /// The collection to use to implement the indexer.
+ public FakeList(IEnumerable collection)
+ : this(collection.GetEnumerator())
+ {
+ }
+
+ ///
+ /// Gets the element at the specified index.
+ ///
+ ///
+ /// If index is greater or equal than the last used index, this operation is O(index - lastIndex),
+ /// else this operation is O(index).
+ ///
+ public T this[int index] {
+ get {
+ if(index < currentIndex) {
+ collection.Reset();
+ currentIndex = -1;
+ }
+
+ while(currentIndex < index) {
+ if(!collection.MoveNext()) {
+ throw new ArgumentOutOfRangeException("index");
+ }
+ ++currentIndex;
+ }
+
+ return collection.Current;
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/YamlDotNet.Core/Parser.cs b/YamlDotNet.Core/Parser.cs
index 302d4b0..26c80d3 100644
--- a/YamlDotNet.Core/Parser.cs
+++ b/YamlDotNet.Core/Parser.cs
@@ -19,912 +19,912 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
-using System;
-using System.Diagnostics;
-using System.Collections.Generic;
-using System.IO;
-using YamlDotNet.Core.Tokens;
-using Event = YamlDotNet.Core.Events.ParsingEvent;
-using SequenceStyle = YamlDotNet.Core.Events.SequenceStyle;
-using MappingStyle = YamlDotNet.Core.Events.MappingStyle;
-
-namespace YamlDotNet.Core
-{
- ///
- /// Parses YAML streams.
- ///
- public class Parser : IParser
- {
- private readonly Stack states = new Stack();
- private readonly TagDirectiveCollection tagDirectives = new TagDirectiveCollection();
- private ParserState state;
-
- private readonly Scanner scanner;
- private Event current;
-
- private Token currentToken;
-
- private Token GetCurrentToken()
- {
- if (currentToken == null)
- {
- if (scanner.InternalMoveNext())
- {
- currentToken = scanner.Current;
- }
- }
- return currentToken;
- }
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The input where the YAML stream is to be read.
- public Parser(TextReader input)
- {
- scanner = new Scanner(input);
- }
-
- ///
- /// Gets the current event.
- ///
- public Event Current
- {
- get
- {
- return current;
- }
- }
-
- ///
- /// Moves to the next event.
- ///
- /// Returns true if there are more events available, otherwise returns false.
- public bool MoveNext()
- {
- // No events after the end of the stream or error.
- if (state == ParserState.YAML_PARSE_END_STATE)
- {
- current = null;
- return false;
- }
- else
- {
- // Generate the next event.
- current = StateMachine();
- return true;
- }
- }
-
- private Event StateMachine()
- {
- switch (state)
- {
- case ParserState.YAML_PARSE_STREAM_START_STATE:
- return ParseStreamStart();
-
- case ParserState.YAML_PARSE_IMPLICIT_DOCUMENT_START_STATE:
- return ParseDocumentStart(true);
-
- case ParserState.YAML_PARSE_DOCUMENT_START_STATE:
- return ParseDocumentStart(false);
-
- case ParserState.YAML_PARSE_DOCUMENT_CONTENT_STATE:
- return ParseDocumentContent();
-
- case ParserState.YAML_PARSE_DOCUMENT_END_STATE:
- return ParseDocumentEnd();
-
- case ParserState.YAML_PARSE_BLOCK_NODE_STATE:
- return ParseNode(true, false);
-
- case ParserState.YAML_PARSE_BLOCK_NODE_OR_INDENTLESS_SEQUENCE_STATE:
- return ParseNode(true, true);
-
- case ParserState.YAML_PARSE_FLOW_NODE_STATE:
- return ParseNode(false, false);
-
- case ParserState.YAML_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE:
- return ParseBlockSequenceEntry(true);
-
- case ParserState.YAML_PARSE_BLOCK_SEQUENCE_ENTRY_STATE:
- return ParseBlockSequenceEntry(false);
-
- case ParserState.YAML_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE:
- return ParseIndentlessSequenceEntry();
-
- case ParserState.YAML_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE:
- return ParseBlockMappingKey(true);
-
- case ParserState.YAML_PARSE_BLOCK_MAPPING_KEY_STATE:
- return ParseBlockMappingKey(false);
-
- case ParserState.YAML_PARSE_BLOCK_MAPPING_VALUE_STATE:
- return ParseBlockMappingValue();
-
- case ParserState.YAML_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE:
- return ParseFlowSequenceEntry(true);
-
- case ParserState.YAML_PARSE_FLOW_SEQUENCE_ENTRY_STATE:
- return ParseFlowSequenceEntry(false);
-
- case ParserState.YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_KEY_STATE:
- return ParseFlowSequenceEntryMappingKey();
-
- case ParserState.YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE:
- return ParseFlowSequenceEntryMappingValue();
-
- case ParserState.YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE:
- return ParseFlowSequenceEntryMappingEnd();
-
- case ParserState.YAML_PARSE_FLOW_MAPPING_FIRST_KEY_STATE:
- return ParseFlowMappingKey(true);
-
- case ParserState.YAML_PARSE_FLOW_MAPPING_KEY_STATE:
- return ParseFlowMappingKey(false);
-
- case ParserState.YAML_PARSE_FLOW_MAPPING_VALUE_STATE:
- return ParseFlowMappingValue(false);
-
- case ParserState.YAML_PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE:
- return ParseFlowMappingValue(true);
-
- default:
- Debug.Assert(false, "Invalid state"); // Invalid state.
- throw new InvalidOperationException();
- }
- }
-
- private void Skip()
- {
- if (currentToken != null)
- {
- currentToken = null;
- scanner.ConsumeCurrent();
- }
- }
-
- ///
- /// Parse the production:
- /// stream ::= STREAM-START implicit_document? explicit_document* STREAM-END
- /// ************
- ///
- private Event ParseStreamStart()
- {
- StreamStart streamStart = GetCurrentToken() as StreamStart;
- if (streamStart == null)
- {
- var current = GetCurrentToken();
- throw new SemanticErrorException(current.Start, current.End, "Did not find expected .");
- }
- Skip();
-
- state = ParserState.YAML_PARSE_IMPLICIT_DOCUMENT_START_STATE;
- return new Events.StreamStart(streamStart.Start, streamStart.End);
- }
-
- ///
- /// Parse the productions:
- /// implicit_document ::= block_node DOCUMENT-END*
- /// *
- /// explicit_document ::= DIRECTIVE* DOCUMENT-START block_node? DOCUMENT-END*
- /// *************************
- ///
- private Event ParseDocumentStart(bool isImplicit)
- {
- // Parse extra document end indicators.
-
- if (!isImplicit)
- {
- while (GetCurrentToken() is DocumentEnd)
- {
- Skip();
- }
- }
-
- // Parse an isImplicit document.
-
- if (isImplicit && !(GetCurrentToken() is VersionDirective || GetCurrentToken() is TagDirective || GetCurrentToken() is DocumentStart || GetCurrentToken() is StreamEnd))
- {
- TagDirectiveCollection directives = new TagDirectiveCollection();
- ProcessDirectives(directives);
-
- states.Push(ParserState.YAML_PARSE_DOCUMENT_END_STATE);
-
- state = ParserState.YAML_PARSE_BLOCK_NODE_STATE;
-
- return new Events.DocumentStart(null, directives, true, GetCurrentToken().Start, GetCurrentToken().End);
- }
-
- // Parse an explicit document.
-
- else if (!(GetCurrentToken() is StreamEnd))
- {
- Mark start = GetCurrentToken().Start;
- TagDirectiveCollection directives = new TagDirectiveCollection();
+using System;
+using System.Diagnostics;
+using System.Collections.Generic;
+using System.IO;
+using YamlDotNet.Core.Tokens;
+using Event = YamlDotNet.Core.Events.ParsingEvent;
+using SequenceStyle = YamlDotNet.Core.Events.SequenceStyle;
+using MappingStyle = YamlDotNet.Core.Events.MappingStyle;
+
+namespace YamlDotNet.Core
+{
+ ///
+ /// Parses YAML streams.
+ ///
+ public class Parser : IParser
+ {
+ private readonly Stack states = new Stack();
+ private readonly TagDirectiveCollection tagDirectives = new TagDirectiveCollection();
+ private ParserState state;
+
+ private readonly Scanner scanner;
+ private Event current;
+
+ private Token currentToken;
+
+ private Token GetCurrentToken()
+ {
+ if (currentToken == null)
+ {
+ if (scanner.InternalMoveNext())
+ {
+ currentToken = scanner.Current;
+ }
+ }
+ return currentToken;
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The input where the YAML stream is to be read.
+ public Parser(TextReader input)
+ {
+ scanner = new Scanner(input);
+ }
+
+ ///
+ /// Gets the current event.
+ ///
+ public Event Current
+ {
+ get
+ {
+ return current;
+ }
+ }
+
+ ///
+ /// Moves to the next event.
+ ///
+ /// Returns true if there are more events available, otherwise returns false.
+ public bool MoveNext()
+ {
+ // No events after the end of the stream or error.
+ if (state == ParserState.YAML_PARSE_END_STATE)
+ {
+ current = null;
+ return false;
+ }
+ else
+ {
+ // Generate the next event.
+ current = StateMachine();
+ return true;
+ }
+ }
+
+ private Event StateMachine()
+ {
+ switch (state)
+ {
+ case ParserState.YAML_PARSE_STREAM_START_STATE:
+ return ParseStreamStart();
+
+ case ParserState.YAML_PARSE_IMPLICIT_DOCUMENT_START_STATE:
+ return ParseDocumentStart(true);
+
+ case ParserState.YAML_PARSE_DOCUMENT_START_STATE:
+ return ParseDocumentStart(false);
+
+ case ParserState.YAML_PARSE_DOCUMENT_CONTENT_STATE:
+ return ParseDocumentContent();
+
+ case ParserState.YAML_PARSE_DOCUMENT_END_STATE:
+ return ParseDocumentEnd();
+
+ case ParserState.YAML_PARSE_BLOCK_NODE_STATE:
+ return ParseNode(true, false);
+
+ case ParserState.YAML_PARSE_BLOCK_NODE_OR_INDENTLESS_SEQUENCE_STATE:
+ return ParseNode(true, true);
+
+ case ParserState.YAML_PARSE_FLOW_NODE_STATE:
+ return ParseNode(false, false);
+
+ case ParserState.YAML_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE:
+ return ParseBlockSequenceEntry(true);
+
+ case ParserState.YAML_PARSE_BLOCK_SEQUENCE_ENTRY_STATE:
+ return ParseBlockSequenceEntry(false);
+
+ case ParserState.YAML_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE:
+ return ParseIndentlessSequenceEntry();
+
+ case ParserState.YAML_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE:
+ return ParseBlockMappingKey(true);
+
+ case ParserState.YAML_PARSE_BLOCK_MAPPING_KEY_STATE:
+ return ParseBlockMappingKey(false);
+
+ case ParserState.YAML_PARSE_BLOCK_MAPPING_VALUE_STATE:
+ return ParseBlockMappingValue();
+
+ case ParserState.YAML_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE:
+ return ParseFlowSequenceEntry(true);
+
+ case ParserState.YAML_PARSE_FLOW_SEQUENCE_ENTRY_STATE:
+ return ParseFlowSequenceEntry(false);
+
+ case ParserState.YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_KEY_STATE:
+ return ParseFlowSequenceEntryMappingKey();
+
+ case ParserState.YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE:
+ return ParseFlowSequenceEntryMappingValue();
+
+ case ParserState.YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE:
+ return ParseFlowSequenceEntryMappingEnd();
+
+ case ParserState.YAML_PARSE_FLOW_MAPPING_FIRST_KEY_STATE:
+ return ParseFlowMappingKey(true);
+
+ case ParserState.YAML_PARSE_FLOW_MAPPING_KEY_STATE:
+ return ParseFlowMappingKey(false);
+
+ case ParserState.YAML_PARSE_FLOW_MAPPING_VALUE_STATE:
+ return ParseFlowMappingValue(false);
+
+ case ParserState.YAML_PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE:
+ return ParseFlowMappingValue(true);
+
+ default:
+ Debug.Assert(false, "Invalid state"); // Invalid state.
+ throw new InvalidOperationException();
+ }
+ }
+
+ private void Skip()
+ {
+ if (currentToken != null)
+ {
+ currentToken = null;
+ scanner.ConsumeCurrent();
+ }
+ }
+
+ ///
+ /// Parse the production:
+ /// stream ::= STREAM-START implicit_document? explicit_document* STREAM-END
+ /// ************
+ ///
+ private Event ParseStreamStart()
+ {
+ StreamStart streamStart = GetCurrentToken() as StreamStart;
+ if (streamStart == null)
+ {
+ var current = GetCurrentToken();
+ throw new SemanticErrorException(current.Start, current.End, "Did not find expected .");
+ }
+ Skip();
+
+ state = ParserState.YAML_PARSE_IMPLICIT_DOCUMENT_START_STATE;
+ return new Events.StreamStart(streamStart.Start, streamStart.End);
+ }
+
+ ///
+ /// Parse the productions:
+ /// implicit_document ::= block_node DOCUMENT-END*
+ /// *
+ /// explicit_document ::= DIRECTIVE* DOCUMENT-START block_node? DOCUMENT-END*
+ /// *************************
+ ///
+ private Event ParseDocumentStart(bool isImplicit)
+ {
+ // Parse extra document end indicators.
+
+ if (!isImplicit)
+ {
+ while (GetCurrentToken() is DocumentEnd)
+ {
+ Skip();
+ }
+ }
+
+ // Parse an isImplicit document.
+
+ if (isImplicit && !(GetCurrentToken() is VersionDirective || GetCurrentToken() is TagDirective || GetCurrentToken() is DocumentStart || GetCurrentToken() is StreamEnd))
+ {
+ TagDirectiveCollection directives = new TagDirectiveCollection();
+ ProcessDirectives(directives);
+
+ states.Push(ParserState.YAML_PARSE_DOCUMENT_END_STATE);
+
+ state = ParserState.YAML_PARSE_BLOCK_NODE_STATE;
+
+ return new Events.DocumentStart(null, directives, true, GetCurrentToken().Start, GetCurrentToken().End);
+ }
+
+ // Parse an explicit document.
+
+ else if (!(GetCurrentToken() is StreamEnd))
+ {
+ Mark start = GetCurrentToken().Start;
+ TagDirectiveCollection directives = new TagDirectiveCollection();
VersionDirective versionDirective = ProcessDirectives(directives);
var current = GetCurrentToken();
- if (!(current is DocumentStart))
- {
- throw new SemanticErrorException(current.Start, current.End, "Did not find expected .");
- }
-
- states.Push(ParserState.YAML_PARSE_DOCUMENT_END_STATE);
-
+ if (!(current is DocumentStart))
+ {
+ throw new SemanticErrorException(current.Start, current.End, "Did not find expected .");
+ }
+
+ states.Push(ParserState.YAML_PARSE_DOCUMENT_END_STATE);
+
state = ParserState.YAML_PARSE_DOCUMENT_CONTENT_STATE;
- Event evt = new Events.DocumentStart(versionDirective, directives, false, start, current.End);
- Skip();
- return evt;
- }
-
- // Parse the stream end.
-
- else
- {
- state = ParserState.YAML_PARSE_END_STATE;
-
- Event evt = new Events.StreamEnd(GetCurrentToken().Start, GetCurrentToken().End);
- // Do not call skip here because that would throw an exception
- if (scanner.InternalMoveNext())
- {
- throw new InvalidOperationException("The scanner should contain no more tokens.");
- }
- return evt;
- }
- }
-
- ///
- /// Parse directives.
- ///
- private VersionDirective ProcessDirectives(TagDirectiveCollection tags)
- {
- VersionDirective version = null;
-
- while (true)
- {
- VersionDirective currentVersion;
- TagDirective tag;
-
- if ((currentVersion = GetCurrentToken() as VersionDirective) != null)
- {
- if (version != null)
- {
- throw new SemanticErrorException(currentVersion.Start, currentVersion.End, "Found duplicate %YAML directive.");
- }
-
- if (currentVersion.Version.Major != Constants.MajorVersion || currentVersion.Version.Minor != Constants.MinorVersion)
+ Event evt = new Events.DocumentStart(versionDirective, directives, false, start, current.End);
+ Skip();
+ return evt;
+ }
+
+ // Parse the stream end.
+
+ else
+ {
+ state = ParserState.YAML_PARSE_END_STATE;
+
+ Event evt = new Events.StreamEnd(GetCurrentToken().Start, GetCurrentToken().End);
+ // Do not call skip here because that would throw an exception
+ if (scanner.InternalMoveNext())
+ {
+ throw new InvalidOperationException("The scanner should contain no more tokens.");
+ }
+ return evt;
+ }
+ }
+
+ ///
+ /// Parse directives.
+ ///
+ private VersionDirective ProcessDirectives(TagDirectiveCollection tags)
+ {
+ VersionDirective version = null;
+
+ while (true)
+ {
+ VersionDirective currentVersion;
+ TagDirective tag;
+
+ if ((currentVersion = GetCurrentToken() as VersionDirective) != null)
+ {
+ if (version != null)
{
- throw new SemanticErrorException(currentVersion.Start, currentVersion.End, "Found incompatible YAML document.");
- }
-
- version = currentVersion;
- }
- else if ((tag = GetCurrentToken() as TagDirective) != null)
- {
- if (tagDirectives.Contains(tag.Handle))
- {
- throw new SemanticErrorException(tag.Start, tag.End, "Found duplicate %TAG directive.");
- }
- tagDirectives.Add(tag);
- if (tags != null)
- {
- tags.Add(tag);
- }
- }
- else
- {
- break;
- }
-
- Skip();
- }
-
- if (tags != null)
- {
- AddDefaultTagDirectives(tags);
- }
- AddDefaultTagDirectives(tagDirectives);
-
- return version;
- }
-
- private static void AddDefaultTagDirectives(TagDirectiveCollection directives)
- {
- foreach(var directive in Constants.DefaultTagDirectives)
- {
- if (!directives.Contains(directive))
- {
- directives.Add(directive);
- }
- }
- }
-
- ///
- /// Parse the productions:
- /// explicit_document ::= DIRECTIVE* DOCUMENT-START block_node? DOCUMENT-END*
- /// ***********
- ///
- private Event ParseDocumentContent()
- {
- if (
- GetCurrentToken() is VersionDirective ||
- GetCurrentToken() is TagDirective ||
- GetCurrentToken() is DocumentStart ||
- GetCurrentToken() is DocumentEnd ||
- GetCurrentToken() is StreamEnd
- )
- {
- state = states.Pop();
- return ProcessEmptyScalar(scanner.CurrentPosition);
- }
- else
- {
- return ParseNode(true, false);
- }
- }
-
- ///
- /// Generate an empty scalar event.
- ///
- private static Event ProcessEmptyScalar(Mark position)
- {
- return new Events.Scalar(null, null, string.Empty, ScalarStyle.Plain, true, false, position, position);
- }
-
- ///
- /// Parse the productions:
- /// block_node_or_indentless_sequence ::=
- /// ALIAS
- /// *****
- /// | properties (block_content | indentless_block_sequence)?
- /// ********** *
- /// | block_content | indentless_block_sequence
- /// *
- /// block_node ::= ALIAS
- /// *****
- /// | properties block_content?
- /// ********** *
- /// | block_content
- /// *
- /// flow_node ::= ALIAS
- /// *****
- /// | properties flow_content?
- /// ********** *
- /// | flow_content
- /// *
- /// properties ::= TAG ANCHOR? | ANCHOR TAG?
- /// *************************
- /// block_content ::= block_collection | flow_collection | SCALAR
- /// ******
- /// flow_content ::= flow_collection | SCALAR
- /// ******
- ///
- private Event ParseNode(bool isBlock, bool isIndentlessSequence)
- {
- AnchorAlias alias = GetCurrentToken() as AnchorAlias;
- if (alias != null)
- {
- state = states.Pop();
- Event evt = new Events.AnchorAlias(alias.Value, alias.Start, alias.End);
- Skip();
- return evt;
- }
-
- Mark start = GetCurrentToken().Start;
-
- Anchor anchor = null;
- Tag tag = null;
-
- // The anchor and the tag can be in any order. This loop repeats at most twice.
- while (true)
- {
- if (anchor == null && (anchor = GetCurrentToken() as Anchor) != null)
- {
- Skip();
- }
- else if (tag == null && (tag = GetCurrentToken() as Tag) != null)
- {
- Skip();
- }
- else
- {
- break;
- }
- }
-
- string tagName = null;
- if (tag != null)
- {
- if (string.IsNullOrEmpty(tag.Handle))
- {
- tagName = tag.Suffix;
- }
- else if (tagDirectives.Contains(tag.Handle))
- {
- tagName = string.Concat(tagDirectives[tag.Handle].Prefix, tag.Suffix);
- }
- else
- {
- throw new SemanticErrorException(tag.Start, tag.End, "While parsing a node, find undefined tag handle.");
- }
- }
- if (string.IsNullOrEmpty(tagName))
- {
- tagName = null;
- }
-
- string anchorName = anchor != null ? string.IsNullOrEmpty(anchor.Value) ? null : anchor.Value : null;
-
- bool isImplicit = string.IsNullOrEmpty(tagName);
-
- if (isIndentlessSequence && GetCurrentToken() is BlockEntry)
- {
- state = ParserState.YAML_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE;
-
- return new Events.SequenceStart(
- anchorName,
- tagName,
- isImplicit,
- SequenceStyle.Block,
- start,
- GetCurrentToken().End
- );
- }
- else
- {
- Scalar scalar = GetCurrentToken() as Scalar;
- if (scalar != null)
- {
- bool isPlainImplicit = false;
- bool isQuotedImplicit = false;
- if ((scalar.Style == ScalarStyle.Plain && tagName == null) || tagName == Constants.DefaultHandle)
- {
- isPlainImplicit = true;
- }
- else if (tagName == null)
- {
- isQuotedImplicit = true;
- }
-
- state = states.Pop();
- Event evt = new Events.Scalar(anchorName, tagName, scalar.Value, scalar.Style, isPlainImplicit, isQuotedImplicit, start, scalar.End);
-
- Skip();
- return evt;
- }
-
- FlowSequenceStart flowSequenceStart = GetCurrentToken() as FlowSequenceStart;
- if (flowSequenceStart != null)
- {
- state = ParserState.YAML_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE;
- return new Events.SequenceStart(anchorName, tagName, isImplicit, SequenceStyle.Flow, start, flowSequenceStart.End);
- }
-
- FlowMappingStart flowMappingStart = GetCurrentToken() as FlowMappingStart;
- if (flowMappingStart != null)
- {
- state = ParserState.YAML_PARSE_FLOW_MAPPING_FIRST_KEY_STATE;
- return new Events.MappingStart(anchorName, tagName, isImplicit, MappingStyle.Flow, start, flowMappingStart.End);
- }
-
- if (isBlock)
- {
- BlockSequenceStart blockSequenceStart = GetCurrentToken() as BlockSequenceStart;
- if (blockSequenceStart != null)
- {
- state = ParserState.YAML_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE;
- return new Events.SequenceStart(anchorName, tagName, isImplicit, SequenceStyle.Block, start, blockSequenceStart.End);
- }
-
- BlockMappingStart blockMappingStart = GetCurrentToken() as BlockMappingStart;
- if (blockMappingStart != null)
- {
- state = ParserState.YAML_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE;
- return new Events.MappingStart(anchorName, tagName, isImplicit, MappingStyle.Block, start, GetCurrentToken().End);
- }
- }
-
- if (anchorName != null || tag != null)
- {
- state = states.Pop();
- return new Events.Scalar(anchorName, tagName, string.Empty, ScalarStyle.Plain, isImplicit, false, start, GetCurrentToken().End);
+ throw new SemanticErrorException(currentVersion.Start, currentVersion.End, "Found duplicate %YAML directive.");
+ }
+
+ if (currentVersion.Version.Major != Constants.MajorVersion || currentVersion.Version.Minor != Constants.MinorVersion)
+ {
+ throw new SemanticErrorException(currentVersion.Start, currentVersion.End, "Found incompatible YAML document.");
+ }
+
+ version = currentVersion;
+ }
+ else if ((tag = GetCurrentToken() as TagDirective) != null)
+ {
+ if (tagDirectives.Contains(tag.Handle))
+ {
+ throw new SemanticErrorException(tag.Start, tag.End, "Found duplicate %TAG directive.");
+ }
+ tagDirectives.Add(tag);
+ if (tags != null)
+ {
+ tags.Add(tag);
+ }
+ }
+ else
+ {
+ break;
+ }
+
+ Skip();
+ }
+
+ if (tags != null)
+ {
+ AddDefaultTagDirectives(tags);
+ }
+ AddDefaultTagDirectives(tagDirectives);
+
+ return version;
+ }
+
+ private static void AddDefaultTagDirectives(TagDirectiveCollection directives)
+ {
+ foreach(var directive in Constants.DefaultTagDirectives)
+ {
+ if (!directives.Contains(directive))
+ {
+ directives.Add(directive);
+ }
+ }
+ }
+
+ ///
+ /// Parse the productions:
+ /// explicit_document ::= DIRECTIVE* DOCUMENT-START block_node? DOCUMENT-END*
+ /// ***********
+ ///
+ private Event ParseDocumentContent()
+ {
+ if (
+ GetCurrentToken() is VersionDirective ||
+ GetCurrentToken() is TagDirective ||
+ GetCurrentToken() is DocumentStart ||
+ GetCurrentToken() is DocumentEnd ||
+ GetCurrentToken() is StreamEnd
+ )
+ {
+ state = states.Pop();
+ return ProcessEmptyScalar(scanner.CurrentPosition);
+ }
+ else
+ {
+ return ParseNode(true, false);
+ }
+ }
+
+ ///
+ /// Generate an empty scalar event.
+ ///
+ private static Event ProcessEmptyScalar(Mark position)
+ {
+ return new Events.Scalar(null, null, string.Empty, ScalarStyle.Plain, true, false, position, position);
+ }
+
+ ///
+ /// Parse the productions:
+ /// block_node_or_indentless_sequence ::=
+ /// ALIAS
+ /// *****
+ /// | properties (block_content | indentless_block_sequence)?
+ /// ********** *
+ /// | block_content | indentless_block_sequence
+ /// *
+ /// block_node ::= ALIAS
+ /// *****
+ /// | properties block_content?
+ /// ********** *
+ /// | block_content
+ /// *
+ /// flow_node ::= ALIAS
+ /// *****
+ /// | properties flow_content?
+ /// ********** *
+ /// | flow_content
+ /// *
+ /// properties ::= TAG ANCHOR? | ANCHOR TAG?
+ /// *************************
+ /// block_content ::= block_collection | flow_collection | SCALAR
+ /// ******
+ /// flow_content ::= flow_collection | SCALAR
+ /// ******
+ ///
+ private Event ParseNode(bool isBlock, bool isIndentlessSequence)
+ {
+ AnchorAlias alias = GetCurrentToken() as AnchorAlias;
+ if (alias != null)
+ {
+ state = states.Pop();
+ Event evt = new Events.AnchorAlias(alias.Value, alias.Start, alias.End);
+ Skip();
+ return evt;
+ }
+
+ Mark start = GetCurrentToken().Start;
+
+ Anchor anchor = null;
+ Tag tag = null;
+
+ // The anchor and the tag can be in any order. This loop repeats at most twice.
+ while (true)
+ {
+ if (anchor == null && (anchor = GetCurrentToken() as Anchor) != null)
+ {
+ Skip();
+ }
+ else if (tag == null && (tag = GetCurrentToken() as Tag) != null)
+ {
+ Skip();
+ }
+ else
+ {
+ break;
+ }
+ }
+
+ string tagName = null;
+ if (tag != null)
+ {
+ if (string.IsNullOrEmpty(tag.Handle))
+ {
+ tagName = tag.Suffix;
+ }
+ else if (tagDirectives.Contains(tag.Handle))
+ {
+ tagName = string.Concat(tagDirectives[tag.Handle].Prefix, tag.Suffix);
+ }
+ else
+ {
+ throw new SemanticErrorException(tag.Start, tag.End, "While parsing a node, find undefined tag handle.");
+ }
+ }
+ if (string.IsNullOrEmpty(tagName))
+ {
+ tagName = null;
+ }
+
+ string anchorName = anchor != null ? string.IsNullOrEmpty(anchor.Value) ? null : anchor.Value : null;
+
+ bool isImplicit = string.IsNullOrEmpty(tagName);
+
+ if (isIndentlessSequence && GetCurrentToken() is BlockEntry)
+ {
+ state = ParserState.YAML_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE;
+
+ return new Events.SequenceStart(
+ anchorName,
+ tagName,
+ isImplicit,
+ SequenceStyle.Block,
+ start,
+ GetCurrentToken().End
+ );
+ }
+ else
+ {
+ Scalar scalar = GetCurrentToken() as Scalar;
+ if (scalar != null)
+ {
+ bool isPlainImplicit = false;
+ bool isQuotedImplicit = false;
+ if ((scalar.Style == ScalarStyle.Plain && tagName == null) || tagName == Constants.DefaultHandle)
+ {
+ isPlainImplicit = true;
+ }
+ else if (tagName == null)
+ {
+ isQuotedImplicit = true;
+ }
+
+ state = states.Pop();
+ Event evt = new Events.Scalar(anchorName, tagName, scalar.Value, scalar.Style, isPlainImplicit, isQuotedImplicit, start, scalar.End);
+
+ Skip();
+ return evt;
+ }
+
+ FlowSequenceStart flowSequenceStart = GetCurrentToken() as FlowSequenceStart;
+ if (flowSequenceStart != null)
+ {
+ state = ParserState.YAML_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE;
+ return new Events.SequenceStart(anchorName, tagName, isImplicit, SequenceStyle.Flow, start, flowSequenceStart.End);
+ }
+
+ FlowMappingStart flowMappingStart = GetCurrentToken() as FlowMappingStart;
+ if (flowMappingStart != null)
+ {
+ state = ParserState.YAML_PARSE_FLOW_MAPPING_FIRST_KEY_STATE;
+ return new Events.MappingStart(anchorName, tagName, isImplicit, MappingStyle.Flow, start, flowMappingStart.End);
+ }
+
+ if (isBlock)
+ {
+ BlockSequenceStart blockSequenceStart = GetCurrentToken() as BlockSequenceStart;
+ if (blockSequenceStart != null)
+ {
+ state = ParserState.YAML_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE;
+ return new Events.SequenceStart(anchorName, tagName, isImplicit, SequenceStyle.Block, start, blockSequenceStart.End);
+ }
+
+ BlockMappingStart blockMappingStart = GetCurrentToken() as BlockMappingStart;
+ if (blockMappingStart != null)
+ {
+ state = ParserState.YAML_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE;
+ return new Events.MappingStart(anchorName, tagName, isImplicit, MappingStyle.Block, start, GetCurrentToken().End);
+ }
+ }
+
+ if (anchorName != null || tag != null)
+ {
+ state = states.Pop();
+ return new Events.Scalar(anchorName, tagName, string.Empty, ScalarStyle.Plain, isImplicit, false, start, GetCurrentToken().End);
}
var current = GetCurrentToken();
- throw new SemanticErrorException(current.Start, current.End, "While parsing a node, did not find expected node content.");
- }
- }
-
- ///
- /// Parse the productions:
- /// implicit_document ::= block_node DOCUMENT-END*
- /// *************
- /// explicit_document ::= DIRECTIVE* DOCUMENT-START block_node? DOCUMENT-END*
- /// *************
- ///
-
- private Event ParseDocumentEnd()
- {
- bool isImplicit = true;
- Mark start = GetCurrentToken().Start;
- Mark end = start;
-
- if (GetCurrentToken() is DocumentEnd)
- {
- end = GetCurrentToken().End;
- Skip();
- isImplicit = false;
- }
-
- tagDirectives.Clear();
-
- state = ParserState.YAML_PARSE_DOCUMENT_START_STATE;
- return new Events.DocumentEnd(isImplicit, start, end);
- }
-
- ///
- /// Parse the productions:
- /// block_sequence ::= BLOCK-SEQUENCE-START (BLOCK-ENTRY block_node?)* BLOCK-END
- /// ******************** *********** * *********
- ///
-
- private Event ParseBlockSequenceEntry(bool isFirst)
- {
- if (isFirst)
- {
- GetCurrentToken();
- Skip();
- }
-
- if (GetCurrentToken() is BlockEntry)
- {
- Mark mark = GetCurrentToken().End;
-
- Skip();
- if (!(GetCurrentToken() is BlockEntry || GetCurrentToken() is BlockEnd))
- {
- states.Push(ParserState.YAML_PARSE_BLOCK_SEQUENCE_ENTRY_STATE);
- return ParseNode(true, false);
- }
- else
- {
- state = ParserState.YAML_PARSE_BLOCK_SEQUENCE_ENTRY_STATE;
- return ProcessEmptyScalar(mark);
- }
- }
-
- else if (GetCurrentToken() is BlockEnd)
- {
- state = states.Pop();
- Event evt = new Events.SequenceEnd(GetCurrentToken().Start, GetCurrentToken().End);
- Skip();
- return evt;
- }
-
- else
+ throw new SemanticErrorException(current.Start, current.End, "While parsing a node, did not find expected node content.");
+ }
+ }
+
+ ///
+ /// Parse the productions:
+ /// implicit_document ::= block_node DOCUMENT-END*
+ /// *************
+ /// explicit_document ::= DIRECTIVE* DOCUMENT-START block_node? DOCUMENT-END*
+ /// *************
+ ///
+
+ private Event ParseDocumentEnd()
+ {
+ bool isImplicit = true;
+ Mark start = GetCurrentToken().Start;
+ Mark end = start;
+
+ if (GetCurrentToken() is DocumentEnd)
{
- var current = GetCurrentToken();
- throw new SemanticErrorException(current.Start, current.End, "While parsing a block collection, did not find expected '-' indicator.");
- }
- }
-
- ///
- /// Parse the productions:
- /// indentless_sequence ::= (BLOCK-ENTRY block_node?)+
- /// *********** *
- ///
- private Event ParseIndentlessSequenceEntry()
- {
- if (GetCurrentToken() is BlockEntry)
- {
- Mark mark = GetCurrentToken().End;
- Skip();
-
- if (!(GetCurrentToken() is BlockEntry || GetCurrentToken() is Key || GetCurrentToken() is Value || GetCurrentToken() is BlockEnd))
- {
- states.Push(ParserState.YAML_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE);
- return ParseNode(true, false);
- }
- else
- {
- state = ParserState.YAML_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE;
- return ProcessEmptyScalar(mark);
- }
- }
- else
- {
- state = states.Pop();
- return new Events.SequenceEnd(GetCurrentToken().Start, GetCurrentToken().End);
- }
- }
-
- ///
- /// Parse the productions:
- /// block_mapping ::= BLOCK-MAPPING_START
- /// *******************
- /// ((KEY block_node_or_indentless_sequence?)?
- /// *** *
- /// (VALUE block_node_or_indentless_sequence?)?)*
- ///
- /// BLOCK-END
- /// *********
- ///
- private Event ParseBlockMappingKey(bool isFirst)
- {
- if (isFirst)
- {
- GetCurrentToken();
- Skip();
- }
-
- if (GetCurrentToken() is Key)
- {
- Mark mark = GetCurrentToken().End;
- Skip();
- if (!(GetCurrentToken() is Key || GetCurrentToken() is Value || GetCurrentToken() is BlockEnd))
- {
- states.Push(ParserState.YAML_PARSE_BLOCK_MAPPING_VALUE_STATE);
- return ParseNode(true, true);
- }
- else
- {
- state = ParserState.YAML_PARSE_BLOCK_MAPPING_VALUE_STATE;
- return ProcessEmptyScalar(mark);
- }
- }
-
- else if (GetCurrentToken() is BlockEnd)
- {
- state = states.Pop();
- Event evt = new Events.MappingEnd(GetCurrentToken().Start, GetCurrentToken().End);
- Skip();
- return evt;
- }
-
- else
+ end = GetCurrentToken().End;
+ Skip();
+ isImplicit = false;
+ }
+
+ tagDirectives.Clear();
+
+ state = ParserState.YAML_PARSE_DOCUMENT_START_STATE;
+ return new Events.DocumentEnd(isImplicit, start, end);
+ }
+
+ ///
+ /// Parse the productions:
+ /// block_sequence ::= BLOCK-SEQUENCE-START (BLOCK-ENTRY block_node?)* BLOCK-END
+ /// ******************** *********** * *********
+ ///
+
+ private Event ParseBlockSequenceEntry(bool isFirst)
+ {
+ if (isFirst)
+ {
+ GetCurrentToken();
+ Skip();
+ }
+
+ if (GetCurrentToken() is BlockEntry)
+ {
+ Mark mark = GetCurrentToken().End;
+
+ Skip();
+ if (!(GetCurrentToken() is BlockEntry || GetCurrentToken() is BlockEnd))
+ {
+ states.Push(ParserState.YAML_PARSE_BLOCK_SEQUENCE_ENTRY_STATE);
+ return ParseNode(true, false);
+ }
+ else
+ {
+ state = ParserState.YAML_PARSE_BLOCK_SEQUENCE_ENTRY_STATE;
+ return ProcessEmptyScalar(mark);
+ }
+ }
+
+ else if (GetCurrentToken() is BlockEnd)
+ {
+ state = states.Pop();
+ Event evt = new Events.SequenceEnd(GetCurrentToken().Start, GetCurrentToken().End);
+ Skip();
+ return evt;
+ }
+
+ else
{
var current = GetCurrentToken();
- throw new SemanticErrorException(current.Start, current.End, "While parsing a block mapping, did not find expected key.");
- }
- }
-
- ///
- /// Parse the productions:
- /// block_mapping ::= BLOCK-MAPPING_START
- ///
- /// ((KEY block_node_or_indentless_sequence?)?
- ///
- /// (VALUE block_node_or_indentless_sequence?)?)*
- /// ***** *
- /// BLOCK-END
- ///
- ///
- private Event ParseBlockMappingValue()
- {
- if (GetCurrentToken() is Value)
- {
- Mark mark = GetCurrentToken().End;
- Skip();
-
- if (!(GetCurrentToken() is Key || GetCurrentToken() is Value || GetCurrentToken() is BlockEnd))
- {
- states.Push(ParserState.YAML_PARSE_BLOCK_MAPPING_KEY_STATE);
- return ParseNode(true, true);
- }
- else
- {
- state = ParserState.YAML_PARSE_BLOCK_MAPPING_KEY_STATE;
- return ProcessEmptyScalar(mark);
- }
- }
-
- else
- {
- state = ParserState.YAML_PARSE_BLOCK_MAPPING_KEY_STATE;
- return ProcessEmptyScalar(GetCurrentToken().Start);
- }
- }
-
- ///
- /// Parse the productions:
- /// flow_sequence ::= FLOW-SEQUENCE-START
- /// *******************
- /// (flow_sequence_entry FLOW-ENTRY)*
- /// * **********
- /// flow_sequence_entry?
- /// *
- /// FLOW-SEQUENCE-END
- /// *****************
- /// flow_sequence_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)?
- /// *
- ///
- private Event ParseFlowSequenceEntry(bool isFirst)
- {
- if (isFirst)
- {
- GetCurrentToken();
- Skip();
- }
-
- Event evt;
- if (!(GetCurrentToken() is FlowSequenceEnd))
- {
- if (!isFirst)
- {
- if (GetCurrentToken() is FlowEntry)
- {
- Skip();
- }
- else
+ throw new SemanticErrorException(current.Start, current.End, "While parsing a block collection, did not find expected '-' indicator.");
+ }
+ }
+
+ ///
+ /// Parse the productions:
+ /// indentless_sequence ::= (BLOCK-ENTRY block_node?)+
+ /// *********** *
+ ///
+ private Event ParseIndentlessSequenceEntry()
+ {
+ if (GetCurrentToken() is BlockEntry)
+ {
+ Mark mark = GetCurrentToken().End;
+ Skip();
+
+ if (!(GetCurrentToken() is BlockEntry || GetCurrentToken() is Key || GetCurrentToken() is Value || GetCurrentToken() is BlockEnd))
+ {
+ states.Push(ParserState.YAML_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE);
+ return ParseNode(true, false);
+ }
+ else
+ {
+ state = ParserState.YAML_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE;
+ return ProcessEmptyScalar(mark);
+ }
+ }
+ else
+ {
+ state = states.Pop();
+ return new Events.SequenceEnd(GetCurrentToken().Start, GetCurrentToken().End);
+ }
+ }
+
+ ///
+ /// Parse the productions:
+ /// block_mapping ::= BLOCK-MAPPING_START
+ /// *******************
+ /// ((KEY block_node_or_indentless_sequence?)?
+ /// *** *
+ /// (VALUE block_node_or_indentless_sequence?)?)*
+ ///
+ /// BLOCK-END
+ /// *********
+ ///
+ private Event ParseBlockMappingKey(bool isFirst)
+ {
+ if (isFirst)
+ {
+ GetCurrentToken();
+ Skip();
+ }
+
+ if (GetCurrentToken() is Key)
+ {
+ Mark mark = GetCurrentToken().End;
+ Skip();
+ if (!(GetCurrentToken() is Key || GetCurrentToken() is Value || GetCurrentToken() is BlockEnd))
+ {
+ states.Push(ParserState.YAML_PARSE_BLOCK_MAPPING_VALUE_STATE);
+ return ParseNode(true, true);
+ }
+ else
+ {
+ state = ParserState.YAML_PARSE_BLOCK_MAPPING_VALUE_STATE;
+ return ProcessEmptyScalar(mark);
+ }
+ }
+
+ else if (GetCurrentToken() is BlockEnd)
+ {
+ state = states.Pop();
+ Event evt = new Events.MappingEnd(GetCurrentToken().Start, GetCurrentToken().End);
+ Skip();
+ return evt;
+ }
+
+ else
+ {
+ var current = GetCurrentToken();
+ throw new SemanticErrorException(current.Start, current.End, "While parsing a block mapping, did not find expected key.");
+ }
+ }
+
+ ///
+ /// Parse the productions:
+ /// block_mapping ::= BLOCK-MAPPING_START
+ ///
+ /// ((KEY block_node_or_indentless_sequence?)?
+ ///
+ /// (VALUE block_node_or_indentless_sequence?)?)*
+ /// ***** *
+ /// BLOCK-END
+ ///
+ ///
+ private Event ParseBlockMappingValue()
+ {
+ if (GetCurrentToken() is Value)
+ {
+ Mark mark = GetCurrentToken().End;
+ Skip();
+
+ if (!(GetCurrentToken() is Key || GetCurrentToken() is Value || GetCurrentToken() is BlockEnd))
+ {
+ states.Push(ParserState.YAML_PARSE_BLOCK_MAPPING_KEY_STATE);
+ return ParseNode(true, true);
+ }
+ else
+ {
+ state = ParserState.YAML_PARSE_BLOCK_MAPPING_KEY_STATE;
+ return ProcessEmptyScalar(mark);
+ }
+ }
+
+ else
+ {
+ state = ParserState.YAML_PARSE_BLOCK_MAPPING_KEY_STATE;
+ return ProcessEmptyScalar(GetCurrentToken().Start);
+ }
+ }
+
+ ///
+ /// Parse the productions:
+ /// flow_sequence ::= FLOW-SEQUENCE-START
+ /// *******************
+ /// (flow_sequence_entry FLOW-ENTRY)*
+ /// * **********
+ /// flow_sequence_entry?
+ /// *
+ /// FLOW-SEQUENCE-END
+ /// *****************
+ /// flow_sequence_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)?
+ /// *
+ ///
+ private Event ParseFlowSequenceEntry(bool isFirst)
+ {
+ if (isFirst)
+ {
+ GetCurrentToken();
+ Skip();
+ }
+
+ Event evt;
+ if (!(GetCurrentToken() is FlowSequenceEnd))
+ {
+ if (!isFirst)
+ {
+ if (GetCurrentToken() is FlowEntry)
+ {
+ Skip();
+ }
+ else
{
var current = GetCurrentToken();
- throw new SemanticErrorException(current.Start, current.End, "While parsing a flow sequence, did not find expected ',' or ']'.");
- }
- }
-
- if (GetCurrentToken() is Key)
- {
- state = ParserState.YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_KEY_STATE;
- evt = new Events.MappingStart(null, null, true, MappingStyle.Flow);
- Skip();
- return evt;
- }
- else if (!(GetCurrentToken() is FlowSequenceEnd))
- {
- states.Push(ParserState.YAML_PARSE_FLOW_SEQUENCE_ENTRY_STATE);
- return ParseNode(false, false);
- }
- }
-
- state = states.Pop();
- evt = new Events.SequenceEnd(GetCurrentToken().Start, GetCurrentToken().End);
- Skip();
- return evt;
- }
-
- ///
- /// Parse the productions:
- /// flow_sequence_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)?
- /// *** *
- ///
- private Event ParseFlowSequenceEntryMappingKey()
- {
- if (!(GetCurrentToken() is Value || GetCurrentToken() is FlowEntry || GetCurrentToken() is FlowSequenceEnd))
- {
- states.Push(ParserState.YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE);
- return ParseNode(false, false);
- }
- else
- {
- Mark mark = GetCurrentToken().End;
- Skip();
- state = ParserState.YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE;
- return ProcessEmptyScalar(mark);
- }
- }
-
- ///
- /// Parse the productions:
- /// flow_sequence_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)?
- /// ***** *
- ///
- private Event ParseFlowSequenceEntryMappingValue()
- {
- if (GetCurrentToken() is Value)
- {
- Skip();
- if (!(GetCurrentToken() is FlowEntry || GetCurrentToken() is FlowSequenceEnd))
- {
- states.Push(ParserState.YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE);
- return ParseNode(false, false);
- }
- }
- state = ParserState.YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE;
- return ProcessEmptyScalar(GetCurrentToken().Start);
- }
-
- ///
- /// Parse the productions:
- /// flow_sequence_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)?
- /// *
- ///
- private Event ParseFlowSequenceEntryMappingEnd()
- {
- state = ParserState.YAML_PARSE_FLOW_SEQUENCE_ENTRY_STATE;
- return new Events.MappingEnd(GetCurrentToken().Start, GetCurrentToken().End);
- }
-
- ///
- /// Parse the productions:
- /// flow_mapping ::= FLOW-MAPPING-START
- /// ******************
- /// (flow_mapping_entry FLOW-ENTRY)*
- /// * **********
- /// flow_mapping_entry?
- /// ******************
- /// FLOW-MAPPING-END
- /// ****************
- /// flow_mapping_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)?
- /// * *** *
- ///
- private Event ParseFlowMappingKey(bool isFirst)
- {
- if (isFirst)
- {
- GetCurrentToken();
- Skip();
- }
-
- if (!(GetCurrentToken() is FlowMappingEnd))
- {
- if (!isFirst)
- {
- if (GetCurrentToken() is FlowEntry)
- {
- Skip();
- }
- else
+ throw new SemanticErrorException(current.Start, current.End, "While parsing a flow sequence, did not find expected ',' or ']'.");
+ }
+ }
+
+ if (GetCurrentToken() is Key)
+ {
+ state = ParserState.YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_KEY_STATE;
+ evt = new Events.MappingStart(null, null, true, MappingStyle.Flow);
+ Skip();
+ return evt;
+ }
+ else if (!(GetCurrentToken() is FlowSequenceEnd))
+ {
+ states.Push(ParserState.YAML_PARSE_FLOW_SEQUENCE_ENTRY_STATE);
+ return ParseNode(false, false);
+ }
+ }
+
+ state = states.Pop();
+ evt = new Events.SequenceEnd(GetCurrentToken().Start, GetCurrentToken().End);
+ Skip();
+ return evt;
+ }
+
+ ///
+ /// Parse the productions:
+ /// flow_sequence_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)?
+ /// *** *
+ ///
+ private Event ParseFlowSequenceEntryMappingKey()
+ {
+ if (!(GetCurrentToken() is Value || GetCurrentToken() is FlowEntry || GetCurrentToken() is FlowSequenceEnd))
+ {
+ states.Push(ParserState.YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE);
+ return ParseNode(false, false);
+ }
+ else
+ {
+ Mark mark = GetCurrentToken().End;
+ Skip();
+ state = ParserState.YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE;
+ return ProcessEmptyScalar(mark);
+ }
+ }
+
+ ///
+ /// Parse the productions:
+ /// flow_sequence_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)?
+ /// ***** *
+ ///
+ private Event ParseFlowSequenceEntryMappingValue()
+ {
+ if (GetCurrentToken() is Value)
+ {
+ Skip();
+ if (!(GetCurrentToken() is FlowEntry || GetCurrentToken() is FlowSequenceEnd))
+ {
+ states.Push(ParserState.YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE);
+ return ParseNode(false, false);
+ }
+ }
+ state = ParserState.YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE;
+ return ProcessEmptyScalar(GetCurrentToken().Start);
+ }
+
+ ///
+ /// Parse the productions:
+ /// flow_sequence_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)?
+ /// *
+ ///
+ private Event ParseFlowSequenceEntryMappingEnd()
+ {
+ state = ParserState.YAML_PARSE_FLOW_SEQUENCE_ENTRY_STATE;
+ return new Events.MappingEnd(GetCurrentToken().Start, GetCurrentToken().End);
+ }
+
+ ///
+ /// Parse the productions:
+ /// flow_mapping ::= FLOW-MAPPING-START
+ /// ******************
+ /// (flow_mapping_entry FLOW-ENTRY)*
+ /// * **********
+ /// flow_mapping_entry?
+ /// ******************
+ /// FLOW-MAPPING-END
+ /// ****************
+ /// flow_mapping_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)?
+ /// * *** *
+ ///
+ private Event ParseFlowMappingKey(bool isFirst)
+ {
+ if (isFirst)
+ {
+ GetCurrentToken();
+ Skip();
+ }
+
+ if (!(GetCurrentToken() is FlowMappingEnd))
+ {
+ if (!isFirst)
+ {
+ if (GetCurrentToken() is FlowEntry)
+ {
+ Skip();
+ }
+ else
{
var current = GetCurrentToken();
- throw new SemanticErrorException(current.Start, current.End, "While parsing a flow mapping, did not find expected ',' or '}'.");
- }
- }
-
- if (GetCurrentToken() is Key)
- {
- Skip();
-
- if (!(GetCurrentToken() is Value || GetCurrentToken() is FlowEntry || GetCurrentToken() is FlowMappingEnd))
- {
- states.Push(ParserState.YAML_PARSE_FLOW_MAPPING_VALUE_STATE);
- return ParseNode(false, false);
- }
- else
- {
- state = ParserState.YAML_PARSE_FLOW_MAPPING_VALUE_STATE;
- return ProcessEmptyScalar(GetCurrentToken().Start);
- }
- }
- else if (!(GetCurrentToken() is FlowMappingEnd))
- {
- states.Push(ParserState.YAML_PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE);
- return ParseNode(false, false);
- }
- }
-
- state = states.Pop();
- Event evt = new Events.MappingEnd(GetCurrentToken().Start, GetCurrentToken().End);
- Skip();
- return evt;
- }
-
- ///
- /// Parse the productions:
- /// flow_mapping_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)?
- /// * ***** *
- ///
- private Event ParseFlowMappingValue(bool isEmpty)
- {
- if (isEmpty)
- {
- state = ParserState.YAML_PARSE_FLOW_MAPPING_KEY_STATE;
- return ProcessEmptyScalar(GetCurrentToken().Start);
- }
-
- if (GetCurrentToken() is Value)
- {
- Skip();
- if (!(GetCurrentToken() is FlowEntry || GetCurrentToken() is FlowMappingEnd))
- {
- states.Push(ParserState.YAML_PARSE_FLOW_MAPPING_KEY_STATE);
- return ParseNode(false, false);
- }
- }
-
- state = ParserState.YAML_PARSE_FLOW_MAPPING_KEY_STATE;
- return ProcessEmptyScalar(GetCurrentToken().Start);
- }
- }
-}
+ throw new SemanticErrorException(current.Start, current.End, "While parsing a flow mapping, did not find expected ',' or '}'.");
+ }
+ }
+
+ if (GetCurrentToken() is Key)
+ {
+ Skip();
+
+ if (!(GetCurrentToken() is Value || GetCurrentToken() is FlowEntry || GetCurrentToken() is FlowMappingEnd))
+ {
+ states.Push(ParserState.YAML_PARSE_FLOW_MAPPING_VALUE_STATE);
+ return ParseNode(false, false);
+ }
+ else
+ {
+ state = ParserState.YAML_PARSE_FLOW_MAPPING_VALUE_STATE;
+ return ProcessEmptyScalar(GetCurrentToken().Start);
+ }
+ }
+ else if (!(GetCurrentToken() is FlowMappingEnd))
+ {
+ states.Push(ParserState.YAML_PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE);
+ return ParseNode(false, false);
+ }
+ }
+
+ state = states.Pop();
+ Event evt = new Events.MappingEnd(GetCurrentToken().Start, GetCurrentToken().End);
+ Skip();
+ return evt;
+ }
+
+ ///
+ /// Parse the productions:
+ /// flow_mapping_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)?
+ /// * ***** *
+ ///
+ private Event ParseFlowMappingValue(bool isEmpty)
+ {
+ if (isEmpty)
+ {
+ state = ParserState.YAML_PARSE_FLOW_MAPPING_KEY_STATE;
+ return ProcessEmptyScalar(GetCurrentToken().Start);
+ }
+
+ if (GetCurrentToken() is Value)
+ {
+ Skip();
+ if (!(GetCurrentToken() is FlowEntry || GetCurrentToken() is FlowMappingEnd))
+ {
+ states.Push(ParserState.YAML_PARSE_FLOW_MAPPING_KEY_STATE);
+ return ParseNode(false, false);
+ }
+ }
+
+ state = ParserState.YAML_PARSE_FLOW_MAPPING_KEY_STATE;
+ return ProcessEmptyScalar(GetCurrentToken().Start);
+ }
+ }
+}
diff --git a/YamlDotNet.Core/ScalarStyle.cs b/YamlDotNet.Core/ScalarStyle.cs
index 88d123c..c2a0e51 100644
--- a/YamlDotNet.Core/ScalarStyle.cs
+++ b/YamlDotNet.Core/ScalarStyle.cs
@@ -19,43 +19,43 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
-using System;
-
-namespace YamlDotNet.Core
-{
- ///
- /// Specifies the style of a YAML scalar.
- ///
- public enum ScalarStyle
- {
- ///
- /// Let the emitter choose the style.
- ///
- Any,
-
- ///
- /// The plain scalar style.
- ///
- Plain,
-
- ///
- /// The single-quoted scalar style.
- ///
- SingleQuoted,
-
- ///
- /// The double-quoted scalar style.
- ///
- DoubleQuoted,
-
- ///
- /// The literal scalar style.
- ///
- Literal,
-
- ///
- /// The folded scalar style.
- ///
- Folded,
- }
+using System;
+
+namespace YamlDotNet.Core
+{
+ ///
+ /// Specifies the style of a YAML scalar.
+ ///
+ public enum ScalarStyle
+ {
+ ///
+ /// Let the emitter choose the style.
+ ///
+ Any,
+
+ ///
+ /// The plain scalar style.
+ ///
+ Plain,
+
+ ///
+ /// The single-quoted scalar style.
+ ///
+ SingleQuoted,
+
+ ///
+ /// The double-quoted scalar style.
+ ///
+ DoubleQuoted,
+
+ ///
+ /// The literal scalar style.
+ ///
+ Literal,
+
+ ///
+ /// The folded scalar style.
+ ///
+ Folded,
+ }
}
\ No newline at end of file
diff --git a/YamlDotNet.Core/StringLookAheadBuffer.cs b/YamlDotNet.Core/StringLookAheadBuffer.cs
index dbe18f0..059f7cc 100644
--- a/YamlDotNet.Core/StringLookAheadBuffer.cs
+++ b/YamlDotNet.Core/StringLookAheadBuffer.cs
@@ -19,54 +19,54 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
-using System;
-
-namespace YamlDotNet.Core
-{
- internal class StringLookAheadBuffer : ILookAheadBuffer
- {
- private readonly string value;
- private int currentIndex;
-
- public int Length {
- get {
- return value.Length;
- }
- }
-
- public int Position {
- get {
- return currentIndex;
- }
- }
-
- private bool IsOutside(int index) {
- return index >= value.Length;
- }
-
- public bool EndOfInput {
- get {
- return IsOutside(currentIndex);
- }
- }
-
- public StringLookAheadBuffer(string value)
- {
- this.value = value;
- }
-
- public char Peek(int offset)
- {
- int index = currentIndex + offset;
- return IsOutside(index) ? '\0' : value[index];
- }
-
- public void Skip(int length)
- {
- if(length < 0) {
- throw new ArgumentOutOfRangeException("length", "The length must be positive.");
- }
- currentIndex += length;
- }
- }
+using System;
+
+namespace YamlDotNet.Core
+{
+ internal class StringLookAheadBuffer : ILookAheadBuffer
+ {
+ private readonly string value;
+ private int currentIndex;
+
+ public int Length {
+ get {
+ return value.Length;
+ }
+ }
+
+ public int Position {
+ get {
+ return currentIndex;
+ }
+ }
+
+ private bool IsOutside(int index) {
+ return index >= value.Length;
+ }
+
+ public bool EndOfInput {
+ get {
+ return IsOutside(currentIndex);
+ }
+ }
+
+ public StringLookAheadBuffer(string value)
+ {
+ this.value = value;
+ }
+
+ public char Peek(int offset)
+ {
+ int index = currentIndex + offset;
+ return IsOutside(index) ? '\0' : value[index];
+ }
+
+ public void Skip(int length)
+ {
+ if(length < 0) {
+ throw new ArgumentOutOfRangeException("length", "The length must be positive.");
+ }
+ currentIndex += length;
+ }
+ }
}
\ No newline at end of file
diff --git a/YamlDotNet.Core/Tokens/AnchorAlias.cs b/YamlDotNet.Core/Tokens/AnchorAlias.cs
index 1a94a7a..6f0e7c5 100644
--- a/YamlDotNet.Core/Tokens/AnchorAlias.cs
+++ b/YamlDotNet.Core/Tokens/AnchorAlias.cs
@@ -19,48 +19,48 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
-
-using System;
-
-namespace YamlDotNet.Core.Tokens
-{
- ///
- /// Represents an alias token.
- ///
- public class AnchorAlias : Token
- {
- private readonly string value;
-
- ///
- /// Gets the value of the alias.
- ///
- public string Value
- {
- get
- {
- return value;
- }
- }
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The value of the anchor.
- public AnchorAlias(string value)
- : this(value, Mark.Empty, Mark.Empty)
- {
- }
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The value of the anchor.
- /// The start position of the event.
- /// The end position of the event.
- public AnchorAlias(string value, Mark start, Mark end)
- : base(start, end)
- {
- this.value = value;
- }
- }
+
+using System;
+
+namespace YamlDotNet.Core.Tokens
+{
+ ///
+ /// Represents an alias token.
+ ///
+ public class AnchorAlias : Token
+ {
+ private readonly string value;
+
+ ///
+ /// Gets the value of the alias.
+ ///
+ public string Value
+ {
+ get
+ {
+ return value;
+ }
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The value of the anchor.
+ public AnchorAlias(string value)
+ : this(value, Mark.Empty, Mark.Empty)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The value of the anchor.
+ /// The start position of the event.
+ /// The end position of the event.
+ public AnchorAlias(string value, Mark start, Mark end)
+ : base(start, end)
+ {
+ this.value = value;
+ }
+ }
}
\ No newline at end of file
diff --git a/YamlDotNet.Core/YamlException.cs b/YamlDotNet.Core/YamlException.cs
index e3a308a..df9a6c0 100644
--- a/YamlDotNet.Core/YamlException.cs
+++ b/YamlDotNet.Core/YamlException.cs
@@ -39,7 +39,7 @@ namespace YamlDotNet.Core
///
/// Gets the position in the input stream where the event that originated the exception ends.
///
- public Mark End { get; private set; }
+ public Mark End { get; private set; }
///
/// Initializes a new instance of the class.
diff --git a/YamlDotNet.RepresentationModel/IYamlVisitor.cs b/YamlDotNet.RepresentationModel/IYamlVisitor.cs
index 25d9ed8..8f4232b 100644
--- a/YamlDotNet.RepresentationModel/IYamlVisitor.cs
+++ b/YamlDotNet.RepresentationModel/IYamlVisitor.cs
@@ -19,53 +19,53 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
-using System;
-
-namespace YamlDotNet.RepresentationModel
-{
- ///
- /// Defines the method needed to be able to visit Yaml elements.
- ///
- public interface IYamlVisitor
- {
- ///
- /// Visits a .
- ///
- ///
- /// The that is being visited.
- ///
- void Visit(YamlStream stream);
-
- ///
- /// Visits a .
- ///
- ///
- /// The that is being visited.
- ///
- void Visit(YamlDocument document);
-
- ///
- /// Visits a .
- ///
- ///
- /// The that is being visited.
- ///
- void Visit(YamlScalarNode scalar);
-
- ///
- /// Visits a .
- ///
- ///
- /// The that is being visited.
- ///
- void Visit(YamlSequenceNode sequence);
-
- ///
- /// Visits a .
- ///
- ///
- /// The that is being visited.
- ///
- void Visit(YamlMappingNode mapping);
- }
+using System;
+
+namespace YamlDotNet.RepresentationModel
+{
+ ///
+ /// Defines the method needed to be able to visit Yaml elements.
+ ///
+ public interface IYamlVisitor
+ {
+ ///
+ /// Visits a .
+ ///
+ ///
+ /// The that is being visited.
+ ///
+ void Visit(YamlStream stream);
+
+ ///
+ /// Visits a .
+ ///
+ ///
+ /// The that is being visited.
+ ///
+ void Visit(YamlDocument document);
+
+ ///
+ /// Visits a .
+ ///
+ ///
+ /// The that is being visited.
+ ///
+ void Visit(YamlScalarNode scalar);
+
+ ///
+ /// Visits a .
+ ///
+ ///
+ /// The that is being visited.
+ ///
+ void Visit(YamlSequenceNode sequence);
+
+ ///
+ /// Visits a .
+ ///
+ ///
+ /// The that is being visited.
+ ///
+ void Visit(YamlMappingNode mapping);
+ }
}
\ No newline at end of file
diff --git a/YamlDotNet.RepresentationModel/Serialization/AliasValueDeserializer.cs b/YamlDotNet.RepresentationModel/Serialization/AliasValueDeserializer.cs
index 9f647b1..317af8b 100644
--- a/YamlDotNet.RepresentationModel/Serialization/AliasValueDeserializer.cs
+++ b/YamlDotNet.RepresentationModel/Serialization/AliasValueDeserializer.cs
@@ -1,31 +1,31 @@
-// This file is part of YamlDotNet - A .NET library for YAML.
-// Copyright (c) 2013 Antoine Aubry
-//
-// 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;
-using YamlDotNet.Core.Events;
-
-namespace YamlDotNet.RepresentationModel.Serialization
-{
+// This file is part of YamlDotNet - A .NET library for YAML.
+// Copyright (c) 2013 Antoine Aubry
+//
+// 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;
+using YamlDotNet.Core.Events;
+
+namespace YamlDotNet.RepresentationModel.Serialization
+{
public sealed class AliasValueDeserializer : IValueDeserializer
{
private readonly IValueDeserializer innerDeserializer;
@@ -35,12 +35,12 @@ namespace YamlDotNet.RepresentationModel.Serialization
if (innerDeserializer == null)
{
throw new ArgumentNullException ("innerDeserializer");
- }
+ }
this.innerDeserializer = innerDeserializer;
}
- private sealed class AliasState : Dictionary, IDisposable
+ private sealed class AliasState : Dictionary, IDisposable
{
public void Dispose()
{
@@ -103,39 +103,39 @@ namespace YamlDotNet.RepresentationModel.Serialization
}
}
}
- }
+ }
public object DeserializeValue (EventReader reader, Type expectedType, SerializerState state, IValueDeserializer nestedObjectDeserializer)
- {
- object value;
- var alias = reader.Allow();
- if(alias != null)
- {
+ {
+ object value;
+ var alias = reader.Allow();
+ if(alias != null)
+ {
var aliasState = state.Get();
- ValuePromise valuePromise;
- if(!aliasState.TryGetValue(alias.Value, out valuePromise))
+ ValuePromise valuePromise;
+ if(!aliasState.TryGetValue(alias.Value, out valuePromise))
{
valuePromise = new ValuePromise(alias);
- aliasState.Add(alias.Value, valuePromise);
+ aliasState.Add(alias.Value, valuePromise);
}
- return valuePromise.HasValue ? valuePromise.Value : valuePromise;
- }
-
- string anchor = null;
-
- var nodeEvent = reader.Peek();
- if(nodeEvent != null && !string.IsNullOrEmpty(nodeEvent.Anchor))
- {
- anchor = nodeEvent.Anchor;
- }
+ return valuePromise.HasValue ? valuePromise.Value : valuePromise;
+ }
- value = innerDeserializer.DeserializeValue(reader, expectedType, state, nestedObjectDeserializer);
-
- if(anchor != null)
- {
- var aliasState = state.Get();
-
+ string anchor = null;
+
+ var nodeEvent = reader.Peek();
+ if(nodeEvent != null && !string.IsNullOrEmpty(nodeEvent.Anchor))
+ {
+ anchor = nodeEvent.Anchor;
+ }
+
+ value = innerDeserializer.DeserializeValue(reader, expectedType, state, nestedObjectDeserializer);
+
+ if(anchor != null)
+ {
+ var aliasState = state.Get();
+
ValuePromise valuePromise;
if (!aliasState.TryGetValue(anchor, out valuePromise))
{
@@ -151,10 +151,10 @@ namespace YamlDotNet.RepresentationModel.Serialization
"Anchor '{0}' already defined",
alias.Value
));
- }
- }
-
+ }
+ }
+
return value;
}
- }
-}
+ }
+}
diff --git a/YamlDotNet.RepresentationModel/Serialization/Deserializer.cs b/YamlDotNet.RepresentationModel/Serialization/Deserializer.cs
index 92ed197..32db8fb 100644
--- a/YamlDotNet.RepresentationModel/Serialization/Deserializer.cs
+++ b/YamlDotNet.RepresentationModel/Serialization/Deserializer.cs
@@ -1,22 +1,22 @@
-// This file is part of YamlDotNet - A .NET library for YAML.
-// Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 Antoine Aubry
-
-// 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
+// This file is part of YamlDotNet - A .NET library for YAML.
+// Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 Antoine Aubry
+
+// 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;
@@ -28,76 +28,76 @@ using YamlDotNet.RepresentationModel.Serialization.NamingConventions;
using YamlDotNet.RepresentationModel.Serialization.NodeDeserializers;
using YamlDotNet.RepresentationModel.Serialization.NodeTypeResolvers;
-namespace YamlDotNet.RepresentationModel.Serialization
-{
- ///
- /// A façade for the YAML library with the standard configuration.
- ///
- public sealed class Deserializer
- {
- private static readonly Dictionary predefinedTagMappings = new Dictionary
- {
- { "tag:yaml.org,2002:map", typeof(Dictionary