Standard library / go/token

go/token.File.AddLine()

Adds a strictly increasing line-start offset below file size; invalid offsets are ignored. Expected stdout: '[0 3]\n'.

Formal Syntax & Structure

go syntaxgo
func (f *File) AddLine(offset int)

Parameters & Attributes

NameTypeDescription
offsetintZero-based byte offset within the source file.

Working Example

Example Snippetgo
package main
import (  "fmt"  "go/token")
func main() {  s := token.NewFileSet()  f := s.AddFile("demo.go", -1, 5)  f.AddLine(3)  fmt.Println(f.Lines())}
Go Reference