benjamin-hodgson / Pidgin

A lightweight and fast parsing library for C#.
https://www.benjamin.pizza/Pidgin/
MIT License
883 stars 68 forks source link

Getting current position in 3.x #127

Closed atrauzzi closed 2 years ago

atrauzzi commented 2 years ago

I noticed that the 2.x versions have CurrentPos as a way to get the current position. Does a similar facility exist in 3.x?

atrauzzi commented 2 years ago

Also seeing that CurrentPos is internal right now. Is this my best option for the time being?

public class Position : Parser<char, int>
{
    public override bool TryParse(ref ParseState<char> state, ref PooledList<Expected<char>> expecteds, out int result)
    {
        result = state.Location;

        return true;
    }
}
benjamin-hodgson commented 2 years ago

It’s still public! https://github.com/benjamin-hodgson/Pidgin/blob/main/Pidgin/Parser.CurrentPos.cs#L16

atrauzzi commented 2 years ago

Ah perfect, I just needed to do using static Pidgin.Parser<char>;

Thank you! This library is incredible.

benjamin-hodgson commented 2 years ago

Thanks! ❤️