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
+6.8k Golang : Calculate pivot points for a cross
+33k Golang : How to check if a date is within certain range?
+24.6k Golang : How to print rune, unicode, utf-8 and non-ASCII CJK(Chinese/Japanese/Korean) characters?
+26.4k Golang : Get executable name behind process ID example
+10.5k Golang : Generate 403 Forbidden to protect a page or prevent indexing by search engine
+10.8k Android Studio : Checkbox for user to select options example
+7.7k Golang : Mapping Iban to Dunging alphabets
+9.3k Golang : How to get garbage collection data?
+21.1k Golang : For loop continue,break and range
+10.7k Golang : Underscore string example
+9.9k Golang : Ordinal and Ordinalize a given number to the English ordinal numeral
+16.4k Golang : Convert slice to array