On Friday, 11 May 2012 at 13:25:53 UTC, Jacob Carlborg wrote:
On 2012-05-11 15:01, Roman D. Boiko wrote:

What about the following signature: Location locate(size_t index)?
Or even better:
alias size_t CodeUnitIndex;
Location locateFor(CodeUnitIndex position);

That is better although I would prefer to pass in a token (assuming that is where index is declared). Then it would be an implementation detail that "index" is used to get the location.
It is also what I was planning to do after I posted my last suggestion. Unless I will discover some conceptual problem with that, which is unlikely.

Another option would be to turn it around:

sturct/class Location
{
    Location find/locate (Token token);
}

The problem with placing it in Token is that Token should not know
anything about source as a whole.

I see. For convenience there could be properties defined that just forwards the call to some other function.
Both these cases would introduce circular dependency between Lexer and its output data (Location or Token). It is possible to break such dependency via complicating things even more, or live with it. But I don't like circular dependencies when there is no compelling reason to introduce them.

Reply via email to