This appears to be a very popular topic as there has been a couple of PRs and issues related to this. Here is the latest https://github.com/abailly/jparsec/pull/16 that made it to release 2.1 (available in maven central). There was a lengthy discussion (https://github.com/abailly/jparsec/issues/5) with various solutions envisioned but we decided not to include the Locatable
feature (yet?).
So basically, starting from 2.1 you can use withSource()
combinator or the "old-fashioned" INDEX parsers that return parsed position in the stream. Here is a proposal from @fluentfuture:
Mapper.curry(LocationAnnotated.class).sequence(Parsers.INDEX, parser, Parsers.INDEX);
public class LocationAnnotated<T> {
public LocationAnnotated(int begin, T value, int end) {...}
}