CanonSharp/CanonSharp.Combinator/Results/FailedResultWithException.cs
jackfiled 3ed8bf5d36
All checks were successful
Run unit test / Unit-Test (push) Successful in 41s
feat: Parser Combinator库和词法分析器 (#2)
Reviewed-on: https://git.bupt-hpc.cn/jackfiled/CanonSharp/pulls/2
Co-authored-by: jackfiled <xcrenchangjun@outlook.com>
Co-committed-by: jackfiled <xcrenchangjun@outlook.com>
2024-08-13 14:46:11 +08:00

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);
}