Golang go/token.File.MergeLine function examples

package go/token

MergeLine merges a line(1st parameter) with the following line. It is akin to replacing the newline character at the end of the line with a space (to not change the remaining offsets). To obtain the line number, consult e.g. Position.Line. MergeLine will panic if given an invalid line number.

Golang go/token.File.MergeLine function examples

Example 1:

 if len(d.Specs) > 0 {
 lastSpec := d.Specs[len(d.Specs)-1]
 lastLine := fset.Position(lastSpec.Pos()).Line
 if rParenLine := fset.Position(d.Rparen).Line; rParenLine > lastLine+1 {
  fset.File(d.Rparen).MergeLine(rParenLine - 1) // <-- here
 }
 }

Example 2:

 p := s.Pos()
 fset.File(p).MergeLine(fset.Position(p).Line)

Reference :

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

Advertisement