21 lines
860 B
C#
21 lines
860 B
C#
|
using CanonSharp.Combinator.Abstractions;
|
||
|
|
||
|
namespace CanonSharp.Combinator.Parsers.Bases;
|
||
|
|
||
|
/// <summary>
|
||
|
/// 单子解析器
|
||
|
/// </summary>
|
||
|
/// <param name="parser">上游解析器</param>
|
||
|
/// <param name="next">下游解析器生成函数</param>
|
||
|
/// <typeparam name="TToken">输入流类型</typeparam>
|
||
|
/// <typeparam name="TIntermediate">上游解析器结果类型</typeparam>
|
||
|
/// <typeparam name="T">下游解析器结果类型</typeparam>
|
||
|
internal sealed class BindParser<TToken, TIntermediate, T>(
|
||
|
Parser<TToken, TIntermediate> parser,
|
||
|
Func<TIntermediate, Parser<TToken, T>> next) : Parser<TToken, T>
|
||
|
{
|
||
|
internal override ParseResult<TToken, TResult> Run<TState, TResult>(TState state,
|
||
|
Func<ParseResult<TToken, T>, ParseResult<TToken, TResult>> continuation)
|
||
|
=> parser.Run(state, result => result.Next(next, continuation));
|
||
|
}
|