using System.Runtime.CompilerServices; using CanonSharp.Combinator.Abstractions; using CanonSharp.Combinator.Results; namespace CanonSharp.Combinator; /// /// 相关的扩展方法 /// public static class ParseResultBuilder { /// /// 生成解析成功的结果 /// /// 解析成功的对象 /// 下一个输入流状态 /// 输入流类型 /// 输入流状态类型 /// 解析成功的对象类型 /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ParseResult Succeed(T value, TState state) where TState : IReadState => new InternalSuccessfulResult(value, state); /// /// 生成错误类型的解析失败结果 /// /// 解析的输入流状态 /// 输入流类型 /// 输入流状态类型 /// 解析成功的对象类型 /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ParseResult Fail(TState state) where TState : IReadState => new FailedResultWithError(state); /// /// 生成消息类型的解析失败结果 /// /// 错误消息 /// 输入流状态 /// 输入流类型 /// 输入流状态类型 /// 解析成功的对象类型 /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ParseResult Fail(string message, TState state) where TState : IReadState => new FailedResultWithMessage(message, state); /// /// 生成异常类型的解析失败结果 /// /// 解析异常 /// 输入流状态 /// 输入流类型 /// 输入流状态类型 /// 解析成功的对象类型 /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ParseResult Fail(Exception exception, TState state) where TState : IReadState => new FailedResultWithException(exception, state); }