benjamin-hodgson/Pidgin

SourcePosDelta => MatchPos

Closed this issue · 1 comments

Hi,
recently, I needed to have complete information about the result of the parser: StartLine, EndLine, StartColumn, EndColumnt, StartOffset, EndOffset, Lenght.

I could get the result in the way shown in the screenshot, but that doesn't seem like an elegant solution to me. This will require some minor internal changes, but I think you could implement it out of the box.

image

What you have there looks sensible to me. If you want to improve the code you could wrap the pair of CurrentPos and CurrentOffset into something reusable,

Parser<TToken, (int, SourcePos)> FullPositionInfo { get; }
    = Map(
        ValueTuple.Create,
        CurrentOffset,
        CurrentPos
    );

It’s a fairly straightforward application of the library, so I don’t think we need to add any special support to the API, but in general I’m not against adding convenience methods such as FullPositionInfo so I’d accept a PR!