2024-08-13 14:46:11 +08:00
|
|
|
namespace CanonSharp.Combinator.Abstractions;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 解析器结果
|
|
|
|
/// </summary>
|
|
|
|
/// <typeparam name="TToken">输入流类型</typeparam>
|
|
|
|
/// <typeparam name="T">实际结果类型</typeparam>
|
2024-08-18 12:01:27 +08:00
|
|
|
public interface IParseResult<TToken, out T>
|
2024-08-13 14:46:11 +08:00
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// 实际结果对象
|
|
|
|
/// </summary>
|
2024-08-18 12:01:27 +08:00
|
|
|
public T Value { get; }
|
2024-08-13 14:46:11 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 在当前结果上应用下一个解析器
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="nextParser">下一个解析器的函数</param>
|
|
|
|
/// <param name="continuation">处理解析结果的后继函数</param>
|
|
|
|
/// <typeparam name="TNext">下一个解析器函数返回的解析结果类型</typeparam>
|
|
|
|
/// <typeparam name="TResult">最终的解析结果类型</typeparam>
|
|
|
|
/// <returns></returns>
|
2024-08-18 12:01:27 +08:00
|
|
|
internal IParseResult<TToken, TResult> Next<TNext, TResult>(Func<T, IParser<TToken, TNext>> nextParser,
|
|
|
|
Func<IParseResult<TToken, TNext>, IParseResult<TToken, TResult>> continuation);
|
2024-08-13 14:46:11 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 映射结果
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="map">映射结果的函数</param>
|
|
|
|
/// <typeparam name="TResult">映射结果函数返回解析结果的类型</typeparam>
|
|
|
|
/// <returns>最终的解析结果</returns>
|
2024-08-18 12:01:27 +08:00
|
|
|
public IParseResult<TToken, TResult> Map<TResult>(Func<T, TResult> map);
|
2024-08-13 14:46:11 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 在成功或者失败解析结果上应用不同的后继函数
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="successfulHandler">在成功解析结果上应用的函数</param>
|
|
|
|
/// <param name="failedHandler">在失败解析结构上应用的函数</param>
|
|
|
|
/// <typeparam name="TResult">最后返回解析结果的类型</typeparam>
|
|
|
|
/// <returns>最后的解析结果</returns>
|
2024-08-18 12:01:27 +08:00
|
|
|
public TResult CaseOf<TResult>(Func<ISuccessfulResult<TToken, T>, TResult> successfulHandler,
|
|
|
|
Func<IFailedResult<TToken, T>, TResult> failedHandler);
|
2024-08-13 14:46:11 +08:00
|
|
|
}
|