using CanonSharp.Combinator.Abstractions; namespace CanonSharp.Combinator.Parsers.Modifiers; /// /// 翻转结果的解析器 /// 当成功时失败 /// 当失败时返回指定的成功结果 /// /// 上游解析器 /// 期望中的结果 /// 输入流的类型 /// 上游解析器结果类型 /// 最终的返回结果 internal sealed class ReverseParser(Parser parser, T result) : ModifiedParser(parser) { protected override ParseResult Succeed(TState state, SuccessfulResult successfulResult) => ParseResultBuilder.Fail($"Unexpected successful result: {successfulResult.Value}", state); protected override ParseResult Fail(TState state, FailedResult failedResult) => ParseResultBuilder.Succeed(result, state); }