jackfiled
cf19f8197e
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>
28 lines
1.0 KiB
C#
28 lines
1.0 KiB
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>
|
|
internal sealed 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(Message, exception);
|
|
|
|
public string Message => $"Exception occured: {exception}.";
|
|
|
|
public IFailedResult<TToken, TNext> Convert<TNext>()
|
|
=> new FailedResultWithException<TToken, TState, TNext>(exception, state);
|
|
|
|
public override string ToString() => $"Parse failed: {Message}.";
|
|
}
|