Files
2025-06-04 16:13:32 +09:30

28 lines
777 B
C#

namespace Sprache
{
partial class Parse
{
/// <summary>
/// Construct a parser that will set the position to the position-aware
/// T on succsessful match.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="parser"></param>
/// <returns></returns>
public static Parser<T> Positioned<T>(this Parser<T> parser) where T : IPositionAware<T>
{
return i =>
{
var r = parser(i);
if (r.WasSuccessful)
{
return Result.Success(r.Value.SetPos(Position.FromInput(i), r.Remainder.Position - i.Position), r.Remainder);
}
return r;
};
}
}
}