Standard library / go/token

go/token.File.AddLineColumnInfo()

Registers alternative filename, line and byte-column information at an increasing offset. Expected stdout: 'virtual.go:20:5\n'.

Formal Syntax & Structure

go syntaxgo
func (f *File) AddLineColumnInfo(offset int, filename string, line, column int)

Parameters & Attributes

NameTypeDescription
offsetintZero-based byte offset within the source file.
filenamestringSource filename used in diagnostics.
lineintOne-based source line number.
columnintOne-based byte column, or zero if unknown.

Working Example

Example Snippetgo
package main
import (  "fmt"  "go/token")
func main() {  s := token.NewFileSet()  f := s.AddFile("demo.go", -1, 5)  f.AddLineColumnInfo(1, "virtual.go", 20, 4)  fmt.Println(f.Position(f.Pos(2)))}
Go Reference