25 lines
948 B
C#
25 lines
948 B
C#
using CanonSharp.Combinator.Abstractions;
|
|
|
|
namespace CanonSharp.Combinator.Results;
|
|
|
|
/// <summary>
|
|
/// 异常类型的失败解析结果
|
|
/// </summary>
|
|
/// <param name="exception">解析中发生的异常</param>
|
|
/// <param name="state">当前输入流的状态</param>
|
|
/// <typeparam name="TToken">输入流类型</typeparam>
|
|
/// <typeparam name="TState">当前输入流状态的类型</typeparam>
|
|
/// <typeparam name="T">解析结果的类型</typeparam>
|
|
public class FailedResultWithException<TToken, TState, T>(Exception exception, TState state) : IFailedResult<TToken, T>
|
|
where TState : IReadState<TToken, TState>
|
|
{
|
|
public IReadState<TToken> State => state;
|
|
|
|
public ParseException Exception => new(ToString(), exception);
|
|
|
|
public string Message => $"Exception occured: {exception}.";
|
|
|
|
public IFailedResult<TToken, TNext> Convert<TNext>()
|
|
=> new FailedResultWithException<TToken, TState, TNext>(exception, state);
|
|
}
|