Skip to content
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

go/token: be clearer that Column is a byte count #9948

Closed
rsc opened this issue Feb 20, 2015 · 0 comments
Closed

go/token: be clearer that Column is a byte count #9948

rsc opened this issue Feb 20, 2015 · 0 comments
Milestone

Comments

@rsc
Copy link
Contributor

rsc commented Feb 20, 2015

I looked through the source code to find out, and it appears to me that in

// Position describes an arbitrary source position
// including the file, line, and column location.
// A Position is valid if the line number is > 0.
//
type Position struct {
    Filename string // filename, if any
    Offset   int    // offset, starting at 0
    Line     int    // line number, starting at 1
    Column   int    // column number, starting at 1 (character count)
}

the Column is a byte count, not a character (rune) count. Bytes are much more useful when you're holding a []byte anyway, so that's what I was hoping. Probably docs should be updated.

It might also help here:

To create the Pos value for a specific source offset, first add the
respective file to the current file set (via FileSet.AddFile) and then
call File.Pos(offset) for that file. Given a Pos value p for a specific
file set fset, the corresponding Position value is obtained by calling
fset.Position(p).

to say "a specific source file offset (measured in bytes)". It may be that token is agnostic about this and the bytes part is imposed by go/scanner, but this is where people will look. Maybe "usually measured in bytes" if that's a concern.

@rsc rsc added this to the Go1.5 milestone Feb 20, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants