зеркало из https://github.com/stride3d/SharpYaml.git
Started implementing the parser.
This commit is contained in:
Родитель
e41bf5a9bd
Коммит
ba56997b7f
|
@ -1,5 +1,5 @@
|
||||||
<Project name="Test" fileversion="2.0" language="C#" clr-version="Net_2_0" ctype="DotNetProject">
|
<Project name="Test" fileversion="2.0" language="C#" clr-version="Net_2_0" ctype="DotNetProject">
|
||||||
<Configurations active="Debug|Any CPU">
|
<Configurations active="Debug">
|
||||||
<Configuration name="Debug" ctype="DotNetProjectConfiguration">
|
<Configuration name="Debug" ctype="DotNetProjectConfiguration">
|
||||||
<Output directory="bin/Debug" assembly="Test" />
|
<Output directory="bin/Debug" assembly="Test" />
|
||||||
<Build debugmode="True" target="Exe" />
|
<Build debugmode="True" target="Exe" />
|
||||||
|
|
|
@ -97,7 +97,7 @@ namespace YamlDotNet {
|
||||||
|
|
||||||
static int
|
static int
|
||||||
yaml_parser_parse_document_start(yaml_parser_t *parser, yaml_event_t *event,
|
yaml_parser_parse_document_start(yaml_parser_t *parser, yaml_event_t *event,
|
||||||
int implicit);
|
int isImplicit);
|
||||||
|
|
||||||
static int
|
static int
|
||||||
yaml_parser_parse_document_content(yaml_parser_t *parser, yaml_event_t *event);
|
yaml_parser_parse_document_content(yaml_parser_t *parser, yaml_event_t *event);
|
||||||
|
@ -345,7 +345,7 @@ namespace YamlDotNet {
|
||||||
|
|
||||||
static int
|
static int
|
||||||
yaml_parser_parse_document_start(yaml_parser_t *parser, yaml_event_t *event,
|
yaml_parser_parse_document_start(yaml_parser_t *parser, yaml_event_t *event,
|
||||||
int implicit)
|
int isImplicit)
|
||||||
{
|
{
|
||||||
yaml_token_t *token;
|
yaml_token_t *token;
|
||||||
yaml_version_directive_t *version_directive = NULL;
|
yaml_version_directive_t *version_directive = NULL;
|
||||||
|
@ -359,7 +359,7 @@ namespace YamlDotNet {
|
||||||
|
|
||||||
/* Parse extra document end indicators. */
|
/* Parse extra document end indicators. */
|
||||||
|
|
||||||
if (!implicit)
|
if (!isImplicit)
|
||||||
{
|
{
|
||||||
while (token->type == YAML_DOCUMENT_END_TOKEN) {
|
while (token->type == YAML_DOCUMENT_END_TOKEN) {
|
||||||
SKIP_TOKEN(parser);
|
SKIP_TOKEN(parser);
|
||||||
|
@ -368,9 +368,9 @@ namespace YamlDotNet {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Parse an implicit document. */
|
/* Parse an isImplicit document. */
|
||||||
|
|
||||||
if (implicit && token->type != YAML_VERSION_DIRECTIVE_TOKEN &&
|
if (isImplicit && token->type != YAML_VERSION_DIRECTIVE_TOKEN &&
|
||||||
token->type != YAML_TAG_DIRECTIVE_TOKEN &&
|
token->type != YAML_TAG_DIRECTIVE_TOKEN &&
|
||||||
token->type != YAML_DOCUMENT_START_TOKEN &&
|
token->type != YAML_DOCUMENT_START_TOKEN &&
|
||||||
token->type != YAML_STREAM_END_TOKEN)
|
token->type != YAML_STREAM_END_TOKEN)
|
||||||
|
@ -476,7 +476,7 @@ namespace YamlDotNet {
|
||||||
{
|
{
|
||||||
yaml_token_t *token;
|
yaml_token_t *token;
|
||||||
yaml_mark_t start_mark, end_mark;
|
yaml_mark_t start_mark, end_mark;
|
||||||
int implicit = 1;
|
int isImplicit = 1;
|
||||||
|
|
||||||
token = PEEK_TOKEN(parser);
|
token = PEEK_TOKEN(parser);
|
||||||
if (!token) return 0;
|
if (!token) return 0;
|
||||||
|
@ -486,7 +486,7 @@ namespace YamlDotNet {
|
||||||
if (token->type == YAML_DOCUMENT_END_TOKEN) {
|
if (token->type == YAML_DOCUMENT_END_TOKEN) {
|
||||||
end_mark = token->end_mark;
|
end_mark = token->end_mark;
|
||||||
SKIP_TOKEN(parser);
|
SKIP_TOKEN(parser);
|
||||||
implicit = 0;
|
isImplicit = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!STACK_EMPTY(parser, parser->tag_directives)) {
|
while (!STACK_EMPTY(parser, parser->tag_directives)) {
|
||||||
|
@ -496,7 +496,7 @@ namespace YamlDotNet {
|
||||||
}
|
}
|
||||||
|
|
||||||
parser->state = YAML_PARSE_DOCUMENT_START_STATE;
|
parser->state = YAML_PARSE_DOCUMENT_START_STATE;
|
||||||
DOCUMENT_END_EVENT_INIT(*event, implicit, start_mark, end_mark);
|
DOCUMENT_END_EVENT_INIT(*event, isImplicit, start_mark, end_mark);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -540,7 +540,7 @@ namespace YamlDotNet {
|
||||||
yaml_char_t *tag_suffix = NULL;
|
yaml_char_t *tag_suffix = NULL;
|
||||||
yaml_char_t *tag = NULL;
|
yaml_char_t *tag = NULL;
|
||||||
yaml_mark_t start_mark, end_mark, tag_mark;
|
yaml_mark_t start_mark, end_mark, tag_mark;
|
||||||
int implicit;
|
int isImplicit;
|
||||||
|
|
||||||
token = PEEK_TOKEN(parser);
|
token = PEEK_TOKEN(parser);
|
||||||
if (!token) return 0;
|
if (!token) return 0;
|
||||||
|
@ -633,11 +633,11 @@ namespace YamlDotNet {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
implicit = (!tag || !*tag);
|
isImplicit = (!tag || !*tag);
|
||||||
if (indentless_sequence && token->type == YAML_BLOCK_ENTRY_TOKEN) {
|
if (indentless_sequence && token->type == YAML_BLOCK_ENTRY_TOKEN) {
|
||||||
end_mark = token->end_mark;
|
end_mark = token->end_mark;
|
||||||
parser->state = YAML_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE;
|
parser->state = YAML_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE;
|
||||||
SEQUENCE_START_EVENT_INIT(*event, anchor, tag, implicit,
|
SEQUENCE_START_EVENT_INIT(*event, anchor, tag, isImplicit,
|
||||||
YAML_BLOCK_SEQUENCE_STYLE, start_mark, end_mark);
|
YAML_BLOCK_SEQUENCE_STYLE, start_mark, end_mark);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -664,28 +664,28 @@ namespace YamlDotNet {
|
||||||
else if (token->type == YAML_FLOW_SEQUENCE_START_TOKEN) {
|
else if (token->type == YAML_FLOW_SEQUENCE_START_TOKEN) {
|
||||||
end_mark = token->end_mark;
|
end_mark = token->end_mark;
|
||||||
parser->state = YAML_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE;
|
parser->state = YAML_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE;
|
||||||
SEQUENCE_START_EVENT_INIT(*event, anchor, tag, implicit,
|
SEQUENCE_START_EVENT_INIT(*event, anchor, tag, isImplicit,
|
||||||
YAML_FLOW_SEQUENCE_STYLE, start_mark, end_mark);
|
YAML_FLOW_SEQUENCE_STYLE, start_mark, end_mark);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else if (token->type == YAML_FLOW_MAPPING_START_TOKEN) {
|
else if (token->type == YAML_FLOW_MAPPING_START_TOKEN) {
|
||||||
end_mark = token->end_mark;
|
end_mark = token->end_mark;
|
||||||
parser->state = YAML_PARSE_FLOW_MAPPING_FIRST_KEY_STATE;
|
parser->state = YAML_PARSE_FLOW_MAPPING_FIRST_KEY_STATE;
|
||||||
MAPPING_START_EVENT_INIT(*event, anchor, tag, implicit,
|
MAPPING_START_EVENT_INIT(*event, anchor, tag, isImplicit,
|
||||||
YAML_FLOW_MAPPING_STYLE, start_mark, end_mark);
|
YAML_FLOW_MAPPING_STYLE, start_mark, end_mark);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else if (block && token->type == YAML_BLOCK_SEQUENCE_START_TOKEN) {
|
else if (block && token->type == YAML_BLOCK_SEQUENCE_START_TOKEN) {
|
||||||
end_mark = token->end_mark;
|
end_mark = token->end_mark;
|
||||||
parser->state = YAML_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE;
|
parser->state = YAML_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE;
|
||||||
SEQUENCE_START_EVENT_INIT(*event, anchor, tag, implicit,
|
SEQUENCE_START_EVENT_INIT(*event, anchor, tag, isImplicit,
|
||||||
YAML_BLOCK_SEQUENCE_STYLE, start_mark, end_mark);
|
YAML_BLOCK_SEQUENCE_STYLE, start_mark, end_mark);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else if (block && token->type == YAML_BLOCK_MAPPING_START_TOKEN) {
|
else if (block && token->type == YAML_BLOCK_MAPPING_START_TOKEN) {
|
||||||
end_mark = token->end_mark;
|
end_mark = token->end_mark;
|
||||||
parser->state = YAML_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE;
|
parser->state = YAML_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE;
|
||||||
MAPPING_START_EVENT_INIT(*event, anchor, tag, implicit,
|
MAPPING_START_EVENT_INIT(*event, anchor, tag, isImplicit,
|
||||||
YAML_BLOCK_MAPPING_STYLE, start_mark, end_mark);
|
YAML_BLOCK_MAPPING_STYLE, start_mark, end_mark);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -698,7 +698,7 @@ namespace YamlDotNet {
|
||||||
value[0] = '\0';
|
value[0] = '\0';
|
||||||
parser->state = POP(parser, parser->states);
|
parser->state = POP(parser, parser->states);
|
||||||
SCALAR_EVENT_INIT(*event, anchor, tag, value, 0,
|
SCALAR_EVENT_INIT(*event, anchor, tag, value, 0,
|
||||||
implicit, 0, YAML_PLAIN_SCALAR_STYLE,
|
isImplicit, 0, YAML_PLAIN_SCALAR_STYLE,
|
||||||
start_mark, end_mark);
|
start_mark, end_mark);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ using System.Runtime.CompilerServices;
|
||||||
// Information about this assembly is defined by the following attributes.
|
// Information about this assembly is defined by the following attributes.
|
||||||
// Change them to the values specific to your project.
|
// Change them to the values specific to your project.
|
||||||
|
|
||||||
[assembly: AssemblyTitle("YamlDotNet.CoreCs")]
|
[assembly: AssemblyTitle("YamlDotNet.Core")]
|
||||||
[assembly: AssemblyDescription("")]
|
[assembly: AssemblyDescription("")]
|
||||||
[assembly: AssemblyConfiguration("")]
|
[assembly: AssemblyConfiguration("")]
|
||||||
[assembly: AssemblyCompany("")]
|
[assembly: AssemblyCompany("")]
|
||||||
|
@ -22,4 +22,3 @@ using System.Runtime.CompilerServices;
|
||||||
// if desired. See the Mono documentation for more information about signing.
|
// if desired. See the Mono documentation for more information about signing.
|
||||||
|
|
||||||
[assembly: AssemblyDelaySign(false)]
|
[assembly: AssemblyDelaySign(false)]
|
||||||
[assembly: AssemblyKeyFile("")]
|
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace YamlDotNet.CoreCs.Events
|
|
||||||
{
|
|
||||||
public class StreamStartEvent : YamlEvent
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,6 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace YamlDotNet.CoreCs.Events
|
namespace YamlDotNet.Core.Events
|
||||||
{
|
{
|
||||||
public class Alias : Event
|
public class Alias : Event
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace YamlDotNet.CoreCs.Events
|
namespace YamlDotNet.Core.Events
|
||||||
{
|
{
|
||||||
public class DocumentEnd : Event
|
public class DocumentEnd : Event
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,11 +1,40 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using YamlDotNet.Core.Tokens;
|
||||||
|
|
||||||
namespace YamlDotNet.CoreCs.Events
|
namespace YamlDotNet.Core.Events
|
||||||
{
|
{
|
||||||
public class DocumentStart : Event
|
public class DocumentStart : Event
|
||||||
{
|
{
|
||||||
public DocumentStart(Mark start, Mark end)
|
private readonly IList<TagDirective> tags;
|
||||||
|
private readonly VersionDirective version;
|
||||||
|
|
||||||
|
public IList<TagDirective> Tags {
|
||||||
|
get {
|
||||||
|
return tags;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public VersionDirective Version {
|
||||||
|
get {
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public DocumentStart(Tokens.VersionDirective version, IList<Tokens.TagDirective> tags, Mark start, Mark end)
|
||||||
: base(start, end)
|
: base(start, end)
|
||||||
|
{
|
||||||
|
this.version = version;
|
||||||
|
this.tags = tags;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DocumentStart(Tokens.VersionDirective version, IList<Tokens.TagDirective> tags)
|
||||||
|
: this(version, tags, Mark.Empty, Mark.Empty)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public DocumentStart(Mark start, Mark end)
|
||||||
|
: this(null, null, start, end)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace YamlDotNet.CoreCs.Events
|
namespace YamlDotNet.Core.Events
|
||||||
{
|
{
|
||||||
public abstract class Event
|
public abstract class Event
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace YamlDotNet.CoreCs.Events
|
namespace YamlDotNet.Core.Events
|
||||||
{
|
{
|
||||||
public interface INodeEvent
|
public interface INodeEvent
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace YamlDotNet.CoreCs.Events
|
namespace YamlDotNet.Core.Events
|
||||||
{
|
{
|
||||||
public class MappingEnd : Event
|
public class MappingEnd : Event
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace YamlDotNet.CoreCs.Events
|
namespace YamlDotNet.Core.Events
|
||||||
{
|
{
|
||||||
public class MappingStart : Event, INodeEvent
|
public class MappingStart : Event, INodeEvent
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace YamlDotNet.CoreCs.Events
|
namespace YamlDotNet.Core.Events
|
||||||
{
|
{
|
||||||
public class Scalar : Event, INodeEvent
|
public class Scalar : Event, INodeEvent
|
||||||
{
|
{
|
||||||
|
@ -26,7 +26,12 @@ namespace YamlDotNet.CoreCs.Events
|
||||||
this.anchor = anchor;
|
this.anchor = anchor;
|
||||||
this.tag = tag;
|
this.tag = tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Scalar(string anchor, string tag)
|
||||||
|
: this(anchor, tag, Mark.Empty, Mark.Empty)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
public Scalar() {
|
public Scalar() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace YamlDotNet.CoreCs.Events
|
namespace YamlDotNet.Core.Events
|
||||||
{
|
{
|
||||||
public class SequenceEnd : Event
|
public class SequenceEnd : Event
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace YamlDotNet.CoreCs.Events
|
namespace YamlDotNet.Core.Events
|
||||||
{
|
{
|
||||||
public class SequenceStart : Event, INodeEvent
|
public class SequenceStart : Event, INodeEvent
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace YamlDotNet.CoreCs.Events
|
namespace YamlDotNet.Core.Events
|
||||||
{
|
{
|
||||||
public class StreamEnd : Event
|
public class StreamEnd : Event
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace YamlDotNet.CoreCs.Events
|
namespace YamlDotNet.Core.Events
|
||||||
{
|
{
|
||||||
public class StreamStart : Event
|
public class StreamStart : Event
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,41 +0,0 @@
|
||||||
public class AliasEvent : YamlEvent
|
|
||||||
|
|
||||||
public class DocumentEndEvent : YamlEvent
|
|
||||||
|
|
||||||
public class DocumentStartEvent : YamlEvent
|
|
||||||
|
|
||||||
public class Emitter : IDisposable
|
|
||||||
|
|
||||||
public interface INodeEvent
|
|
||||||
|
|
||||||
public class MappingEndEvent : YamlEvent
|
|
||||||
|
|
||||||
public class MappingStartEvent : YamlEvent, INodeEvent
|
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
|
||||||
public struct Mark
|
|
||||||
|
|
||||||
public class Parser : IDisposable
|
|
||||||
|
|
||||||
public class ScalarEvent : YamlEvent, INodeEvent
|
|
||||||
|
|
||||||
public enum ScalarStyle
|
|
||||||
|
|
||||||
public class SequenceEndEvent : YamlEvent
|
|
||||||
|
|
||||||
public class SequenceStartEvent : YamlEvent, INodeEvent
|
|
||||||
|
|
||||||
public class StreamEndEvent : YamlEvent
|
|
||||||
|
|
||||||
public class StreamStartEvent : YamlEvent
|
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential, Size=1), NativeCppClass, DebugInfoInPDB, MiscellaneousBits(0x40)]
|
|
||||||
internal struct StringConverter
|
|
||||||
|
|
||||||
public abstract class YamlEvent : IDisposable
|
|
||||||
|
|
||||||
[Serializable]
|
|
||||||
public class YamlException : Exception
|
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
|
||||||
public struct YamlVersion
|
|
|
@ -1,7 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace YamlDotNet.CoreCs
|
namespace YamlDotNet.Core
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Generic queue on which items may be inserted
|
/// Generic queue on which items may be inserted
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
namespace YamlDotNet.CoreCs
|
namespace YamlDotNet.Core
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provides access to a stream and allows to peek at the next characters,
|
/// Provides access to a stream and allows to peek at the next characters,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace YamlDotNet.CoreCs
|
namespace YamlDotNet.Core
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a location inside a file
|
/// Represents a location inside a file
|
||||||
|
|
|
@ -1,32 +1,51 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using YamlDotNet.CoreCs.Tokens;
|
using System.Collections.ObjectModel;
|
||||||
using YamlDotNet.CoreCs.Events;
|
using System.Globalization;
|
||||||
|
using System.IO;
|
||||||
|
using YamlDotNet.Core.Tokens;
|
||||||
|
using Event = YamlDotNet.Core.Events.Event;
|
||||||
|
|
||||||
namespace YamlDotNet.CoreCs
|
namespace YamlDotNet.Core
|
||||||
{
|
{
|
||||||
public class Parser
|
public class Parser
|
||||||
{
|
{
|
||||||
|
private class TagDirectiveCollection : KeyedCollection<string, TagDirective> {
|
||||||
|
protected override string GetKeyForItem(TagDirective item)
|
||||||
|
{
|
||||||
|
return item.Handle;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private Stack<ParserState> states = new Stack<ParserState>();
|
private Stack<ParserState> states = new Stack<ParserState>();
|
||||||
private Stack<Mark> marks = new Stack<Mark>();
|
private Stack<Mark> marks = new Stack<Mark>();
|
||||||
private Stack<TagDirective> tagDirectives = new Stack<TagDirective>();
|
private TagDirectiveCollection tagDirectives = new TagDirectiveCollection();
|
||||||
|
|
||||||
private bool streamStartProduced;
|
|
||||||
private bool streamEndProduced;
|
|
||||||
private bool error;
|
|
||||||
private ParserState state;
|
private ParserState state;
|
||||||
|
|
||||||
private Scanner scanner;
|
private readonly Scanner scanner;
|
||||||
|
private Event current = null;
|
||||||
|
|
||||||
public Event Parse() {
|
public Parser(TextReader input) {
|
||||||
/* No events after the end of the stream or error. */
|
scanner = new Scanner(input);
|
||||||
if (streamEndProduced || error || state == ParserState.YAML_PARSE_END_STATE) {
|
}
|
||||||
return null;
|
|
||||||
|
public Event Current {
|
||||||
|
get {
|
||||||
|
return current;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 = yaml_parser_state_machine();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Generate the next event. */
|
|
||||||
return yaml_parser_state_machine();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Event yaml_parser_state_machine()
|
Event yaml_parser_state_machine()
|
||||||
|
@ -104,7 +123,7 @@ namespace YamlDotNet.CoreCs
|
||||||
|
|
||||||
default:
|
default:
|
||||||
Debug.Assert(false, "Invalid state"); /* Invalid state. */
|
Debug.Assert(false, "Invalid state"); /* Invalid state. */
|
||||||
return null;
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,74 +131,214 @@ namespace YamlDotNet.CoreCs
|
||||||
Token token = scanner.Current;
|
Token token = scanner.Current;
|
||||||
T t = token as T;
|
T t = token as T;
|
||||||
if(t == null) {
|
if(t == null) {
|
||||||
throw new ParserException("did not found expected <stream-start>", token.Start);
|
throw new ParserException(string.Format(CultureInfo.InvariantCulture, "Did not found expected {0}.", typeof(T).Name), token.Start);
|
||||||
} else {
|
} else {
|
||||||
scanner.MoveNext();
|
scanner.MoveNext();
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Event yaml_parser_parse_stream_start() {
|
private void Skip() {
|
||||||
|
if(!scanner.MoveNext()) {
|
||||||
|
throw new InvalidOperationException("The scanner should contain more token.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Parse the production:
|
||||||
|
* stream ::= STREAM-START implicit_document? explicit_document* STREAM-END
|
||||||
|
* ************
|
||||||
|
*/
|
||||||
|
|
||||||
|
private Event yaml_parser_parse_stream_start() {
|
||||||
|
Skip();
|
||||||
|
|
||||||
Tokens.StreamStart token = Expect<Tokens.StreamStart>();
|
Tokens.StreamStart token = Expect<Tokens.StreamStart>();
|
||||||
|
|
||||||
state = ParserState.YAML_PARSE_IMPLICIT_DOCUMENT_START_STATE;
|
state = ParserState.YAML_PARSE_IMPLICIT_DOCUMENT_START_STATE;
|
||||||
return new Events.StreamStart(token.Start, token.End);
|
return new Events.StreamStart(token.Start, token.End);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Event yaml_parser_parse_document_start(bool isImplicit) {
|
/*
|
||||||
return null;
|
* Parse the productions:
|
||||||
|
* implicit_document ::= block_node DOCUMENT-END*
|
||||||
|
* *
|
||||||
|
* explicit_document ::= DIRECTIVE* DOCUMENT-START block_node? DOCUMENT-END*
|
||||||
|
* *************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
private Event yaml_parser_parse_document_start(bool isImplicit)
|
||||||
|
{
|
||||||
|
/* Parse extra document end indicators. */
|
||||||
|
|
||||||
|
if (!isImplicit)
|
||||||
|
{
|
||||||
|
while (scanner.Current is Tokens.DocumentEnd) {
|
||||||
|
Skip();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Parse an isImplicit document. */
|
||||||
|
|
||||||
|
if (isImplicit && !(scanner.Current is VersionDirective || scanner.Current is TagDirective || scanner.Current is DocumentStart || scanner.Current is StreamEnd))
|
||||||
|
{
|
||||||
|
yaml_parser_process_directives(null);
|
||||||
|
|
||||||
|
states.Push(ParserState.YAML_PARSE_DOCUMENT_END_STATE);
|
||||||
|
|
||||||
|
state = ParserState.YAML_PARSE_BLOCK_NODE_STATE;
|
||||||
|
|
||||||
|
return new Events.DocumentStart(scanner.Current.Start, scanner.Current.End);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Parse an explicit document. */
|
||||||
|
|
||||||
|
else if (!(scanner.Current is StreamEnd))
|
||||||
|
{
|
||||||
|
Mark start = scanner.Current.Start;
|
||||||
|
List<TagDirective> tagDirectives = new List<TagDirective>();
|
||||||
|
VersionDirective versionDirective = yaml_parser_process_directives(tagDirectives);
|
||||||
|
|
||||||
|
if(!(scanner.Current is DocumentStart)) {
|
||||||
|
throw new ParserException("Did not found expected <document start>.", scanner.Current.Start);
|
||||||
|
}
|
||||||
|
|
||||||
|
states.Push(ParserState.YAML_PARSE_DOCUMENT_END_STATE);
|
||||||
|
|
||||||
|
state = ParserState.YAML_PARSE_DOCUMENT_CONTENT_STATE;
|
||||||
|
|
||||||
|
Event evt = new Events.DocumentStart(versionDirective, tagDirectives, start, scanner.Current.End);
|
||||||
|
Skip();
|
||||||
|
return evt;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Parse the stream end. */
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
state = ParserState.YAML_PARSE_END_STATE;
|
||||||
|
|
||||||
|
Event evt = new Events.StreamEnd(scanner.Current.Start, scanner.Current.End);
|
||||||
|
// Do not call skip here because that would throw an exception
|
||||||
|
if(scanner.MoveNext()) {
|
||||||
|
throw new InvalidOperationException("The scanner should contain no more tokens.");
|
||||||
|
}
|
||||||
|
return evt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Parse directives.
|
||||||
|
*/
|
||||||
|
|
||||||
|
private VersionDirective yaml_parser_process_directives(IList<TagDirective> tags)
|
||||||
|
{
|
||||||
|
VersionDirective version = null;
|
||||||
|
|
||||||
|
while(true)
|
||||||
|
{
|
||||||
|
VersionDirective currentVersion;
|
||||||
|
TagDirective tag;
|
||||||
|
|
||||||
|
if((currentVersion = scanner.Current as VersionDirective) != null) {
|
||||||
|
if(version != null) {
|
||||||
|
throw new ParserException("Found duplicate %YAML directive.", currentVersion.Start);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(currentVersion.Version.Major != 1 || currentVersion.Version.Minor != 1) {
|
||||||
|
throw new ParserException("Found incompatible YAML document.", currentVersion.Start);
|
||||||
|
}
|
||||||
|
|
||||||
|
version = currentVersion;
|
||||||
|
} else if((tag = scanner.Current as TagDirective) != null) {
|
||||||
|
if (tagDirectives.Contains(tag.Handle)) {
|
||||||
|
throw new ParserException("Found duplicate %TAG directive.", tag.Start);
|
||||||
|
}
|
||||||
|
tagDirectives.Add(tag);
|
||||||
|
if(tags != null) {
|
||||||
|
tags.Add(tag);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
Skip();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!tagDirectives.Contains("!")) {
|
||||||
|
tagDirectives.Add(new TagDirective("!", "!"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!tagDirectives.Contains("!!")) {
|
||||||
|
tagDirectives.Add(new TagDirective("!!", "tag:yaml.org,2002:"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Event yaml_parser_parse_document_content() {
|
private Event yaml_parser_parse_document_content()
|
||||||
return null;
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Event yaml_parser_parse_document_end() {
|
private Event yaml_parser_parse_document_end()
|
||||||
return null;
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Event yaml_parser_parse_node(bool isBlock, bool isIndentlessSequence) {
|
private Event yaml_parser_parse_node(bool isBlock, bool isIndentlessSequence)
|
||||||
return null;
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Event yaml_parser_parse_block_sequence_entry(bool isFirst) {
|
private Event yaml_parser_parse_block_sequence_entry(bool isFirst)
|
||||||
return null;
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Event yaml_parser_parse_indentless_sequence_entry() {
|
private Event yaml_parser_parse_indentless_sequence_entry()
|
||||||
return null;
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Event yaml_parser_parse_block_mapping_key(bool isFirst) {
|
private Event yaml_parser_parse_block_mapping_key(bool isFirst)
|
||||||
return null;
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Event yaml_parser_parse_block_mapping_value() {
|
private Event yaml_parser_parse_block_mapping_value()
|
||||||
return null;
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Event yaml_parser_parse_flow_sequence_entry(bool isFirst) {
|
private Event yaml_parser_parse_flow_sequence_entry(bool isFirst)
|
||||||
return null;
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Event yaml_parser_parse_flow_sequence_entry_mapping_key() {
|
private Event yaml_parser_parse_flow_sequence_entry_mapping_key()
|
||||||
return null;
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Event yaml_parser_parse_flow_sequence_entry_mapping_value() {
|
private Event yaml_parser_parse_flow_sequence_entry_mapping_value()
|
||||||
return null;
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Event yaml_parser_parse_flow_sequence_entry_mapping_end() {
|
private Event yaml_parser_parse_flow_sequence_entry_mapping_end()
|
||||||
return null;
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Event yaml_parser_parse_flow_mapping_key(bool isFirst) {
|
private Event yaml_parser_parse_flow_mapping_key(bool isFirst)
|
||||||
return null;
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Event yaml_parser_parse_flow_mapping_value(bool isEmpty) {
|
private Event yaml_parser_parse_flow_mapping_value(bool isEmpty)
|
||||||
return null;
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace YamlDotNet.CoreCs
|
namespace YamlDotNet.Core
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace YamlDotNet.CoreCs
|
namespace YamlDotNet.Core
|
||||||
{
|
{
|
||||||
public enum ParserState
|
public enum ParserState
|
||||||
{
|
{
|
||||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -1,6 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace YamlDotNet.CoreCs
|
namespace YamlDotNet.Core
|
||||||
{
|
{
|
||||||
public class SimpleKey
|
public class SimpleKey
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
|
||||||
namespace YamlDotNet.CoreCs
|
namespace YamlDotNet.Core
|
||||||
{
|
{
|
||||||
public class SyntaxErrorException : Exception
|
public class SyntaxErrorException : Exception
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace YamlDotNet.CoreCs.Tokens
|
namespace YamlDotNet.Core.Tokens
|
||||||
{
|
{
|
||||||
public class Alias : Token {
|
public class Alias : Token {
|
||||||
private string value;
|
private string value;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace YamlDotNet.CoreCs.Tokens
|
namespace YamlDotNet.Core.Tokens
|
||||||
{
|
{
|
||||||
public class Anchor : Token {
|
public class Anchor : Token {
|
||||||
private string value;
|
private string value;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace YamlDotNet.CoreCs.Tokens
|
namespace YamlDotNet.Core.Tokens
|
||||||
{
|
{
|
||||||
public class BlockEnd : Token {
|
public class BlockEnd : Token {
|
||||||
public BlockEnd()
|
public BlockEnd()
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace YamlDotNet.CoreCs.Tokens
|
namespace YamlDotNet.Core.Tokens
|
||||||
{
|
{
|
||||||
public class BlockEntry : Token {
|
public class BlockEntry : Token {
|
||||||
public BlockEntry()
|
public BlockEntry()
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace YamlDotNet.CoreCs.Tokens
|
namespace YamlDotNet.Core.Tokens
|
||||||
{
|
{
|
||||||
public class BlockMappingStart : Token {
|
public class BlockMappingStart : Token {
|
||||||
public BlockMappingStart()
|
public BlockMappingStart()
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace YamlDotNet.CoreCs.Tokens
|
namespace YamlDotNet.Core.Tokens
|
||||||
{
|
{
|
||||||
public class BlockSequenceStart : Token {
|
public class BlockSequenceStart : Token {
|
||||||
public BlockSequenceStart()
|
public BlockSequenceStart()
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace YamlDotNet.CoreCs.Tokens
|
namespace YamlDotNet.Core.Tokens
|
||||||
{
|
{
|
||||||
public class DocumentEnd : Token {
|
public class DocumentEnd : Token {
|
||||||
public DocumentEnd()
|
public DocumentEnd()
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace YamlDotNet.CoreCs.Tokens
|
namespace YamlDotNet.Core.Tokens
|
||||||
{
|
{
|
||||||
public class DocumentStart : Token {
|
public class DocumentStart : Token {
|
||||||
public DocumentStart()
|
public DocumentStart()
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace YamlDotNet.CoreCs.Tokens
|
namespace YamlDotNet.Core.Tokens
|
||||||
{
|
{
|
||||||
public class FlowEntry : Token {
|
public class FlowEntry : Token {
|
||||||
public FlowEntry()
|
public FlowEntry()
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace YamlDotNet.CoreCs.Tokens
|
namespace YamlDotNet.Core.Tokens
|
||||||
{
|
{
|
||||||
public class FlowMappingEnd : Token {
|
public class FlowMappingEnd : Token {
|
||||||
public FlowMappingEnd()
|
public FlowMappingEnd()
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace YamlDotNet.CoreCs.Tokens
|
namespace YamlDotNet.Core.Tokens
|
||||||
{
|
{
|
||||||
public class FlowMappingStart : Token {
|
public class FlowMappingStart : Token {
|
||||||
public FlowMappingStart()
|
public FlowMappingStart()
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace YamlDotNet.CoreCs.Tokens
|
namespace YamlDotNet.Core.Tokens
|
||||||
{
|
{
|
||||||
public class FlowSequenceEnd : Token {
|
public class FlowSequenceEnd : Token {
|
||||||
public FlowSequenceEnd()
|
public FlowSequenceEnd()
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace YamlDotNet.CoreCs.Tokens
|
namespace YamlDotNet.Core.Tokens
|
||||||
{
|
{
|
||||||
public class FlowSequenceStart : Token {
|
public class FlowSequenceStart : Token {
|
||||||
public FlowSequenceStart()
|
public FlowSequenceStart()
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace YamlDotNet.CoreCs.Tokens
|
namespace YamlDotNet.Core.Tokens
|
||||||
{
|
{
|
||||||
public class Key : Token {
|
public class Key : Token {
|
||||||
public Key()
|
public Key()
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace YamlDotNet.CoreCs.Tokens
|
namespace YamlDotNet.Core.Tokens
|
||||||
{
|
{
|
||||||
public class Scalar : Token {
|
public class Scalar : Token {
|
||||||
private string value;
|
private string value;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace YamlDotNet.CoreCs
|
namespace YamlDotNet.Core
|
||||||
{
|
{
|
||||||
public enum ScalarStyle
|
public enum ScalarStyle
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace YamlDotNet.CoreCs.Tokens
|
namespace YamlDotNet.Core.Tokens
|
||||||
{
|
{
|
||||||
public class StreamEnd : Token {
|
public class StreamEnd : Token {
|
||||||
public StreamEnd()
|
public StreamEnd()
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace YamlDotNet.CoreCs.Tokens
|
namespace YamlDotNet.Core.Tokens
|
||||||
{
|
{
|
||||||
public class StreamStart : Token {
|
public class StreamStart : Token {
|
||||||
public StreamStart()
|
public StreamStart()
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace YamlDotNet.CoreCs.Tokens
|
namespace YamlDotNet.Core.Tokens
|
||||||
{
|
{
|
||||||
public class Tag : Token {
|
public class Tag : Token {
|
||||||
private string handle;
|
private string handle;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace YamlDotNet.CoreCs.Tokens
|
namespace YamlDotNet.Core.Tokens
|
||||||
{
|
{
|
||||||
public class TagDirective : Token {
|
public class TagDirective : Token {
|
||||||
private readonly string handle;
|
private readonly string handle;
|
||||||
|
@ -30,5 +30,16 @@ namespace YamlDotNet.CoreCs.Tokens
|
||||||
this.handle = handle;
|
this.handle = handle;
|
||||||
this.prefix = prefix;
|
this.prefix = prefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override bool Equals (object o)
|
||||||
|
{
|
||||||
|
TagDirective other = o as TagDirective;
|
||||||
|
return other != null && handle.Equals(other.handle) && prefix.Equals(other.prefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int GetHashCode ()
|
||||||
|
{
|
||||||
|
return handle.GetHashCode() ^ prefix.GetHashCode();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace YamlDotNet.CoreCs.Tokens
|
namespace YamlDotNet.Core.Tokens
|
||||||
{
|
{
|
||||||
public abstract class Token
|
public abstract class Token
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace YamlDotNet.CoreCs.Tokens
|
namespace YamlDotNet.Core.Tokens
|
||||||
{
|
{
|
||||||
public class Value : Token {
|
public class Value : Token {
|
||||||
public Value()
|
public Value()
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace YamlDotNet.CoreCs.Tokens
|
namespace YamlDotNet.Core.Tokens
|
||||||
{
|
{
|
||||||
public class VersionDirective : Token {
|
public class VersionDirective : Token {
|
||||||
private readonly Version version;
|
private readonly Version version;
|
||||||
|
@ -21,5 +21,17 @@ namespace YamlDotNet.CoreCs.Tokens
|
||||||
{
|
{
|
||||||
this.version = version;
|
this.version = version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public override bool Equals (object o)
|
||||||
|
{
|
||||||
|
VersionDirective other = o as VersionDirective;
|
||||||
|
return other != null && version.Equals(other.version);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int GetHashCode ()
|
||||||
|
{
|
||||||
|
return version.GetHashCode();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace YamlDotNet.CoreCs
|
namespace YamlDotNet.Core
|
||||||
{
|
{
|
||||||
public class Version
|
public class Version
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
<Project name="YamlDotNet.CoreCs" fileversion="2.0" language="C#" clr-version="Net_2_0" ctype="DotNetProject">
|
<Project name="YamlDotNet.Core" fileversion="2.0" DefaultNamespace="YamlDotNet.Core" language="C#" clr-version="Net_2_0" ctype="DotNetProject">
|
||||||
<Configurations active="Debug">
|
<Configurations active="Debug">
|
||||||
<Configuration name="Debug" ctype="DotNetProjectConfiguration">
|
<Configuration name="Debug" ctype="DotNetProjectConfiguration">
|
||||||
<Output directory="bin/Debug" assembly="YamlDotNet.CoreCs" />
|
<Output directory="bin/Debug" signAssembly="True" assemblyKeyFile="../YamlDotNet.snk" assembly="YamlDotNet.Core" />
|
||||||
<Build debugmode="True" target="Library" />
|
<Build debugmode="True" target="Library" />
|
||||||
<Execution runwithwarnings="True" consolepause="False" runtime="MsNet" clr-version="Net_2_0" />
|
<Execution runwithwarnings="True" consolepause="False" runtime="MsNet" clr-version="Net_2_0" />
|
||||||
<CodeGeneration compiler="Mcs" warninglevel="4" optimize="True" unsafecodeallowed="False" generateoverflowchecks="True" definesymbols="DEBUG" generatexmldocumentation="False" ctype="CSharpCompilerParameters" />
|
<CodeGeneration compiler="Mcs" warninglevel="4" optimize="True" unsafecodeallowed="False" generateoverflowchecks="True" definesymbols="DEBUG" generatexmldocumentation="False" ctype="CSharpCompilerParameters" />
|
||||||
</Configuration>
|
</Configuration>
|
||||||
<Configuration name="Release" ctype="DotNetProjectConfiguration">
|
<Configuration name="Release" ctype="DotNetProjectConfiguration">
|
||||||
<Output directory="bin/Release" assembly="YamlDotNet.CoreCs" />
|
<Output directory="bin/Release" signAssembly="True" assemblyKeyFile="../YamlDotNet.snk" assembly="YamlDotNet.Core" />
|
||||||
<Build debugmode="False" target="Library" />
|
<Build debugmode="False" target="Library" />
|
||||||
<Execution runwithwarnings="True" consolepause="False" runtime="MsNet" clr-version="Net_2_0" />
|
<Execution runwithwarnings="True" consolepause="False" runtime="MsNet" clr-version="Net_2_0" />
|
||||||
<CodeGeneration compiler="Mcs" warninglevel="4" optimize="True" unsafecodeallowed="False" generateoverflowchecks="True" generatexmldocumentation="False" ctype="CSharpCompilerParameters" />
|
<CodeGeneration compiler="Mcs" warninglevel="4" optimize="True" unsafecodeallowed="False" generateoverflowchecks="True" generatexmldocumentation="False" ctype="CSharpCompilerParameters" />
|
||||||
|
@ -20,7 +20,6 @@
|
||||||
<File name="ParserState.cs" subtype="Code" buildaction="Compile" />
|
<File name="ParserState.cs" subtype="Code" buildaction="Compile" />
|
||||||
<File name="Mark.cs" subtype="Code" buildaction="Compile" />
|
<File name="Mark.cs" subtype="Code" buildaction="Compile" />
|
||||||
<File name="ParserException.cs" subtype="Code" buildaction="Compile" />
|
<File name="ParserException.cs" subtype="Code" buildaction="Compile" />
|
||||||
<File name="Scanner.cs" subtype="Code" buildaction="Compile" />
|
|
||||||
<File name="Tokens" subtype="Directory" buildaction="Compile" />
|
<File name="Tokens" subtype="Directory" buildaction="Compile" />
|
||||||
<File name="Tokens/Token.cs" subtype="Code" buildaction="Compile" />
|
<File name="Tokens/Token.cs" subtype="Code" buildaction="Compile" />
|
||||||
<File name="Tokens/Alias.cs" subtype="Code" buildaction="Compile" />
|
<File name="Tokens/Alias.cs" subtype="Code" buildaction="Compile" />
|
||||||
|
@ -61,8 +60,10 @@
|
||||||
<File name="LookAheadBuffer.cs" subtype="Code" buildaction="Compile" />
|
<File name="LookAheadBuffer.cs" subtype="Code" buildaction="Compile" />
|
||||||
<File name="Tokens/ScalarStyle.cs" subtype="Code" buildaction="Compile" />
|
<File name="Tokens/ScalarStyle.cs" subtype="Code" buildaction="Compile" />
|
||||||
<File name="InsertionQueue.cs" subtype="Code" buildaction="Compile" />
|
<File name="InsertionQueue.cs" subtype="Code" buildaction="Compile" />
|
||||||
|
<File name="Scanner.cs" subtype="Code" buildaction="Compile" />
|
||||||
</Contents>
|
</Contents>
|
||||||
<References>
|
<References>
|
||||||
<ProjectReference type="Gac" localcopy="True" refto="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
<ProjectReference type="Gac" localcopy="True" refto="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
||||||
</References>
|
</References>
|
||||||
|
<Deployment.LinuxDeployData scriptName="yamldotnet.corecs" />
|
||||||
</Project>
|
</Project>
|
|
@ -0,0 +1,29 @@
|
||||||
|
// AssemblyInfo.cs created with MonoDevelop
|
||||||
|
// User: aaubry at 10:18 PM 8/21/2008
|
||||||
|
//
|
||||||
|
// To change standard headers go to Edit->Preferences->Coding->Standard Headers
|
||||||
|
//
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
|
// Information about this assembly is defined by the following attributes.
|
||||||
|
// Change them to the values specific to your project.
|
||||||
|
|
||||||
|
[assembly: AssemblyTitle("YamlDotNet.RepresentationModel")]
|
||||||
|
[assembly: AssemblyDescription("")]
|
||||||
|
[assembly: AssemblyConfiguration("")]
|
||||||
|
[assembly: AssemblyCompany("")]
|
||||||
|
[assembly: AssemblyProduct("")]
|
||||||
|
[assembly: AssemblyCopyright("")]
|
||||||
|
[assembly: AssemblyTrademark("")]
|
||||||
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
|
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
|
||||||
|
// If the build and revision are set to '*' they will be updated automatically.
|
||||||
|
|
||||||
|
[assembly: AssemblyVersion("1.0.*.*")]
|
||||||
|
|
||||||
|
// The following attributes are used to specify the signing key for the assembly,
|
||||||
|
// if desired. See the Mono documentation for more information about signing.
|
||||||
|
|
||||||
|
[assembly: AssemblyDelaySign(false)]
|
|
@ -1,77 +0,0 @@
|
||||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
|
||||||
<PropertyGroup>
|
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
|
||||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
|
||||||
<ProductVersion>8.0.50727</ProductVersion>
|
|
||||||
<SchemaVersion>2.0</SchemaVersion>
|
|
||||||
<ProjectGuid>{A8DD0745-FA72-416D-9B4C-4EA30F6242CB}</ProjectGuid>
|
|
||||||
<OutputType>Library</OutputType>
|
|
||||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
|
||||||
<RootNamespace>YamlDotNet.RepresentationModel</RootNamespace>
|
|
||||||
<AssemblyName>YamlDotNet.RepresentationModel</AssemblyName>
|
|
||||||
<SignAssembly>true</SignAssembly>
|
|
||||||
<AssemblyOriginatorKeyFile>..\YamlDotNet.snk</AssemblyOriginatorKeyFile>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
|
||||||
<DebugSymbols>true</DebugSymbols>
|
|
||||||
<DebugType>full</DebugType>
|
|
||||||
<Optimize>false</Optimize>
|
|
||||||
<OutputPath>bin\Debug\</OutputPath>
|
|
||||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
|
||||||
<ErrorReport>prompt</ErrorReport>
|
|
||||||
<WarningLevel>4</WarningLevel>
|
|
||||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
|
||||||
<DocumentationFile>bin\Debug\YamlDotNet.RepresentationModel.XML</DocumentationFile>
|
|
||||||
<OutputType>Library</OutputType>
|
|
||||||
<AssemblyName>YamlDotNet.RepresentationModel</AssemblyName>
|
|
||||||
<RootNamespace>YamlDotNet.RepresentationModel</RootNamespace>
|
|
||||||
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
|
|
||||||
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
|
||||||
<DebugType>pdbonly</DebugType>
|
|
||||||
<Optimize>true</Optimize>
|
|
||||||
<OutputPath>bin\Release\</OutputPath>
|
|
||||||
<DefineConstants>TRACE</DefineConstants>
|
|
||||||
<ErrorReport>prompt</ErrorReport>
|
|
||||||
<WarningLevel>4</WarningLevel>
|
|
||||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
|
||||||
<DocumentationFile>
|
|
||||||
</DocumentationFile>
|
|
||||||
<OutputType>Library</OutputType>
|
|
||||||
<AssemblyName>YamlDotNet.RepresentationModel</AssemblyName>
|
|
||||||
<DebugSymbols>true</DebugSymbols>
|
|
||||||
<RootNamespace>YamlDotNet.RepresentationModel</RootNamespace>
|
|
||||||
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
|
|
||||||
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
|
|
||||||
</PropertyGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<Reference Include="System" />
|
|
||||||
<Reference Include="System.Data" />
|
|
||||||
<Reference Include="System.Xml" />
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<Compile Include="AnchorNotFoundException.cs" />
|
|
||||||
<Compile Include="DocumentState.cs" />
|
|
||||||
<Compile Include="DuplicateAnchorException.cs" />
|
|
||||||
<Compile Include="EventReader.cs" />
|
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
|
||||||
<Compile Include="Serialization\YamlSerializer.cs" />
|
|
||||||
<Compile Include="Serialization\YamlSerializerOptions.cs" />
|
|
||||||
<Compile Include="YamlAliasNode.cs" />
|
|
||||||
<Compile Include="YamlDocument.cs" />
|
|
||||||
<Compile Include="YamlMappingNode.cs" />
|
|
||||||
<Compile Include="YamlNode.cs" />
|
|
||||||
<Compile Include="YamlScalarNode.cs" />
|
|
||||||
<Compile Include="YamlSequenceNode.cs" />
|
|
||||||
<Compile Include="YamlStream.cs" />
|
|
||||||
</ItemGroup>
|
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
|
||||||
Other similar extension points exist, see Microsoft.Common.targets.
|
|
||||||
<Target Name="BeforeBuild">
|
|
||||||
</Target>
|
|
||||||
<Target Name="AfterBuild">
|
|
||||||
</Target>
|
|
||||||
-->
|
|
||||||
</Project>
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
<Project name="YamlDotNet.RepresentationModel" fileversion="2.0" language="C#" clr-version="Net_2_0" ctype="DotNetProject">
|
||||||
|
<Configurations active="Debug">
|
||||||
|
<Configuration name="Debug" ctype="DotNetProjectConfiguration">
|
||||||
|
<Output directory="bin/Debug" signAssembly="True" assemblyKeyFile="../YamlDotNet.snk" assembly="YamlDotNet.RepresentationModel" />
|
||||||
|
<Build debugmode="True" target="Library" />
|
||||||
|
<Execution runwithwarnings="True" consolepause="False" runtime="MsNet" clr-version="Net_2_0" />
|
||||||
|
<CodeGeneration compiler="Mcs" warninglevel="4" optimize="True" unsafecodeallowed="False" generateoverflowchecks="True" definesymbols="DEBUG" generatexmldocumentation="False" ctype="CSharpCompilerParameters" />
|
||||||
|
</Configuration>
|
||||||
|
<Configuration name="Release" ctype="DotNetProjectConfiguration">
|
||||||
|
<Output directory="bin/Release" signAssembly="True" assemblyKeyFile="../YamlDotNet.snk" assembly="YamlDotNet.RepresentationModel" />
|
||||||
|
<Build debugmode="False" target="Library" />
|
||||||
|
<Execution runwithwarnings="True" consolepause="False" runtime="MsNet" clr-version="Net_2_0" />
|
||||||
|
<CodeGeneration compiler="Mcs" warninglevel="4" optimize="True" unsafecodeallowed="False" generateoverflowchecks="True" generatexmldocumentation="False" ctype="CSharpCompilerParameters" />
|
||||||
|
</Configuration>
|
||||||
|
</Configurations>
|
||||||
|
<Contents>
|
||||||
|
<File name="AssemblyInfo.cs" subtype="Code" buildaction="Compile" />
|
||||||
|
</Contents>
|
||||||
|
<References>
|
||||||
|
<ProjectReference type="Gac" localcopy="True" refto="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
||||||
|
<ProjectReference type="Project" localcopy="True" refto="YamlDotNet.Core" />
|
||||||
|
</References>
|
||||||
|
</Project>
|
|
@ -1,5 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
using YamlDotNet.CoreCs;
|
using YamlDotNet.Core;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
namespace YamlDotNet.UnitTests
|
namespace YamlDotNet.UnitTests
|
||||||
|
|
|
@ -2,8 +2,8 @@ using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using YamlDotNet.CoreCs;
|
using YamlDotNet.Core;
|
||||||
using YamlDotNet.CoreCs.Events;
|
using YamlDotNet.Core.Events;
|
||||||
|
|
||||||
namespace YamlDotNet.UnitTests
|
namespace YamlDotNet.UnitTests
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,19 +1,98 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Reflection;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using YamlDotNet.CoreCs;
|
using YamlDotNet.Core;
|
||||||
using YamlDotNet.CoreCs.Events;
|
using YamlDotNet.Core.Events;
|
||||||
|
using VersionDirective = YamlDotNet.Core.Tokens.VersionDirective;
|
||||||
|
using TagDirective = YamlDotNet.Core.Tokens.TagDirective;
|
||||||
|
|
||||||
namespace YamlDotNet.UnitTests
|
namespace YamlDotNet.UnitTests
|
||||||
{
|
{
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class ParserTests
|
public class ParserTests : YamlTest
|
||||||
{
|
{
|
||||||
|
private static Parser CreateParser(string content) {
|
||||||
|
return new Parser(YamlFile(content));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AssertHasNext(Parser parser) {
|
||||||
|
Assert.IsTrue(parser.MoveNext(), "The parser does not contain more events.");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AssertDoesNotHaveNext(Parser parser) {
|
||||||
|
Assert.IsFalse(parser.MoveNext(), "The parser should not contain more events.");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AssertCurrent(Parser parser, Event expected) {
|
||||||
|
Console.WriteLine(expected.GetType().Name);
|
||||||
|
Assert.IsInstanceOfType(expected.GetType(), parser.Current, "The event is not of the expected type.");
|
||||||
|
|
||||||
|
foreach (PropertyInfo property in expected.GetType().GetProperties()) {
|
||||||
|
if(property.PropertyType != typeof(Mark) && property.CanRead) {
|
||||||
|
object value = property.GetValue(parser.Current, null);
|
||||||
|
object expectedValue = property.GetValue(expected, null);
|
||||||
|
if(Type.GetTypeCode(expectedValue.GetType()) == TypeCode.Object && expectedValue is IEnumerable) {
|
||||||
|
Console.Write("\t{0} = {{", property.Name);
|
||||||
|
bool isFirst = true;
|
||||||
|
foreach(object item in (IEnumerable)value) {
|
||||||
|
if(isFirst) {
|
||||||
|
isFirst = false;
|
||||||
|
} else {
|
||||||
|
Console.Write(", ");
|
||||||
|
}
|
||||||
|
Console.Write(item);
|
||||||
|
}
|
||||||
|
Console.WriteLine("}");
|
||||||
|
|
||||||
|
IEnumerator values = ((IEnumerable)value).GetEnumerator();
|
||||||
|
IEnumerator expectedValues = ((IEnumerable)expectedValue).GetEnumerator();
|
||||||
|
while(expectedValues.MoveNext()) {
|
||||||
|
Assert.IsTrue(values.MoveNext(), "The property does not contain enough items.");
|
||||||
|
Assert.AreEqual(expectedValues.Current, values.Current, string.Format("The property '{0}' is incorrect.", property.Name));
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert.IsFalse(values.MoveNext(), "The property contains too many items.");
|
||||||
|
} else {
|
||||||
|
Console.WriteLine("\t{0} = {1}", property.Name, value);
|
||||||
|
Assert.AreEqual(expectedValue, value, string.Format("The property '{0}' is incorrect.", property.Name));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AssertNext(Parser parser, Event expected) {
|
||||||
|
AssertHasNext(parser);
|
||||||
|
AssertCurrent(parser, expected);
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void ParseStreamStart()
|
public void EmptyDocument()
|
||||||
{
|
{
|
||||||
Parser parser = new Parser();
|
Parser parser = CreateParser(@"");
|
||||||
Event evt = parser.Parse();
|
|
||||||
Assert.IsInstanceOfType(typeof(StreamStart), evt, "Parsed the wrong type");
|
AssertNext(parser, new StreamStart());
|
||||||
|
AssertNext(parser, new StreamEnd());
|
||||||
|
AssertDoesNotHaveNext(parser);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void VerifyEventsOnExample1()
|
||||||
|
{
|
||||||
|
Parser parser = CreateParser(@"
|
||||||
|
%YAML 1.1
|
||||||
|
%TAG ! !foo
|
||||||
|
%TAG !yaml! tag:yaml.org,2002:
|
||||||
|
---
|
||||||
|
");
|
||||||
|
|
||||||
|
AssertNext(parser, new StreamStart());
|
||||||
|
AssertNext(parser, new DocumentStart(new VersionDirective(new Core.Version(1, 1)), new TagDirective[] { new TagDirective("!", "!foo"), new TagDirective("!yaml!", "tag:yaml.org,2002:") }));
|
||||||
|
AssertNext(parser, new Scalar(string.Empty, string.Empty));
|
||||||
|
AssertNext(parser, new DocumentEnd());
|
||||||
|
AssertNext(parser, new StreamEnd());
|
||||||
|
AssertDoesNotHaveNext(parser);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -3,32 +3,14 @@ using System.IO;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using YamlDotNet.CoreCs;
|
using YamlDotNet.Core;
|
||||||
using YamlDotNet.CoreCs.Tokens;
|
using YamlDotNet.Core.Tokens;
|
||||||
|
|
||||||
namespace YamlDotNet.UnitTests
|
namespace YamlDotNet.UnitTests
|
||||||
{
|
{
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class ScannerTests
|
public class ScannerTests : YamlTest
|
||||||
{
|
{
|
||||||
private TextReader YamlFile(string content) {
|
|
||||||
string[] lines = content.Split('\n');
|
|
||||||
StringBuilder buffer = new StringBuilder();
|
|
||||||
int indent = -1;
|
|
||||||
for(int i = 1; i < lines.Length - 1; ++i) {
|
|
||||||
if(indent < 0) {
|
|
||||||
indent = 0;
|
|
||||||
while(lines[i][indent] == '\t') {
|
|
||||||
++indent;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
buffer.Append('\n');
|
|
||||||
}
|
|
||||||
buffer.Append(lines[i].Substring(indent));
|
|
||||||
}
|
|
||||||
return new StringReader(buffer.ToString());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void MakeSureThatYamlFileWorks() {
|
public void MakeSureThatYamlFileWorks() {
|
||||||
TextReader file = YamlFile(@"
|
TextReader file = YamlFile(@"
|
||||||
|
@ -41,8 +23,8 @@ namespace YamlDotNet.UnitTests
|
||||||
string expected = "%YAML 1.1\n%TAG ! !foo\n%TAG !yaml! tag:yaml.org,2002:\n---";
|
string expected = "%YAML 1.1\n%TAG ! !foo\n%TAG !yaml! tag:yaml.org,2002:\n---";
|
||||||
Assert.AreEqual(expected, file.ReadToEnd(), "The YamlFile method does not work properly.");
|
Assert.AreEqual(expected, file.ReadToEnd(), "The YamlFile method does not work properly.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private Scanner CreateScanner(string content) {
|
private static Scanner CreateScanner(string content) {
|
||||||
return new Scanner(YamlFile(content));
|
return new Scanner(YamlFile(content));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,7 +65,7 @@ namespace YamlDotNet.UnitTests
|
||||||
");
|
");
|
||||||
|
|
||||||
AssertNext(scanner, new StreamStart());
|
AssertNext(scanner, new StreamStart());
|
||||||
AssertNext(scanner, new VersionDirective(new CoreCs.Version(1, 1)));
|
AssertNext(scanner, new VersionDirective(new Core.Version(1, 1)));
|
||||||
AssertNext(scanner, new TagDirective("!", "!foo"));
|
AssertNext(scanner, new TagDirective("!", "!foo"));
|
||||||
AssertNext(scanner, new TagDirective("!yaml!", "tag:yaml.org,2002:"));
|
AssertNext(scanner, new TagDirective("!yaml!", "tag:yaml.org,2002:"));
|
||||||
AssertNext(scanner, new DocumentStart());
|
AssertNext(scanner, new DocumentStart());
|
||||||
|
|
|
@ -1,79 +0,0 @@
|
||||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
|
||||||
<PropertyGroup>
|
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
|
||||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
|
||||||
<ProductVersion>8.0.50727</ProductVersion>
|
|
||||||
<SchemaVersion>2.0</SchemaVersion>
|
|
||||||
<ProjectGuid>{F2F8F0BB-2DFC-4E71-98D1-65F943CBEA2A}</ProjectGuid>
|
|
||||||
<OutputType>Library</OutputType>
|
|
||||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
|
||||||
<RootNamespace>YamlDotNet.UnitTests</RootNamespace>
|
|
||||||
<AssemblyName>YamlDotNet.UnitTests</AssemblyName>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
|
||||||
<DebugSymbols>true</DebugSymbols>
|
|
||||||
<DebugType>full</DebugType>
|
|
||||||
<Optimize>false</Optimize>
|
|
||||||
<OutputPath>bin\Debug\</OutputPath>
|
|
||||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
|
||||||
<ErrorReport>prompt</ErrorReport>
|
|
||||||
<WarningLevel>4</WarningLevel>
|
|
||||||
<OutputType>Library</OutputType>
|
|
||||||
<AssemblyName>YamlDotNet.UnitTests</AssemblyName>
|
|
||||||
<RootNamespace>YamlDotNet.UnitTests</RootNamespace>
|
|
||||||
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
|
|
||||||
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
|
||||||
<DebugType>pdbonly</DebugType>
|
|
||||||
<Optimize>true</Optimize>
|
|
||||||
<OutputPath>bin\Release\</OutputPath>
|
|
||||||
<DefineConstants>TRACE</DefineConstants>
|
|
||||||
<ErrorReport>prompt</ErrorReport>
|
|
||||||
<WarningLevel>4</WarningLevel>
|
|
||||||
<OutputType>Library</OutputType>
|
|
||||||
<AssemblyName>YamlDotNet.UnitTests</AssemblyName>
|
|
||||||
<DebugSymbols>true</DebugSymbols>
|
|
||||||
<RootNamespace>YamlDotNet.UnitTests</RootNamespace>
|
|
||||||
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
|
|
||||||
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
|
|
||||||
</PropertyGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<Reference Include="MbUnit.Framework, Version=1.0.2700.29885, Culture=neutral, PublicKeyToken=5e72ecd30bc408d5">
|
|
||||||
<SpecificVersion>False</SpecificVersion>
|
|
||||||
<HintPath>..\Dependencies\MbUnit.Framework.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="MbUnit.Framework.2.0, Version=0.0.0.0, Culture=neutral, PublicKeyToken=5e72ecd30bc408d5">
|
|
||||||
<SpecificVersion>False</SpecificVersion>
|
|
||||||
<HintPath>..\Dependencies\MbUnit.Framework.2.0.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="System" />
|
|
||||||
<Reference Include="System.Data" />
|
|
||||||
<Reference Include="System.Drawing" />
|
|
||||||
<Reference Include="System.Xml" />
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<Compile Include="Core\ParserTests.cs" />
|
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
|
||||||
<Compile Include="RepresentationModel\YamlStreamTests.cs" />
|
|
||||||
<Compile Include="TestDocuments.cs" />
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\YamlDotNet.Core\YamlDotNet.Core.vcproj">
|
|
||||||
<Project>{78A464C6-0EA9-4ABB-8116-660C8208D32E}</Project>
|
|
||||||
<Name>YamlDotNet.Core</Name>
|
|
||||||
</ProjectReference>
|
|
||||||
<ProjectReference Include="..\YamlDotNet.RepresentationModel\YamlDotNet.RepresentationModel.csproj">
|
|
||||||
<Project>{A8DD0745-FA72-416D-9B4C-4EA30F6242CB}</Project>
|
|
||||||
<Name>YamlDotNet.RepresentationModel</Name>
|
|
||||||
</ProjectReference>
|
|
||||||
</ItemGroup>
|
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
|
||||||
Other similar extension points exist, see Microsoft.Common.targets.
|
|
||||||
<Target Name="BeforeBuild">
|
|
||||||
</Target>
|
|
||||||
<Target Name="AfterBuild">
|
|
||||||
</Target>
|
|
||||||
-->
|
|
||||||
</Project>
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
<Project name="YamlDotNet.UnitTests" fileversion="2.0" language="C#" clr-version="Net_2_0" ctype="DotNetProject">
|
||||||
|
<Configurations active="Debug">
|
||||||
|
<Configuration name="Debug" ctype="DotNetProjectConfiguration">
|
||||||
|
<Output directory="bin/Debug" assembly="YamlDotNet.UnitTests" />
|
||||||
|
<Build debugmode="True" target="Library" />
|
||||||
|
<Execution runwithwarnings="True" consolepause="True" runtime="MsNet" clr-version="Net_2_0" />
|
||||||
|
<CodeGeneration compiler="Mcs" warninglevel="4" optimize="True" unsafecodeallowed="False" generateoverflowchecks="True" definesymbols="DEBUG" generatexmldocumentation="False" ctype="CSharpCompilerParameters" />
|
||||||
|
</Configuration>
|
||||||
|
<Configuration name="Release" ctype="DotNetProjectConfiguration">
|
||||||
|
<Output directory="bin/Release" assembly="YamlDotNet.UnitTests" />
|
||||||
|
<Build debugmode="False" target="Library" />
|
||||||
|
<Execution runwithwarnings="True" consolepause="True" runtime="MsNet" clr-version="Net_2_0" />
|
||||||
|
<CodeGeneration compiler="Mcs" warninglevel="4" optimize="True" unsafecodeallowed="False" generateoverflowchecks="True" generatexmldocumentation="False" ctype="CSharpCompilerParameters" />
|
||||||
|
</Configuration>
|
||||||
|
</Configurations>
|
||||||
|
<Contents>
|
||||||
|
<File name="ParserTests.cs" subtype="Code" buildaction="Compile" />
|
||||||
|
<File name="ScannerTests.cs" subtype="Code" buildaction="Compile" />
|
||||||
|
<File name="LookAheadBufferTests.cs" subtype="Code" buildaction="Compile" />
|
||||||
|
<File name="InsertionQueueTests.cs" subtype="Code" buildaction="Compile" />
|
||||||
|
<File name="YamlTest.cs" subtype="Code" buildaction="Compile" />
|
||||||
|
</Contents>
|
||||||
|
<References>
|
||||||
|
<ProjectReference type="Gac" localcopy="True" refto="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
||||||
|
<ProjectReference type="Gac" localcopy="True" refto="nunit.core, Version=2.2.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77" />
|
||||||
|
<ProjectReference type="Gac" localcopy="True" refto="nunit.framework, Version=2.2.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77" />
|
||||||
|
<ProjectReference type="Project" localcopy="True" refto="YamlDotNet.Core" />
|
||||||
|
</References>
|
||||||
|
</Project>
|
|
@ -0,0 +1,28 @@
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
|
using YamlDotNet.Core;
|
||||||
|
|
||||||
|
namespace YamlDotNet.UnitTests
|
||||||
|
{
|
||||||
|
public class YamlTest
|
||||||
|
{
|
||||||
|
protected static TextReader YamlFile(string content) {
|
||||||
|
string[] lines = content.Split('\n');
|
||||||
|
StringBuilder buffer = new StringBuilder();
|
||||||
|
int indent = -1;
|
||||||
|
for(int i = 1; i < lines.Length - 1; ++i) {
|
||||||
|
if(indent < 0) {
|
||||||
|
indent = 0;
|
||||||
|
while(lines[i][indent] == '\t') {
|
||||||
|
++indent;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
buffer.Append('\n');
|
||||||
|
}
|
||||||
|
buffer.Append(lines[i].Substring(indent));
|
||||||
|
}
|
||||||
|
return new StringReader(buffer.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
<Combine name="YamlDotNet" fileversion="2.0">
|
||||||
|
<Configurations active="Debug|Any CPU">
|
||||||
|
<Configuration name="Debug|Any CPU" ctype="CombineConfiguration">
|
||||||
|
<Entry build="True" name="YamlDotNet.UnitTests" configuration="Debug" />
|
||||||
|
<Entry build="True" name="Test" configuration="Debug" />
|
||||||
|
<Entry build="True" name="YamlDotNet.Core" configuration="Debug" />
|
||||||
|
<Entry build="True" name="YamlDotNet.RepresentationModel" configuration="Debug" />
|
||||||
|
</Configuration>
|
||||||
|
<Configuration name="Release|Any CPU" ctype="CombineConfiguration">
|
||||||
|
<Entry build="True" name="YamlDotNet.UnitTests" configuration="Debug" />
|
||||||
|
<Entry build="True" name="Test" configuration="Debug" />
|
||||||
|
<Entry build="True" name="YamlDotNet.Core" configuration="Debug" />
|
||||||
|
<Entry build="True" name="YamlDotNet.RepresentationModel" configuration="Debug" />
|
||||||
|
</Configuration>
|
||||||
|
</Configurations>
|
||||||
|
<StartMode startupentry="YamlDotNet.UnitTests" single="True">
|
||||||
|
<Execute type="None" entry="YamlDotNet.Core" />
|
||||||
|
<Execute type="None" entry="YamlDotNet.UnitTests" />
|
||||||
|
<Execute type="None" entry="Test" />
|
||||||
|
<Execute type="None" entry="YamlDotNet.Core" />
|
||||||
|
<Execute type="None" entry="YamlDotNet.RepresentationModel" />
|
||||||
|
</StartMode>
|
||||||
|
<Entries>
|
||||||
|
<Entry filename="YamlDotNet.UnitTests/YamlDotNet.UnitTests.mdp" />
|
||||||
|
<Entry filename="Test/Test.mdp" />
|
||||||
|
<Entry filename="YamlDotNet.Core/YamlDotNet.Core.mdp" />
|
||||||
|
<Entry filename="YamlDotNet.RepresentationModel/YamlDotNet.RepresentationModel.mdp" />
|
||||||
|
</Entries>
|
||||||
|
</Combine>
|
|
@ -1,54 +0,0 @@
|
||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 9.00
|
|
||||||
# Visual Studio 2005
|
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "YamlDotNet.RepresentationModel", "YamlDotNet.RepresentationModel\YamlDotNet.RepresentationModel.csproj", "{A8DD0745-FA72-416D-9B4C-4EA30F6242CB}"
|
|
||||||
EndProject
|
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "YamlDotNet.UnitTests", "YamlDotNet.UnitTests\YamlDotNet.UnitTests.csproj", "{F2F8F0BB-2DFC-4E71-98D1-65F943CBEA2A}"
|
|
||||||
EndProject
|
|
||||||
Global
|
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
|
||||||
Debug|Any CPU = Debug|Any CPU
|
|
||||||
Release|Any CPU = Release|Any CPU
|
|
||||||
Debug|Mixed Platforms = Debug|Mixed Platforms
|
|
||||||
Debug|Win32 = Debug|Win32
|
|
||||||
Release|Mixed Platforms = Release|Mixed Platforms
|
|
||||||
Release|Win32 = Release|Win32
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
|
||||||
{A8DD0745-FA72-416D-9B4C-4EA30F6242CB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{A8DD0745-FA72-416D-9B4C-4EA30F6242CB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{A8DD0745-FA72-416D-9B4C-4EA30F6242CB}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
|
||||||
{A8DD0745-FA72-416D-9B4C-4EA30F6242CB}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
|
||||||
{A8DD0745-FA72-416D-9B4C-4EA30F6242CB}.Debug|Win32.ActiveCfg = Debug|Any CPU
|
|
||||||
{A8DD0745-FA72-416D-9B4C-4EA30F6242CB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{A8DD0745-FA72-416D-9B4C-4EA30F6242CB}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
{A8DD0745-FA72-416D-9B4C-4EA30F6242CB}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
|
||||||
{A8DD0745-FA72-416D-9B4C-4EA30F6242CB}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
|
||||||
{A8DD0745-FA72-416D-9B4C-4EA30F6242CB}.Release|Win32.ActiveCfg = Release|Any CPU
|
|
||||||
{F2F8F0BB-2DFC-4E71-98D1-65F943CBEA2A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{F2F8F0BB-2DFC-4E71-98D1-65F943CBEA2A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{F2F8F0BB-2DFC-4E71-98D1-65F943CBEA2A}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
|
||||||
{F2F8F0BB-2DFC-4E71-98D1-65F943CBEA2A}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
|
||||||
{F2F8F0BB-2DFC-4E71-98D1-65F943CBEA2A}.Debug|Win32.ActiveCfg = Debug|Any CPU
|
|
||||||
{F2F8F0BB-2DFC-4E71-98D1-65F943CBEA2A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{F2F8F0BB-2DFC-4E71-98D1-65F943CBEA2A}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
{F2F8F0BB-2DFC-4E71-98D1-65F943CBEA2A}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
|
||||||
{F2F8F0BB-2DFC-4E71-98D1-65F943CBEA2A}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
|
||||||
{F2F8F0BB-2DFC-4E71-98D1-65F943CBEA2A}.Release|Win32.ActiveCfg = Release|Any CPU
|
|
||||||
{78A464C6-0EA9-4ABB-8116-660C8208D32E}.Debug|Any CPU.ActiveCfg = Debug|Win32
|
|
||||||
{78A464C6-0EA9-4ABB-8116-660C8208D32E}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
|
|
||||||
{78A464C6-0EA9-4ABB-8116-660C8208D32E}.Debug|Mixed Platforms.Build.0 = Debug|Win32
|
|
||||||
{78A464C6-0EA9-4ABB-8116-660C8208D32E}.Debug|Win32.ActiveCfg = Debug|Win32
|
|
||||||
{78A464C6-0EA9-4ABB-8116-660C8208D32E}.Debug|Win32.Build.0 = Debug|Win32
|
|
||||||
{78A464C6-0EA9-4ABB-8116-660C8208D32E}.Release|Any CPU.ActiveCfg = Release|Win32
|
|
||||||
{78A464C6-0EA9-4ABB-8116-660C8208D32E}.Release|Mixed Platforms.ActiveCfg = Release|Win32
|
|
||||||
{78A464C6-0EA9-4ABB-8116-660C8208D32E}.Release|Mixed Platforms.Build.0 = Release|Win32
|
|
||||||
{78A464C6-0EA9-4ABB-8116-660C8208D32E}.Release|Win32.ActiveCfg = Release|Win32
|
|
||||||
{78A464C6-0EA9-4ABB-8116-660C8208D32E}.Release|Win32.Build.0 = Release|Win32
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(NestedProjects) = preSolution
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
|
||||||
HideSolutionNode = FALSE
|
|
||||||
EndGlobalSection
|
|
||||||
EndGlobal
|
|
Загрузка…
Ссылка в новой задаче