Skip to content

Position line and column should start at zero #94

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jamesdbrock opened this issue Sep 8, 2020 · 2 comments
Closed

Position line and column should start at zero #94

jamesdbrock opened this issue Sep 8, 2020 · 2 comments
Labels
type: breaking change A change that requires a major version bump.

Comments

@jamesdbrock
Copy link
Member

Position line and column should start at 0, not 1.

initialPos = Position { line: 1, column: 1 }

This has been super inconvenient for me on several occasions.

https://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html

This would be an easy change to make, but the hard part would be not breaking downstream dependents.

@jamesdbrock
Copy link
Member Author

Actually what would be better is to add a field to Position

initialPos  = Position { line: 1, column: 1, offset: 0 }

so then we can track both the lines-based and offset-based positions.

From an API perspective, it is too easy for a library user to construct this Position with an invalid state.

On the other hand, it was already easy for the library user to construct an invalid state, since for each line
of input, a different range of columns is valid.

Perhaps it would be better to instead add

newtype Offset = Offset Int

initialOffset  = Offset 0

offset :: forall s m. Monad m => ParserT s m Offset

@thomashoneyman
Copy link
Contributor

thomashoneyman commented Sep 9, 2020

Thanks for opening this issue @jamesdbrock. I’m not personally familiar with the background behind why this library starts at 1, so I’m going to defer to other maintainers on that. But just wanted to let you know this was seen!

@thomashoneyman thomashoneyman added the type: breaking change A change that requires a major version bump. label Jan 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: breaking change A change that requires a major version bump.
Development

No branches or pull requests

2 participants