CanonSharp/CanonSharp.Combinator/Results/FailedResultWithMessage.cs

28 lines
925 B
C#
Raw Normal View History

using CanonSharp.Combinator.Abstractions;
namespace CanonSharp.Combinator.Results;
/// <summary>
/// 消息类型的失败解析结果
/// </summary>
/// <param name="message">解析失败的消息</param>
/// <param name="state">当前读取的状态</param>
/// <typeparam name="TToken">输入流的类型</typeparam>
/// <typeparam name="TState">读取状态类型</typeparam>
/// <typeparam name="T">解析结果的类型</typeparam>
internal sealed class FailedResultWithMessage<TToken, TState, T>(string message, TState state)
: IFailedResult<TToken, T>
where TState : IReadState<TToken, TState>
{
public IReadState<TToken> State => state;
public string Message => message;
public IFailedResult<TToken, TNext> Convert<TNext>()
{
return new FailedResultWithMessage<TToken, TState, TNext>(message, state);
}
public override string ToString() => $"Parse failed: {Message}.";
}