func args(filename string) { b, err := ioutil.ReadFile(filename) if err != nil { panic(err) } p := parser.ParseFromString(filename, string(b)+"\n") a := generator.GenerateAST(p) fset := token.NewFileSet() defaultImports := []string{"github.com/gsp-lang/stdlib/prelude", "github.com/gsp-lang/gsp/core"} for _, defaultImport := range defaultImports { split := strings.Split(defaultImport, "/") pkgName := split[len(split)-1] if !(a.Name.Name == "prelude" && pkgName == "prelude") { astutil.AddImport(fset, a, defaultImport) } } if a.Name.Name != "prelude" { a.Decls = append(a.Decls, &ast.GenDecl{ Tok: token.VAR, Specs: []ast.Spec{&ast.ValueSpec{ Names: []*ast.Ident{&ast.Ident{Name: "_"}}, Values: []ast.Expr{&ast.Ident{Name: "prelude.Len"}}, }}, }) } var buf bytes.Buffer printer.Fprint(&buf, fset, a) fmt.Printf("%s\n", buf.String()) }
func args(filename string) { b, err := ioutil.ReadFile(filename) if err != nil { panic(err) } p := parser.ParseFromString(filename, string(b)+"\n") a := generator.GenerateAST(p) fset := token.NewFileSet() defaultImports := []string{"github.com/gsp-lang/stdlib/prelude", "github.com/gsp-lang/gsp/core"} for _, defaultImport := range defaultImports { split := strings.Split(defaultImport, "/") pkgName := split[len(split)-1] if !(a.Name.Name == "prelude" && pkgName == "prelude") { if pkgName == "prelude" { astutil.AddNamedImport(fset, a, "_", defaultImport) } else { astutil.AddImport(fset, a, defaultImport) } } } var buf bytes.Buffer printer.Fprint(&buf, fset, a) fmt.Printf("%s\n", buf.String()) }