Standard library / go/token
go/token.File.PositionFor()
Selects adjusted or physical coordinates, depending on the boolean argument. Expected stdout: 'virtual.go:10:1 demo.go:2:1\n'.
Formal Syntax & Structure
go syntaxgo
func (f *File) PositionFor(p Pos, adjusted bool) (pos Position)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| p | Pos | Compact source position in the associated file set. |
| adjusted | bool | Whether to honor position-altering line directives. |
Return Value
(pos Position)
Selects adjusted or physical coordinates, depending on the boolean argument.
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")) f.AddLineColumnInfo(3, "virtual.go", 10, 1) fmt.Println(f.PositionFor(f.Pos(3), true), f.PositionFor(f.Pos(3), false))}