CanonSharp/CanonSharp.Combinator/Results/FailedResultWithMessage.cs
jackfiled cf19f8197e feat: Grammar Parser (#3)
Reviewed-on: https://git.bupt-hpc.cn/jackfiled/CanonSharp/pulls/3
Co-authored-by: jackfiled <xcrenchangjun@outlook.com>
Co-committed-by: jackfiled <xcrenchangjun@outlook.com>
2024-08-18 12:01:27 +08:00

28 lines
925 B
C#

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}.";
}