CanonSharp/CanonSharp.Combinator/Parsers/Bases/FixParser.cs

26 lines
757 B
C#
Raw Permalink Normal View History

using CanonSharp.Combinator.Abstractions;
namespace CanonSharp.Combinator.Parsers.Bases;
/// <summary>
/// 修正?解析器
/// 感觉是一种递归的高级实现?
///
/// </summary>
/// <typeparam name="TToken"></typeparam>
/// <typeparam name="T"></typeparam>
internal sealed class FixParser<TToken, T> : IParser<TToken, T>
{
private readonly IParser<TToken, T> _parser;
public FixParser(Func<IParser<TToken, T>, IParser<TToken, T>> func)
{
_parser = func(this);
}
public IParseResult<TToken, TResult> Run<TState, TResult>(TState state,
Func<IParseResult<TToken, T>, IParseResult<TToken, TResult>> continuation)
where TState : IReadState<TToken, TState>
=> _parser.Run(state, continuation);
}