Documentation ¶
Overview ¶
Package derive contains some utilities and helpers to build deriving macros.
Index ¶
- Variables
- func Callback(m Macro) macro.HandlerFunc
- type Array
- type ArrayDerive
- type Derive
- func (d *Derive) Derive(t *ast.TypeSpec, s builders.StatementBuilder) (builders.StatementBuilder, error)
- func (d *Derive) Dispatch(field Field, typ types.Type, s builders.StatementBuilder) (builders.StatementBuilder, error)
- func (d *Derive) IsCurrent(typ types.Type) bool
- func (d *Derive) IsDelayed(typ *types.TypeName) bool
- func (d *Derive) With(ctx macro.Context)
- type Field
- type Interpolator
- type Macro
- type Map
- type MapDerive
- type Pointer
- type PointerDerive
- type Protocol
- type Tag
Constants ¶
This section is empty.
Variables ¶
var ( // ErrCycleDetected reports that code cannot be derived due to infinite cycle. ErrCycleDetected = errors.New("cycle detected") // ErrInvalidType reports that type check failed. ErrInvalidType = errors.New("got invalid type") )
var ErrExpected = errors.New("expected expression")
ErrExpected reports that expression has invalid type or kind.
Functions ¶
func Callback ¶
func Callback(m Macro) macro.HandlerFunc
Callback creates new macro handler from derive macro.
Types ¶
type ArrayDerive ¶
ArrayDerive defines code generation for arrays and slices.
type Derive ¶
type Derive struct { macro.Context Macro Interpolator Interpolator // contains filtered or unexported fields }
Derive is a deriving state.
func (*Derive) Derive ¶
func (d *Derive) Derive(t *ast.TypeSpec, s builders.StatementBuilder) (builders.StatementBuilder, error)
Derive derives code for given type declaration.
func (*Derive) Dispatch ¶
func (d *Derive) Dispatch(field Field, typ types.Type, s builders.StatementBuilder) (builders.StatementBuilder, error)
Dispatch derives code for given field.
func (*Derive) IsCurrent ¶
IsCurrent checks that given type is current deriving type. Useful for resolving cycles.
type Interpolator ¶
type Interpolator struct {
// contains filtered or unexported fields
}
Interpolator interpolates and evaluates struct tags.
func NewInterpolator ¶
func NewInterpolator(derive *Derive, values map[string]string) Interpolator
NewInterpolator creates new Interpolator.
func (Interpolator) Expr ¶
func (i Interpolator) Expr(s string) (ast.Expr, error)
Expr interpolates given string and tries to parse it.
func (Interpolator) ExprExpectInfo ¶
ExprExpectInfo interpolates given string, tries to parse it and checks basic type into.
func (Interpolator) ExprExpectKind ¶
ExprExpectKind interpolates given string, tries to parse it and checks basic type kind.
func (Interpolator) Interpolate ¶
func (i Interpolator) Interpolate(s string) string
Interpolate interpolates given string.
type PointerDerive ¶
PointerDerive defines code generation for pointers.