using CanonSharp.Combinator.Abstractions;
namespace CanonSharp.Combinator.Results;
///
/// 实际实现的解析成功结果
///
/// 解析结果
/// 解析成功之后的下一个输入流状态
/// 输入流类型
/// 输入流的状态类型
/// 解析结果的类型
internal sealed class InternalSuccessfulResult(T result, TState state)
: ISuccessfulResult
where TState : IReadState
{
public T Value => result;
public IParseResult RunNext(IParser parser,
Func, IParseResult> continuation)
=> parser.Run(state, continuation);
public IParseResult Map(Func map)
=> new InternalSuccessfulResult(map(Value), state);
public override string ToString() => Value?.ToString() ?? string.Empty;
}