26 lines
961 B
C#
26 lines
961 B
C#
|
using CanonSharp.Combinator.Abstractions;
|
||
|
|
||
|
namespace CanonSharp.Combinator.Parsers;
|
||
|
|
||
|
/// <summary>
|
||
|
/// 解析器原型基类
|
||
|
/// 实际上就是处理了一个后继调用
|
||
|
/// </summary>
|
||
|
/// <typeparam name="TToken">输入流类型</typeparam>
|
||
|
/// <typeparam name="T">解析结果的类型</typeparam>
|
||
|
public abstract class PrimitiveParser<TToken, T> : Parser<TToken, T>
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// 运行解析器 返回解析结果
|
||
|
/// </summary>
|
||
|
/// <param name="state">当前输入流的状态</param>
|
||
|
/// <typeparam name="TState">输入流状态的类型</typeparam>
|
||
|
/// <returns>解析结果</returns>
|
||
|
protected abstract ParseResult<TToken, T> Run<TState>(TState state)
|
||
|
where TState : IReadState<TToken, TState>;
|
||
|
|
||
|
internal sealed override ParseResult<TToken, TResult> Run<TState, TResult>(TState state,
|
||
|
Func<ParseResult<TToken, T>, ParseResult<TToken, TResult>> continuation)
|
||
|
=> continuation(Run(state));
|
||
|
}
|