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
+16.5k Golang : Execute terminal command to remote machine example
+28.8k Golang : Detect (OS) Operating System
+32.2k Golang : Convert []string to []byte examples
+5.6k PHP : Convert string to timestamp or datestamp before storing to database(MariaDB/MySQL)
+9.7k Golang : Load ASN1 encoded DSA public key PEM file example
+6.2k PHP : Get client IP address
+7.9k Javascript : Put image into Chrome browser's console
+7.6k SSL : How to check if current certificate is sha1 or sha2 from command line
+6.6k Golang : Totalize or add-up an array or slice example
+5k Golang : Constant and variable names in native language
+15.9k Golang : Get file permission
+21.9k Golang : Use TLS version 1.2 and enforce server security configuration over client