Skip to content

Commit

Permalink
feature: made functionality public needed for custom tokenizers
Browse files Browse the repository at this point in the history
  • Loading branch information
Ewout Kramer committed Mar 27, 2019
1 parent c8eeff8 commit 9c2674f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/Superpower/Display/Presentation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@

namespace Superpower.Display
{
static class Presentation
/// <summary>
///
/// </summary>
public static class Presentation
{
static string FormatKind(object kind)
{
Expand All @@ -39,6 +42,12 @@ static TokenAttribute TryGetTokenAttribute<TKind>(TKind kind)
return null;
}

/// <summary>
///
/// </summary>
/// <typeparam name="TKind"></typeparam>
/// <param name="kind"></param>
/// <returns></returns>
public static string FormatExpectation<TKind>(TKind kind)
{
var description = TryGetTokenAttribute(kind);
Expand All @@ -53,6 +62,13 @@ public static string FormatExpectation<TKind>(TKind kind)
return FormatKind(kind);
}

/// <summary>
///
/// </summary>
/// <typeparam name="TKind"></typeparam>
/// <param name="kind"></param>
/// <param name="value"></param>
/// <returns></returns>
public static string FormatAppearance<TKind>(TKind kind, string value)
{
var clipped = FormatLiteral(Friendly.Clip(value, 12));
Expand All @@ -69,6 +85,11 @@ public static string FormatAppearance<TKind>(TKind kind, string value)

return $"{FormatKind(kind)} {clipped}";
}
/// <summary>
///
/// </summary>
/// <param name="literal"></param>
/// <returns></returns>
public static string FormatLiteral(char literal)
{
switch (literal)
Expand Down Expand Up @@ -137,6 +158,11 @@ public static string FormatLiteral(char literal)
}
}

/// <summary>
///
/// </summary>
/// <param name="literal"></param>
/// <returns></returns>
public static string FormatLiteral(string literal)
{
return "`" + literal + "`";
Expand Down
14 changes: 14 additions & 0 deletions src/Superpower/Model/Result.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,20 @@ public static Result<T> Value<T>(T value, TextSpan location, TextSpan remainder)
return new Result<T>(value, location, remainder, false);
}

/// <summary>
/// Create a new Result based on another Result, supplying just the values to override
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="original"></param>
/// <param name="remainder"></param>
/// <param name="errorMessage"></param>
/// <param name="expectations"></param>
/// <returns></returns>
public static Result<T> Augment<T>(this Result<T> original, TextSpan? remainder, string errorMessage, string[] expectations)
{
return new Result<T>(remainder ?? original.Remainder, errorMessage ?? original.ErrorMessage, expectations ?? original.Expectations, original.Backtrack);
}

/// <summary>
/// Convert an empty result of one type into another.
/// </summary>
Expand Down

0 comments on commit 9c2674f

Please sign in to comment.