Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parser rewrite #15

Merged
merged 7 commits into from
Oct 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/Strinken/Engine/Cursor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// stylecop.header
// stylecop.header
using System;
using System.IO;

Expand Down Expand Up @@ -40,13 +40,24 @@ public Cursor(string input)
/// </summary>
public int Value { get; private set; }

/// <summary>
/// Gets the current value of the cursor as a <see cref="char"/>.
/// </summary>
public char CharValue => (char)this.Value;

/// <inheritdoc/>
public void Dispose()
{
this.Dispose(true);
GC.SuppressFinalize(this);
}

/// <summary>
/// Indicates if the cursor as reached the end.
/// </summary>
/// <returns>A value indicating whether the cursor as reached the end.</returns>
public bool HasEnded() => this.Position != -1 && this.Value == -1;

/// <summary>
/// Moves the cursor.
/// </summary>
Expand Down
5 changes: 5 additions & 0 deletions src/Strinken/Engine/Errors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ internal static class Errors
/// </summary>
public static readonly string EmptyTag = "Empty tag";

/// <summary>
/// Error: Empty name
/// </summary>
public static readonly string EmptyName = "Empty name";

/// <summary>
/// Error: Illegal '{0}' at position {1}
/// </summary>
Expand Down
58 changes: 58 additions & 0 deletions src/Strinken/Engine/ParseResult`1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// stylecop.header

namespace Strinken.Engine
{
/// <summary>
/// Base class for all parsing result.
/// </summary>
/// <typeparam name="T">The type of the parsed data.</typeparam>
internal class ParseResult<T>
{
/// <summary>
/// A failure result.
/// </summary>
public static readonly ParseResult<T> Failure = new ParseResult<T>(false, default(T), null);

/// <summary>
/// Initializes a new instance of the <see cref="ParseResult{T}"/> class.
/// </summary>
/// <param name="result">A value indicating whether the parsing was successful.</param>
/// <param name="value">The parsed value.</param>
/// <param name="message">The message associated to the parsing.</param>
private ParseResult(bool result, T value, string message)
{
this.Result = result;
this.Value = value;
this.Message = message;
}

/// <summary>
/// Gets a value indicating whether the parsing was successful.
/// </summary>
public bool Result { get; }

/// <summary>
/// Gets the parsed value.
/// </summary>
public T Value { get; }

/// <summary>
/// Gets the message associated to the parsing.
/// </summary>
public string Message { get; }

/// <summary>
/// Creates a new successful result.
/// </summary>
/// <param name="value">The parsed value.</param>
/// <returns>The result.</returns>
public static ParseResult<T> Success(T value) => new ParseResult<T>(true, value, null);

/// <summary>
/// Creates a new failure result.
/// </summary>
/// <param name="message">The message associated to the parsing.</param>
/// <returns>The result.</returns>
public static ParseResult<T> FailureWithMessage(string message) => new ParseResult<T>(false, default(T), message);
}
}
Loading