jackfiled
3ed8bf5d36
All checks were successful
Run unit test / Unit-Test (push) Successful in 41s
Reviewed-on: https://git.bupt-hpc.cn/jackfiled/CanonSharp/pulls/2 Co-authored-by: jackfiled <xcrenchangjun@outlook.com> Co-committed-by: jackfiled <xcrenchangjun@outlook.com>
28 lines
1.1 KiB
C#
28 lines
1.1 KiB
C#
using CanonSharp.Combinator.Abstractions;
|
|
|
|
namespace CanonSharp.Combinator.Parsers.Primitives;
|
|
|
|
/// <summary>
|
|
/// 直接成功的解析器
|
|
/// </summary>
|
|
/// <param name="value">解析成功返回的值</param>
|
|
/// <typeparam name="TToken">输入流类型</typeparam>
|
|
/// <typeparam name="T">解析成功返回值的类型</typeparam>
|
|
internal sealed class PureParser<TToken, T>(T value) : PrimitiveParser<TToken, T>
|
|
{
|
|
protected override ParseResult<TToken, T> Run<TState>(TState state)
|
|
=> ParseResultBuilder.Succeed<TToken, TState, T>(value, state);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 按照输入状态返回结果的始终成功解析器
|
|
/// </summary>
|
|
/// <param name="valueFunc">按照输入状态返回解析结果的函数</param>
|
|
/// <typeparam name="TToken">输入流类型</typeparam>
|
|
/// <typeparam name="T">解析成功返回值的类型</typeparam>
|
|
internal sealed class DelayedPureParser<TToken, T>(Func<IReadState<TToken>, T> valueFunc) : PrimitiveParser<TToken, T>
|
|
{
|
|
protected override ParseResult<TToken, T> Run<TState>(TState state)
|
|
=> ParseResultBuilder.Succeed<TToken, TState, T>(valueFunc(state), state);
|
|
}
|