Standard library / go/token
go/token.FileSet.Position()
Converts a position to adjusted source coordinates. Expected stdout: 'demo.go:2:1\n'.
Formal Syntax & Structure
go syntaxgo
func (s *FileSet) Position(p Pos) (pos Position)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| p | Pos | Compact source position in the associated file set. |
Return Value
(pos Position)
Converts a position to adjusted source coordinates.
Working Example
Example Snippetgo
package main
import ( "fmt" "go/token")
func main() { s := token.NewFileSet() f := s.AddFile("demo.go", -1, 5) f.SetLinesForContent([]byte("ab\ncd")) fmt.Println(s.Position(f.Pos(3)))}