using CanonSharp.Combinator.Abstractions;
namespace CanonSharp.Combinator.Parsers;
///
/// 修改解析器返回结果的解析器基类
///
/// 需要修改结果的解析器
/// 输入流类型
/// 需要修改结果的解析器
/// 最终返回的解析结果
public abstract class ModifiedParser(Parser parser) : Parser
{
protected abstract ParseResult Fail(TState state,
FailedResult failedResult)
where TState : IReadState;
protected abstract ParseResult Succeed(TState state,
SuccessfulResult successfulResult)
where TState : IReadState;
internal override ParseResult Run(TState state,
Func, ParseResult> continuation)
=> parser.Run(state, result => result.CaseOf(
success => continuation(Succeed(state, success)),
failure => continuation(Fail(state, failure))));
}