Decide whether line and column should be 0-based or 1-based #76

Closed
dmajda opened this Issue Apr 20, 2012 · 4 comments

Comments

Projects
None yet
3 participants
Contributor

dmajda commented Apr 20, 2012

Currently all line and column indexes in PEG.js are 1-based. This is OK if this information is mostly presented to users, but it can inconvenient for machine processing where 0-based indexes would often work better.

The line and column indexes are currently visible on two places:

  • line and column properties of exceptions thrown on parse errors
  • line and column variables inside actions and predicates (available if the parser was built with the trackLineAndColumn option)

Indexing should be consistent on both.

For me, the question whether to have 0-based or 1-based reduces to a question whether the "display to users" or "use for computation" use case happens more often. I need to wait for users to adopt 0.7.0 (where position tracking was implemented for the first time) to answer that.

This was split off from #33 where this issue was raised by @paulftw.

otac0n commented May 3, 2012

Is it possible to just make this a configurable option?

I would say that, in general, it is easier for a programmer to handle 1-based indices than it is for an end user to handle 0-based indices. So, I think the default of 1 is good, but if someone wanted to override it, that would be nice.

Contributor

dmajda commented May 5, 2012

I would say that, in general, it is easier for a programmer to handle 1-based indices than it is for an end user to handle 0-based indices.

That's a sound argument, I like it.

Is it possible to just make this a configurable option?

No way :-) Something this trivial shouldn't be configurable.

Contributor

tonylukasavage commented May 30, 2012

I vote 1-based. 0-based doens't make much sense in the context of line numbers

@ghost ghost assigned dmajda Nov 22, 2012

Contributor

dmajda commented Nov 22, 2012

There were no additional complaints from users about this, so let's keep the current way. Closing.

@dmajda dmajda closed this Nov 22, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment