This commit is contained in:
Antoine Aubry 2008-08-17 21:29:50 +00:00
Родитель 72bea89e2a
Коммит e5f79eeb6b
11 изменённых файлов: 2449 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,25 @@
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.CoreCs")]
[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)]
[assembly: AssemblyKeyFile("")]

Просмотреть файл

@ -0,0 +1,103 @@
using System;
using System.IO;
namespace YamlDotNet.CoreCs
{
/// <summary>
/// Provides access to a stream and allows to peek at the next characters,
/// up to the buffer's capacity.
/// </summary>
/// <remarks>
/// This class implements a circular buffer with a fixed capacity.
/// </remarks>
public class LookAheadBuffer
{
private readonly TextReader input;
private readonly char[] buffer;
private int firstIndex;
private int count;
private bool endOfInput;
public LookAheadBuffer(TextReader input, int capacity)
{
if(input == null) {
throw new ArgumentNullException("input");
}
if(capacity < 1) {
throw new ArgumentOutOfRangeException("capacity", "The capacity must be positive.");
}
this.input = input;
buffer = new char[capacity];
}
/// <summary>
/// Gets a value indicating whether the end of the input reader has been reached.
/// </summary>
public bool EndOfInput {
get {
return endOfInput && count == 0;
}
}
/// <summary>
/// Gets the index of the character for the specified offset.
/// </summary>
private int GetIndexForOffset(int offset) {
int index = firstIndex + offset;
if(index >= buffer.Length) {
index -= buffer.Length;
}
return index;
}
/// <summary>
/// Gets the character at thhe specified offset.
/// </summary>
public char Peek(int offset) {
if(offset < 0 || offset >= buffer.Length) {
throw new ArgumentOutOfRangeException("offset", "The offset must be betwwen zero and the capacity of the buffer.");
}
Cache(offset);
if(offset < count) {
return buffer[GetIndexForOffset(offset)];
} else {
return '\0';
}
}
/// <summary>
/// Reads characters until at least <paramref name="length"/> characters are in the buffer.
/// </summary>
/// <param name="length">
/// Number of characters to cache.
/// </param>
public void Cache(int length) {
while(length >= count) {
int nextChar = input.Read();
if(nextChar >= 0) {
int lastIndex = GetIndexForOffset(count);
buffer[lastIndex] = (char)nextChar;
++count;
} else {
endOfInput = true;
return;
}
}
}
/// <summary>
/// Skips the next <paramref name="length"/> characters. Those characters must have been
/// obtained first by calling the <see cref="Peek"/> or <see cref="Cache"/> methods.
/// </summary>
public void Skip(int length) {
if(length < 1 || length > count) {
throw new ArgumentOutOfRangeException("length", "The length must be between 1 and the number of characters in the buffer. Use the Peek() and / or Cache() methods to fill the buffer.");
}
firstIndex = GetIndexForOffset(length);
count -= length;
}
}
}

61
YamlDotNet.CoreCs/Mark.cs Normal file
Просмотреть файл

@ -0,0 +1,61 @@
using System;
namespace YamlDotNet.CoreCs
{
/// <summary>
/// Represents a location inside a file
/// </summary>
public struct Mark
{
private int index;
private int line;
private int column;
/// <summary>
/// Gets / sets the absolute offset in the file
/// </summary>
public int Index {
get {
return index;
}
set {
if(value < 0) {
throw new ArgumentOutOfRangeException("Index", "Index must be greater or equal to zero.");
}
index = value;
}
}
/// <summary>
/// Gets / sets the number of the line
/// </summary>
public int Line {
get {
return line;
}
set {
if(value <= 0) {
throw new ArgumentOutOfRangeException("Line", "Line must be greater than zero.");
}
line = value;
}
}
/// <summary>
/// Gets / sets the index of the column
/// </summary>
public int Column {
get {
return column;
}
set {
if(value <= 0) {
throw new ArgumentOutOfRangeException("Column", "Column must be greater than zero.");
}
column = value;
}
}
public static readonly Mark Empty = new Mark();
}
}

185
YamlDotNet.CoreCs/Parser.cs Normal file
Просмотреть файл

@ -0,0 +1,185 @@
using System;
using System.Diagnostics;
using System.Collections.Generic;
using YamlDotNet.CoreCs.Tokens;
using YamlDotNet.CoreCs.Events;
namespace YamlDotNet.CoreCs
{
public class Parser
{
private Stack<ParserState> states = new Stack<ParserState>();
private Stack<Mark> marks = new Stack<Mark>();
private Stack<TagDirective> tagDirectives = new Stack<TagDirective>();
private bool streamStartProduced;
private bool streamEndProduced;
private bool error;
private ParserState state;
private Scanner scanner;
public Event Parse() {
/* No events after the end of the stream or error. */
if (streamEndProduced || error || state == ParserState.YAML_PARSE_END_STATE) {
return null;
}
/* Generate the next event. */
return yaml_parser_state_machine();
}
Event yaml_parser_state_machine()
{
switch (state)
{
case ParserState.YAML_PARSE_STREAM_START_STATE:
return yaml_parser_parse_stream_start();
case ParserState.YAML_PARSE_IMPLICIT_DOCUMENT_START_STATE:
return yaml_parser_parse_document_start(true);
case ParserState.YAML_PARSE_DOCUMENT_START_STATE:
return yaml_parser_parse_document_start(false);
case ParserState.YAML_PARSE_DOCUMENT_CONTENT_STATE:
return yaml_parser_parse_document_content();
case ParserState.YAML_PARSE_DOCUMENT_END_STATE:
return yaml_parser_parse_document_end();
case ParserState.YAML_PARSE_BLOCK_NODE_STATE:
return yaml_parser_parse_node(true, false);
case ParserState.YAML_PARSE_BLOCK_NODE_OR_INDENTLESS_SEQUENCE_STATE:
return yaml_parser_parse_node(true, true);
case ParserState.YAML_PARSE_FLOW_NODE_STATE:
return yaml_parser_parse_node(false, false);
case ParserState.YAML_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE:
return yaml_parser_parse_block_sequence_entry(true);
case ParserState.YAML_PARSE_BLOCK_SEQUENCE_ENTRY_STATE:
return yaml_parser_parse_block_sequence_entry(false);
case ParserState.YAML_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE:
return yaml_parser_parse_indentless_sequence_entry();
case ParserState.YAML_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE:
return yaml_parser_parse_block_mapping_key(true);
case ParserState.YAML_PARSE_BLOCK_MAPPING_KEY_STATE:
return yaml_parser_parse_block_mapping_key(false);
case ParserState.YAML_PARSE_BLOCK_MAPPING_VALUE_STATE:
return yaml_parser_parse_block_mapping_value();
case ParserState.YAML_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE:
return yaml_parser_parse_flow_sequence_entry(true);
case ParserState.YAML_PARSE_FLOW_SEQUENCE_ENTRY_STATE:
return yaml_parser_parse_flow_sequence_entry(false);
case ParserState.YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_KEY_STATE:
return yaml_parser_parse_flow_sequence_entry_mapping_key();
case ParserState.YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE:
return yaml_parser_parse_flow_sequence_entry_mapping_value();
case ParserState.YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE:
return yaml_parser_parse_flow_sequence_entry_mapping_end();
case ParserState.YAML_PARSE_FLOW_MAPPING_FIRST_KEY_STATE:
return yaml_parser_parse_flow_mapping_key(true);
case ParserState.YAML_PARSE_FLOW_MAPPING_KEY_STATE:
return yaml_parser_parse_flow_mapping_key(false);
case ParserState.YAML_PARSE_FLOW_MAPPING_VALUE_STATE:
return yaml_parser_parse_flow_mapping_value(false);
case ParserState.YAML_PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE:
return yaml_parser_parse_flow_mapping_value(true);
default:
Debug.Assert(false, "Invalid state"); /* Invalid state. */
return null;
}
}
private T Expect<T>() where T : Token {
Token token = scanner.Current;
T t = token as T;
if(t == null) {
throw new ParserException("did not found expected <stream-start>", token.Start);
} else {
scanner.MoveNext();
return t;
}
}
public Event yaml_parser_parse_stream_start() {
Tokens.StreamStart token = Expect<Tokens.StreamStart>();
state = ParserState.YAML_PARSE_IMPLICIT_DOCUMENT_START_STATE;
return new Events.StreamStart(token.Start, token.End);
}
public Event yaml_parser_parse_document_start(bool isImplicit) {
return null;
}
public Event yaml_parser_parse_document_content() {
return null;
}
public Event yaml_parser_parse_document_end() {
return null;
}
public Event yaml_parser_parse_node(bool isBlock, bool isIndentlessSequence) {
return null;
}
public Event yaml_parser_parse_block_sequence_entry(bool isFirst) {
return null;
}
public Event yaml_parser_parse_indentless_sequence_entry() {
return null;
}
public Event yaml_parser_parse_block_mapping_key(bool isFirst) {
return null;
}
public Event yaml_parser_parse_block_mapping_value() {
return null;
}
public Event yaml_parser_parse_flow_sequence_entry(bool isFirst) {
return null;
}
public Event yaml_parser_parse_flow_sequence_entry_mapping_key() {
return null;
}
public Event yaml_parser_parse_flow_sequence_entry_mapping_value() {
return null;
}
public Event yaml_parser_parse_flow_sequence_entry_mapping_end() {
return null;
}
public Event yaml_parser_parse_flow_mapping_key(bool isFirst) {
return null;
}
public Event yaml_parser_parse_flow_mapping_value(bool isEmpty) {
return null;
}
}
}

Просмотреть файл

@ -0,0 +1,15 @@
using System;
namespace YamlDotNet.CoreCs
{
public class ParserException : Exception
{
public ParserException(string description, Mark location)
{
}
}
}

Просмотреть файл

@ -0,0 +1,57 @@
using System;
namespace YamlDotNet.CoreCs
{
public enum ParserState
{
/** Expect STREAM-START. */
YAML_PARSE_STREAM_START_STATE,
/** Expect the beginning of an implicit document. */
YAML_PARSE_IMPLICIT_DOCUMENT_START_STATE,
/** Expect DOCUMENT-START. */
YAML_PARSE_DOCUMENT_START_STATE,
/** Expect the content of a document. */
YAML_PARSE_DOCUMENT_CONTENT_STATE,
/** Expect DOCUMENT-END. */
YAML_PARSE_DOCUMENT_END_STATE,
/** Expect a block node. */
YAML_PARSE_BLOCK_NODE_STATE,
/** Expect a block node or indentless sequence. */
YAML_PARSE_BLOCK_NODE_OR_INDENTLESS_SEQUENCE_STATE,
/** Expect a flow node. */
YAML_PARSE_FLOW_NODE_STATE,
/** Expect the first entry of a block sequence. */
YAML_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE,
/** Expect an entry of a block sequence. */
YAML_PARSE_BLOCK_SEQUENCE_ENTRY_STATE,
/** Expect an entry of an indentless sequence. */
YAML_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE,
/** Expect the first key of a block mapping. */
YAML_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE,
/** Expect a block mapping key. */
YAML_PARSE_BLOCK_MAPPING_KEY_STATE,
/** Expect a block mapping value. */
YAML_PARSE_BLOCK_MAPPING_VALUE_STATE,
/** Expect the first entry of a flow sequence. */
YAML_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE,
/** Expect an entry of a flow sequence. */
YAML_PARSE_FLOW_SEQUENCE_ENTRY_STATE,
/** Expect a key of an ordered mapping. */
YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_KEY_STATE,
/** Expect a value of an ordered mapping. */
YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE,
/** Expect the and of an ordered mapping entry. */
YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE,
/** Expect the first key of a flow mapping. */
YAML_PARSE_FLOW_MAPPING_FIRST_KEY_STATE,
/** Expect a key of a flow mapping. */
YAML_PARSE_FLOW_MAPPING_KEY_STATE,
/** Expect a value of a flow mapping. */
YAML_PARSE_FLOW_MAPPING_VALUE_STATE,
/** Expect an empty value of a flow mapping. */
YAML_PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE,
/** Expect nothing. */
YAML_PARSE_END_STATE
}
}

1948
YamlDotNet.CoreCs/Scanner.cs Normal file

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -0,0 +1,14 @@
using System;
using System.Globalization;
namespace YamlDotNet.CoreCs
{
public class SyntaxErrorException : Exception
{
public SyntaxErrorException(string description, Mark location)
: base(string.Format(CultureInfo.InvariantCulture, "{0} On line {1}, column {2}", description, location.Line, location.Column))
{
}
}
}

Просмотреть файл

@ -0,0 +1,41 @@
using System;
namespace YamlDotNet.CoreCs
{
public class Version
{
private readonly int major;
public int Major {
get {
return major;
}
}
private readonly int minor;
public int Minor {
get {
return minor;
}
}
public Version(int major, int minor)
{
this.major = major;
this.minor = minor;
}
public override bool Equals (object o)
{
Version other = o as Version;
return other != null && major == other.major && minor == other.minor;
}
public override int GetHashCode ()
{
return major.GetHashCode() ^ minor.GetHashCode();
}
}
}

Двоичный файл не отображается.

Двоичный файл не отображается.