Golang go/token.File.Position function examples
package go/token
Position returns the Position value for the given file position p(1st parameter); p must be a Pos value in that file or NoPos.
Golang go/token.File.Position function usage examples
Example 1:
fs := token.NewFileSet()
tf := fs.AddFile("", fs.Base(), len(data))
tf.SetLinesForContent(data)
pos := tf.Position(tf.Pos(offset))
return pos.Line, pos.Column
Example 2:
// verify scan
var S Scanner
file := fset.AddFile(filepath.Join("dir", "TestLineComments"), fset.Base(), len(src))
S.Init(file, []byte(src), nil, dontInsertSemis)
for _, s := range segs {
p, _, lit := S.Scan()
pos := file.Position(p)
checkPos(t, lit, p, token.Position{
Filename: s.filename,
Offset: pos.Offset,
Line: s.line,
Column: pos.Column,
})
}
Reference :
Advertisement
Something interesting
Tutorials
+17.7k Golang : Read data from config file and assign to variables
+7.8k Golang : Regular Expression find string example
+14k Golang : Compress and decompress file with compress/flate example
+8.9k Golang : GMail API create and send draft with simple upload attachment example
+5.4k Golang : fmt.Println prints out empty data from struct
+7.4k Linux : How to fix Brother HL-1110 printing blank page problem
+20k Golang : Convert(cast) bytes.Buffer or bytes.NewBuffer type to io.Reader
+4.7k Adding Skype actions such as call and chat into web page examples
+40.5k Golang : Convert to io.ReadSeeker type
+8.2k Golang : Find relative luminance or color brightness
+7.5k Golang : How to handle file size larger than available memory panic issue
+6k Fontello : How to load and use fonts?