當前位置: 首頁>>代碼示例>>Golang>>正文


Golang parser.New函數代碼示例

本文整理匯總了Golang中k8s/io/kubernetes/cmd/libs/go2idl/parser.New函數的典型用法代碼示例。如果您正苦於以下問題:Golang New函數的具體用法?Golang New怎麽用?Golang New使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了New函數的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: NewBuilder

// NewBuilder makes a new parser.Builder and populates it with the input
// directories.
func (g *GeneratorArgs) NewBuilder() (*parser.Builder, error) {
	b := parser.New()
	for _, d := range g.InputDirs {
		if err := b.AddDir(d); err != nil {
			return nil, fmt.Errorf("unable to add directory %q: %v", d, err)
		}
	}
	return b, nil
}
開發者ID:fwalker,項目名稱:dashboard,代碼行數:11,代碼來源:args.go

示例2: construct

func construct(t *testing.T, files map[string]string, testNamer namer.Namer) (*parser.Builder, types.Universe, []*types.Type) {
	b := parser.New()
	for name, src := range files {
		if err := b.AddFile(name, []byte(src)); err != nil {
			t.Fatal(err)
		}
	}
	u, err := b.FindTypes()
	if err != nil {
		t.Fatal(err)
	}
	orderer := namer.Orderer{testNamer}
	o := orderer.Order(u)
	return b, u, o
}
開發者ID:robertabbott,項目名稱:kubernetes,代碼行數:15,代碼來源:parse_test.go

示例3: construct

func construct(t *testing.T, files map[string]string) *generator.Context {
	b := parser.New()
	for name, src := range files {
		if err := b.AddFile(name, []byte(src)); err != nil {
			t.Fatal(err)
		}
	}
	c, err := generator.NewContext(b, namer.NameSystems{
		"public":  namer.NewPublicNamer(0),
		"private": namer.NewPrivateNamer(0),
	}, "public")
	if err != nil {
		t.Fatal(err)
	}
	return c
}
開發者ID:thed00de,項目名稱:hypernetes,代碼行數:16,代碼來源:snippet_writer_test.go

示例4: NewBuilder

// NewBuilder makes a new parser.Builder and populates it with the input
// directories.
func (g *GeneratorArgs) NewBuilder() (*parser.Builder, error) {
	b := parser.New()
	// Ignore all auto-generated files.
	b.AddBuildTags(g.GeneratedBuildTag)

	for _, d := range g.InputDirs {
		var err error
		if strings.HasSuffix(d, "/...") {
			err = b.AddDirRecursive(strings.TrimSuffix(d, "/..."))
		} else {
			err = b.AddDir(d)
		}
		if err != nil {
			return nil, fmt.Errorf("unable to add directory %q: %v", d, err)
		}
	}
	return b, nil
}
開發者ID:RyanBinfeng,項目名稱:kubernetes,代碼行數:20,代碼來源:args.go

示例5: NewBuilder

// NewBuilder makes a new parser.Builder and populates it with the input
// directories.
func (g *GeneratorArgs) NewBuilder() (*parser.Builder, error) {
	b := parser.New()
	// Ignore all auto-generated files.
	b.AddBuildTags("ignore_autogenerated")

	for _, d := range g.InputDirs {
		if g.Recursive {
			if err := b.AddDirRecursive(d); err != nil {
				return nil, fmt.Errorf("unable to add directory %q: %v", d, err)
			}
		} else {
			if err := b.AddDir(d); err != nil {
				return nil, fmt.Errorf("unable to add directory %q: %v", d, err)
			}
		}
	}
	return b, nil
}
開發者ID:Clarifai,項目名稱:kubernetes,代碼行數:20,代碼來源:args.go

示例6: construct

func construct(t *testing.T, files map[string]string) *generator.Context {
	b := parser.New()
	dir, err := ioutil.TempDir("", "snippet_writer_test")
	if err != nil {
		t.Fatal(err)
	}
	for name, src := range files {
		if err := b.AddFile(filepath.Join(dir, name), name, []byte(src)); err != nil {
			t.Fatal(err)
		}
	}
	c, err := generator.NewContext(b, namer.NameSystems{
		"public":  namer.NewPublicNamer(0),
		"private": namer.NewPrivateNamer(0),
	}, "public")
	if err != nil {
		t.Fatal(err)
	}
	return c
}
開發者ID:juanluisvaladas,項目名稱:origin,代碼行數:20,代碼來源:snippet_writer_test.go

示例7: getPrioritySignatures

func getPrioritySignatures() ([]*types.Signature, error) {
	filePath := "./../types.go"
	pkgName := filepath.Dir(filePath)
	builder := parser.New()
	if err := builder.AddDir(pkgName); err != nil {
		return nil, err
	}
	universe, err := builder.FindTypes()
	if err != nil {
		return nil, err
	}
	signatures := []string{"PriorityFunction", "PriorityMapFunction", "PriorityReduceFunction"}
	results := make([]*types.Signature, 0, len(signatures))
	for _, signature := range signatures {
		result, ok := universe[pkgName].Types[signature]
		if !ok {
			return nil, fmt.Errorf("%s type not defined", signature)
		}
		results = append(results, result.Signature)
	}
	return results, nil
}
開發者ID:huang195,項目名稱:kubernetes,代碼行數:22,代碼來源:priorities_test.go

示例8: GetPublicFunctions

// GetPublicFunctions lists all public functions (not methods) from a golang source file.
func GetPublicFunctions(pkg, filePath string) ([]*types.Type, error) {
	builder := go2idlparser.New()
	data, err := ioutil.ReadFile(filePath)
	if err != nil {
		return nil, err
	}
	if err := builder.AddFile(pkg, filePath, data); err != nil {
		return nil, err
	}
	universe, err := builder.FindTypes()
	if err != nil {
		return nil, err
	}

	var functions []*types.Type

	// Create the AST by parsing src.
	fset := token.NewFileSet() // positions are relative to fset
	f, err := parser.ParseFile(fset, filePath, nil, 0)
	if err != nil {
		return nil, fmt.Errorf("failed parse file to list functions: %v", err)
	}

	// Inspect the AST and print all identifiers and literals.
	ast.Inspect(f, func(n ast.Node) bool {
		var s string
		switch x := n.(type) {
		case *ast.FuncDecl:
			s = x.Name.Name
			// It's a function (not method), and is public, record it.
			if x.Recv == nil && isPublic(s) {
				functions = append(functions, universe[pkg].Function(x.Name.Name))
			}
		}
		return true
	})

	return functions, nil
}
開發者ID:CodeJuan,項目名稱:kubernetes,代碼行數:40,代碼來源:codeinspector.go

示例9: Run

func Run(g *Generator) {
	if g.Common.VerifyOnly {
		g.OnlyIDL = true
		g.Clean = false
	}

	b := parser.New()
	b.AddBuildTags("proto")

	omitTypes := map[types.Name]struct{}{}
	for _, t := range strings.Split(g.DropEmbeddedFields, ",") {
		name := types.Name{}
		if i := strings.LastIndex(t, "."); i != -1 {
			name.Package, name.Name = t[:i], t[i+1:]
		} else {
			name.Name = t
		}
		if len(name.Name) == 0 {
			log.Fatalf("--drop-embedded-types requires names in the form of [GOPACKAGE.]TYPENAME: %v", t)
		}
		omitTypes[name] = struct{}{}
	}

	boilerplate, err := g.Common.LoadGoBoilerplate()
	if err != nil {
		log.Fatalf("Failed loading boilerplate: %v", err)
	}

	protobufNames := NewProtobufNamer()
	outputPackages := generator.Packages{}
	for _, d := range strings.Split(g.Packages, ",") {
		generateAllTypes, outputPackage := true, true
		switch {
		case strings.HasPrefix(d, "+"):
			d = d[1:]
			generateAllTypes = false
		case strings.HasPrefix(d, "-"):
			d = d[1:]
			outputPackage = false
		}
		name := protoSafePackage(d)
		parts := strings.SplitN(d, "=", 2)
		if len(parts) > 1 {
			d = parts[0]
			name = parts[1]
		}
		p := newProtobufPackage(d, name, generateAllTypes, omitTypes)
		header := append([]byte{}, boilerplate...)
		header = append(header, p.HeaderText...)
		p.HeaderText = header
		protobufNames.Add(p)
		if outputPackage {
			outputPackages = append(outputPackages, p)
		}
	}

	if !g.Common.VerifyOnly {
		for _, p := range outputPackages {
			if err := p.(*protobufPackage).Clean(g.OutputBase); err != nil {
				log.Fatalf("Unable to clean package %s: %v", p.Name(), err)
			}
		}
	}

	if g.Clean {
		return
	}

	for _, p := range protobufNames.List() {
		if err := b.AddDir(p.Path()); err != nil {
			log.Fatalf("Unable to add directory %q: %v", p.Path(), err)
		}
	}

	c, err := generator.NewContext(
		b,
		namer.NameSystems{
			"public": namer.NewPublicNamer(3),
			"proto":  protobufNames,
		},
		"public",
	)
	c.Verify = g.Common.VerifyOnly
	c.FileTypes["protoidl"] = NewProtoFile()

	if err != nil {
		log.Fatalf("Failed making a context: %v", err)
	}

	if err := protobufNames.AssignTypesToPackages(c); err != nil {
		log.Fatalf("Failed to identify Common types: %v", err)
	}

	if err := c.ExecutePackages(g.OutputBase, outputPackages); err != nil {
		log.Fatalf("Failed executing generator: %v", err)
	}

	if g.OnlyIDL {
		return
	}
//.........這裏部分代碼省略.........
開發者ID:Clarifai,項目名稱:kubernetes,代碼行數:101,代碼來源:cmd.go


注:本文中的k8s/io/kubernetes/cmd/libs/go2idl/parser.New函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。