generator

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 24, 2023 License: Apache-2.0 Imports: 12 Imported by: 2

Documentation

Overview

Package generator contains code generator for YAML marshalling and unmarshalling methods.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EngineGenerator

type EngineGenerator interface {
	// Packages returns information for packages used by engine as map
	// using package path as key and alias as value
	Packages() map[string]string

	// WarningSuppressors returns a list of types used to create stub variables
	// to suppress warnings
	WarningSuppressors() []string

	// GenerateUnmarshalers generates unmarshalling methods for target type
	// using provided decodeFuncName and typeName. The generated code is written into dst.
	// Decode function has following signature:
	//
	// func(yamly.Decoder, *typeName)
	GenerateUnmarshalers(dst io.Writer, decodeFuncName, typeName string) error

	// GenerateMarshalers generates marshalling methods for target type
	// using provided encodeFuncName and typeName. The generated code is written into dst.
	// Encode function has following signature:
	//
	// func(yamly.Encoder, typeName)
	GenerateMarshalers(dst io.Writer, encodeFuncName, typeName string) error

	// UnmarshalersImplementationCheck checks if provided type t implements any of engine-specific
	// unmarshalling interfaces.
	// If it does, UnmarshalersImplementationCheck generates code using implemented method, writing it into dst.
	UnmarshalersImplementationCheck(dst io.Writer, t reflect.Type, outArg string, indent int) (ImplementationResult, error)

	// MarshalersImplementationCheck checks if provided type t implements any of engine-specific
	// marshalling interfaces.
	// If it does, MarshalersImplementationCheck generates code using implemented method, writing it into dst.
	MarshalersImplementationCheck(dst io.Writer, t reflect.Type, inArg string, indent int) (ImplementationResult, error)

	// GenerateUnmarshalEmptyInterfaceAssertions generates code with type assertions for empty interface
	// (interface{} or any) using unmarshalling interfaces.
	GenerateUnmarshalEmptyInterfaceAssertions(dst io.Writer, outArg string, indent int) error

	// GenerateMarshalEmptyInterfaceAssertions generates code with type assertions for empty interface
	// (interface{} or any) using marshalling interfaces.
	GenerateMarshalEmptyInterfaceAssertions(dst io.Writer, inArg string, indent int) error
}

EngineGenerator interface contains engine-specific methods

type Generator

type Generator struct {
	// contains filtered or unexported fields
}

Generator is used to generate code for YAML (un)marshalling methods in runtime.

func New

func New(outputFile string) *Generator

New creates a Generator which will write generated code into outputFile.

func (*Generator) AddType

func (g *Generator) AddType(v any)

AddType sets a target type for which methods are generated.

func (*Generator) Generate

func (g *Generator) Generate(w io.Writer) error

Generate generates code for marshalling methods, writing it into given io.Writer.

func (*Generator) SetBuildTags

func (g *Generator) SetBuildTags(buildTags string)

func (*Generator) SetDisallowUnknownFields

func (g *Generator) SetDisallowUnknownFields(disallow bool)

func (*Generator) SetEncodePointerReceiver

func (g *Generator) SetEncodePointerReceiver(useReceiver bool)

func (*Generator) SetEngineGenerator

func (g *Generator) SetEngineGenerator(eg EngineGenerator)

SetEngineGenerator defines engine for Generator. Engine represents a "backend" for generator, including lexer, parser etc.

func (*Generator) SetInlineEmbedded

func (g *Generator) SetInlineEmbedded(inlineEmbedded bool)

func (*Generator) SetOmitempty

func (g *Generator) SetOmitempty(omitempty bool)

func (*Generator) SetPkgName

func (g *Generator) SetPkgName(pkgName string)

func (*Generator) SetPkgPath

func (g *Generator) SetPkgPath(pkgPath string)

type ImplementationResult

type ImplementationResult int8

ImplementationResult defines whether type implements any engine interface or not

const (
	// ImplementationResultFalse is equal to boolean false, meaning type does not implement any interface
	ImplementationResultFalse ImplementationResult = iota
	// ImplementationResultTrue is equal to boolean true, meaning type does implement any of engine interfaces
	ImplementationResultTrue
	// ImplementationResultConditional indicates that type can implement one of engine interfaces,
	// but this depends not only on the type, but additional conditions (like if yamly.Decoder implements more
	// specific yamly.ExtendedDecoder).
	ImplementationResultConditional
)

Directories

Path Synopsis
Package bootstrap contains generator for bootstrap main with actual generating with generator.Generator
Package bootstrap contains generator for bootstrap main with actual generating with generator.Generator
Package parser contains parser for package name and path.
Package parser contains parser for package name and path.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL