Frédéric G. MARAND 3 vuotta sitten
vanhempi
sitoutus
2e535a9e3f
5 muutettua tiedostoa jossa 55 lisäystä ja 4 poistoa
  1. 1 1
      decl.go
  2. 33 0
      expr.go
  3. 8 1
      main.go
  4. 11 1
      parse.go
  5. 2 1
      stmt.go

+ 1 - 1
decl.go

@@ -23,7 +23,7 @@ func parseGenDecl(loc string, d *ast.GenDecl) {
 		switch s := s.(type) {
 		case *ast.TypeSpec:
 			parseTypeSpec(loc, s)
-		case *ast.ImportSpec:
+		case *ast.ImportSpec, *ast.ValueSpec:
 			// rien
 		default:
 			fmt.Printf("%s/(%T)\n", loc, s)

+ 33 - 0
expr.go

@@ -0,0 +1,33 @@
+package main
+
+import (
+	"fmt"
+	"go/ast"
+)
+
+func parseTypeExpr(loc string, s ast.Expr, ln bool) {
+	switch s := s.(type) {
+	case *ast.ArrayType:
+		if s.Len == nil {
+			fmt.Print("slice of ")
+		} else {
+			fmt.Print("array of ")
+		}
+		parseTypeExpr(loc, s.Elt, false)
+	case *ast.ChanType:
+		fmt.Print("chan of ")
+		parseTypeExpr(loc, s.Value, false)
+	case *ast.Ident:
+		fmt.Print(s)
+	case *ast.MapType:
+		fmt.Print("map of ")
+		parseTypeExpr(loc, s.Value, false)
+		fmt.Print(" by ")
+		parseTypeExpr(loc, s.Key, false)
+	default:
+		fmt.Printf("type: %#v\n", s)
+	}
+	if ln {
+		fmt.Println()
+	}
+}

+ 8 - 1
main.go

@@ -11,7 +11,14 @@ import (
 	"log"
 )
 
-type packageScope bool
+type (
+	psDefined bool
+	psAlias   = bool
+	psSlice   []bool
+	psArray   [4]bool
+	psChan    chan bool
+	psMap     map[bool]bool
+)
 
 // showPackageImports will usually show nothing
 func showPackageImports(pkg *ast.Package) {

+ 11 - 1
parse.go

@@ -3,6 +3,7 @@ package main
 import (
 	"fmt"
 	"go/ast"
+	"go/token"
 )
 
 func parseFile(f *ast.File) {
@@ -19,6 +20,15 @@ func parseFile(f *ast.File) {
 	}
 }
 
+// type specification: "type [=] <typ>"
 func parseTypeSpec(loc string, s *ast.TypeSpec) {
-	fmt.Printf("%s/typeSpec\n", loc)
+	// type foo bool: .Name + .Type / .Assign = NoPos (== 0)
+	// type foo = bool: .Name + .Type / .Assign = <pos>
+	name := s.Name.String()
+	if s.Assign == token.NoPos {
+		fmt.Printf("%s/Defined %s: ", loc, name)
+	} else {
+		fmt.Printf("%s/Aliased %s: ", loc, name)
+	}
+	parseTypeExpr(loc, s.Type, true)
 }

+ 2 - 1
stmt.go

@@ -11,7 +11,8 @@ func parseStmt(loc string, s ast.Stmt) {
 		parseCaseClause(loc, s)
 	case *ast.DeclStmt:
 		parseDeclStmt(loc, s)
-	case *ast.ExprStmt, *ast.AssignStmt, *ast.ReturnStmt:
+	case *ast.ExprStmt, *ast.AssignStmt, *ast.ReturnStmt,
+		*ast.BranchStmt: // break, continue, fallthrough, goto,
 		// fmt.Printf("%s/(%T)\n", loc, s)
 	case *ast.IfStmt:
 		parseIfStmt(loc, s)

PANIC: session(release): write data/sessions/8/d/8d45c4b033d3b59d: no space left on device

PANIC

session(release): write data/sessions/8/d/8d45c4b033d3b59d: no space left on device
/my/cache/.heroku/go/go-path/pkg/mod/github.com/go-macaron/session@v1.0.3/session.go:204 (0xb13e07)
/my/cache/.heroku/go/go-path/pkg/mod/gopkg.in/macaron.v1@v1.5.1/context.go:80 (0x967b75)
/my/cache/.heroku/go/go-path/pkg/mod/github.com/go-macaron/inject@v0.0.0-20200308113650-138e5925c53b/inject.go:157 (0x9512ee)
/my/cache/.heroku/go/go-path/pkg/mod/github.com/go-macaron/inject@v0.0.0-20200308113650-138e5925c53b/inject.go:135 (0x951205)
/my/cache/.heroku/go/go-path/pkg/mod/gopkg.in/macaron.v1@v1.5.1/context.go:124 (0x967cc4)
/my/cache/.heroku/go/go-path/pkg/mod/gopkg.in/macaron.v1@v1.5.1/context.go:114 (0x967bf6)
/my/cache/.heroku/go/go-path/pkg/mod/gopkg.in/macaron.v1@v1.5.1/recovery.go:161 (0x15baec4)
/my/cache/.heroku/go/go-path/pkg/mod/gopkg.in/macaron.v1@v1.5.1/logger.go:40 (0x96b257)
/my/cache/.heroku/go/go-path/pkg/mod/github.com/go-macaron/inject@v0.0.0-20200308113650-138e5925c53b/inject.go:157 (0x9512ee)
/my/cache/.heroku/go/go-path/pkg/mod/github.com/go-macaron/inject@v0.0.0-20200308113650-138e5925c53b/inject.go:135 (0x951205)
/my/cache/.heroku/go/go-path/pkg/mod/gopkg.in/macaron.v1@v1.5.1/context.go:124 (0x967cc4)
/my/cache/.heroku/go/go-path/pkg/mod/gopkg.in/macaron.v1@v1.5.1/router.go:187 (0x972959)
/my/cache/.heroku/go/go-path/pkg/mod/gopkg.in/macaron.v1@v1.5.1/router.go:304 (0x973a01)
/my/cache/.heroku/go/go-path/pkg/mod/gopkg.in/macaron.v1@v1.5.1/macaron.go:218 (0x96c572)
/my/cache/.heroku/go/go1.26.3/go/src/net/http/server.go:3311 (0x85a5cd)
/my/cache/.heroku/go/go1.26.3/go/src/net/http/server.go:2073 (0x837f6f)
/my/cache/.heroku/go/go1.26.3/go/src/runtime/asm_amd64.s:1771 (0x493380)