Golang go/token.File.Line function examples

package go/token

Line returns the line number for the given file position p(1st parameter); p must be a Pos value in that file or NoPos.

Golang go/token.File.Line function usage examples

Example 1:

 if file := x.fset.File(p); file != nil {
 if base := file.Base(); base <= m[1] && m[1] <= base+file.Size() {
  // match [m[0], m[1]) is within the file boundaries
  list[found].filename = file.Name()
  list[found].line = file.Line(p) // <--- here
  found++
 }
 }

Example 2:

 var p *parser
 if p.file.Line(p.pos) == p.file.Line(prev) {
  // do something
 }

Reference :

http://golang.org/pkg/go/token/#File.Line

Advertisement