using CanonSharp.Combinator.Abstractions;
namespace CanonSharp.Combinator.Parsers.Primitives;
///
/// 直接失败的解析器
///
/// 输入流类型
/// 解析结果的类型
internal sealed class FailedParser : PrimitiveParser
{
protected override IParseResult Run(TState state)
=> ParseResultBuilder.Fail(state);
}
///
/// 含有失败信息的失败解析器
///
/// 失败信息
/// 输入流类型
/// 解析结果的类型
internal sealed class FailedParserWithMessage(string message) : PrimitiveParser
{
protected override IParseResult Run(TState state)
=> ParseResultBuilder.Fail(message, state);
}
///
/// 按照输入状态产生失败信息的失败解析器
///
/// 产生失败信息的函数
/// 输入流类型
/// 解析结果的类型
internal sealed class FailedParserWithDelayedMessage(Func, string> messageFunc)
: PrimitiveParser
{
protected override IParseResult Run(TState state)
=> ParseResultBuilder.Fail(messageFunc(state), state);
}
///
/// 含有失败异常的失败解析器
///
/// 异常
/// 输入流类型
/// 解析结果的类型
internal sealed class FailedParserWithException(Exception e) : PrimitiveParser
{
protected override IParseResult Run(TState state)
=> ParseResultBuilder.Fail(e, state);
}