using CanonSharp.Combinator.Abstractions;
namespace CanonSharp.Combinator.Parsers.Modifiers;
///
/// 向前看解析器
/// 使用传入的解析器向前解析
/// 但是返回的结果中输入流读取状态不前移
///
/// 需要向前看的解析器
/// 输入流令牌
/// 返回的解析结果类型
internal sealed class LookAheadParser(IParser parser) : ModifiedParser(parser)
{
protected override IParseResult Succeed(TState state,
ISuccessfulResult successfulResult)
=> ParseResultBuilder.Succeed(successfulResult.Value, state);
protected override IParseResult Fail(TState state, IFailedResult failedResult)
=> ParseResultBuilder.Fail($"Failed when looking ahead: {failedResult}", state);
}