OXIESEC PANEL
- Current Dir:
/
/
opt
/
golang
/
1.19.4
/
src
/
go
/
token
Server IP: 2a02:4780:11:1084:0:327f:3464:10
Upload:
Create Dir:
Name
Size
Modified
Perms
📁
..
-
12/01/2022 06:13:56 PM
rwxr-xr-x
📄
example_test.go
1.66 KB
12/01/2022 06:12:58 PM
rw-r--r--
📄
position.go
17.29 KB
12/01/2022 06:12:58 PM
rw-r--r--
📄
position_bench_test.go
484 bytes
12/01/2022 06:12:58 PM
rw-r--r--
📄
position_test.go
9.18 KB
12/01/2022 06:12:58 PM
rw-r--r--
📄
serialize.go
1.43 KB
12/01/2022 06:12:58 PM
rw-r--r--
📄
serialize_test.go
2.47 KB
12/01/2022 06:12:58 PM
rw-r--r--
📄
token.go
6.36 KB
12/01/2022 06:12:58 PM
rw-r--r--
📄
token_test.go
796 bytes
12/01/2022 06:12:58 PM
rw-r--r--
Editing: example_test.go
Close
// Copyright 2018 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package token_test import ( "fmt" "go/ast" "go/parser" "go/token" ) func Example_retrievePositionInfo() { fset := token.NewFileSet() const src = `package main import "fmt" import "go/token" //line :1:5 type p = token.Pos const bad = token.NoPos //line fake.go:42:11 func ok(pos p) bool { return pos != bad } /*line :7:9*/func main() { fmt.Println(ok(bad) == bad.IsValid()) } ` f, err := parser.ParseFile(fset, "main.go", src, 0) if err != nil { fmt.Println(err) return } // Print the location and kind of each declaration in f. for _, decl := range f.Decls { // Get the filename, line, and column back via the file set. // We get both the relative and absolute position. // The relative position is relative to the last line directive. // The absolute position is the exact position in the source. pos := decl.Pos() relPosition := fset.Position(pos) absPosition := fset.PositionFor(pos, false) // Either a FuncDecl or GenDecl, since we exit on error. kind := "func" if gen, ok := decl.(*ast.GenDecl); ok { kind = gen.Tok.String() } // If the relative and absolute positions differ, show both. fmtPosition := relPosition.String() if relPosition != absPosition { fmtPosition += "[" + absPosition.String() + "]" } fmt.Printf("%s: %s\n", fmtPosition, kind) } //Output: // // main.go:3:1: import // main.go:5:1: import // main.go:1:5[main.go:8:1]: type // main.go:3:1[main.go:10:1]: const // fake.go:42:11[main.go:13:1]: func // fake.go:7:9[main.go:17:14]: func }