import ( "fmt" "go/token" ) func main() { fileSet := token.NewFileSet() // Add a file to the file set file := fileSet.AddFile("example.go", fileSet.Base(), 100) fmt.Println("File:", file.Name()) // Create a position in the file pos := token.Pos(150) fmt.Println("Position:", pos) // Get the position information position := fileSet.Position(pos) fmt.Println("Line:", position.Line) fmt.Println("Column:", position.Column) fmt.Println("Filename:", position.Filename) }
import ( "fmt" "go/token" ) func main() { fileSet := token.NewFileSet() // Add multiple files to the file set file1 := fileSet.AddFile("a.go", fileSet.Base(), 100) file2 := fileSet.AddFile("b.go", fileSet.Base(), 200) // Create positions in both files pos1 := file1.Pos(150) pos2 := file2.Pos(100) // Get the position information position1 := fileSet.Position(pos1) position2 := fileSet.Position(pos2) fmt.Println("File 1:", position1.Filename, "Line:", position1.Line) fmt.Println("File 2:", position2.Filename, "Line:", position2.Line) }In this example, we create a `FileSet` and add two source files to it. We then create `Position` objects representing positions in each file and use the `Position` method of the `FileSet` to get the file and line information for each position. The `go/token` package is a part of the standard library of Go.