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