using CanonSharp.Combinator.Abstractions;
namespace CanonSharp.Combinator.Parsers.Primitives;
///
/// 满足指定条件即成功的解析器
///
/// 满足的条件谓词
/// 输入流类型
internal sealed class SatisfyParser(Func predicate) : PrimitiveParser
{
protected override IParseResult Run(TState state)
{
return state.HasValue && predicate(state.Current)
? ParseResultBuilder.Succeed(state.Current, state.Next)
: ParseResultBuilder.Fail(state);
}
}