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