using CanonSharp.Combinator.Abstractions;
using CanonSharp.Combinator.Extensions;
namespace CanonSharp.Combinator.Parsers.Primitives;
///
/// 跳过指定数量的输入令牌
///
/// 需要跳过的令牌数量
/// 输入流类型
internal sealed class SkipParser(int count) : PrimitiveParser
{
protected override ParseResult Run(TState state)
{
List result = state.AsEnumerable().Take(count).ToList();
return result.Count == count
? ParseResultBuilder.Succeed(Unit.Instance,
result.Count == 0 ? state : result.Last().Next)
: ParseResultBuilder.Fail("An input does not have required length.", state);
}
}