Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Closed
dmajda opened this Issue · 4 comments

3 participants

@dmajda
Owner

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

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.

@dmajda
Owner

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.

@tonylukasavage

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

@dmajda dmajda was assigned
@dmajda
Owner

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

@dmajda dmajda closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.