CanonSharp/CanonSharp.Combinator/Results/FailedResultWithError.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

25 lines
810 B
C#

using CanonSharp.Combinator.Abstractions;
namespace CanonSharp.Combinator.Results;
/// <summary>
/// 错误类型的失败解析结果
/// </summary>
/// <typeparam name="TToken">输入流的类型</typeparam>
/// <typeparam name="TState">输入流的读取类型</typeparam>
/// <typeparam name="T">实际的结果类型</typeparam>
internal sealed class FailedResultWithError<TToken, TState, T>(TState state) : IFailedResult<TToken, T>
where TState : IReadState<TToken, TState>
{
public IReadState<TToken> State => state;
public string Message => $"Unexpected state: {state}.";
public IFailedResult<TToken, TNext> Convert<TNext>()
{
return new FailedResultWithError<TToken, TState, TNext>(state);
}
public override string ToString() => $"Parse failed: {Message}.";
}