25 lines
982 B
C#
25 lines
982 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) : FailedResult<TToken, T>
|
||
|
where TState : IReadState<TToken, TState>
|
||
|
{
|
||
|
public override IReadState<TToken> State => state;
|
||
|
|
||
|
public override ParseException Exception => new(ToString(), exception);
|
||
|
|
||
|
public override string Message => $"Exception occured: {exception}.";
|
||
|
|
||
|
public override FailedResult<TToken, TNext> Convert<TNext>()
|
||
|
=> new FailedResultWithException<TToken, TState, TNext>(exception, state);
|
||
|
}
|