codegen

package
v0.0.0-...-c19637d Latest Latest
Warning

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

Go to latest
Published: May 24, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AssignStatement

type AssignStatement struct {
	Vars   []string
	Values StatementList
}

func (AssignStatement) CodeLines

func (stmt AssignStatement) CodeLines() []string

type Builder

type Builder struct {
	// Program defines generator program name in the generated file.
	Program string

	// PackageName defines the package name of the generated file.
	PackageName string

	// Imports defines necessary imports to reduce ambiguity when generating
	// formatting the raw-generated code.
	Imports [][]code.Import
	// contains filtered or unexported fields
}

func NewBuilder

func NewBuilder(program string, packageName string, imports [][]code.Import) *Builder

NewBuilder is a constructor of Builder struct.

func (*Builder) AddImplementer

func (b *Builder) AddImplementer(implementer Implementer)

AddImplementer appends a new implemeneter to the implementer list.

func (Builder) Build

func (b Builder) Build() (string, error)

Build generates code from the previously provided specifications.

type CallStatement

type CallStatement struct {
	FuncName string
	Params   StatementList
}

func (CallStatement) CodeLines

func (stmt CallStatement) CodeLines() []string

type ChainBuilder

type ChainBuilder []Statement

func NewChainBuilder

func NewChainBuilder(object string) ChainBuilder

func (ChainBuilder) Build

func (b ChainBuilder) Build() ChainStatement

func (ChainBuilder) Call

func (b ChainBuilder) Call(method string, params ...Statement) ChainBuilder

func (ChainBuilder) Chain

func (b ChainBuilder) Chain(field string) ChainBuilder

type ChainStatement

type ChainStatement []Statement

func (ChainStatement) CodeLines

func (stmt ChainStatement) CodeLines() []string

type DeclAssignStatement

type DeclAssignStatement struct {
	Vars   []string
	Values StatementList
}

func (DeclAssignStatement) CodeLines

func (stmt DeclAssignStatement) CodeLines() []string

type DeclStatement

type DeclStatement struct {
	Name string
	Type code.Type
}

func (DeclStatement) CodeLines

func (stmt DeclStatement) CodeLines() []string

type FunctionBody

type FunctionBody []Statement

func (FunctionBody) Code

func (b FunctionBody) Code() string

type FunctionBuilder

type FunctionBuilder struct {
	Name    string
	Params  []code.Param
	Returns []code.Type
	Body    FunctionBody
}

FunctionBuilder is an implementer of a function.

func (FunctionBuilder) GenParams

func (fb FunctionBuilder) GenParams() string

func (FunctionBuilder) GenReturns

func (fb FunctionBuilder) GenReturns() string

func (FunctionBuilder) Impl

func (fb FunctionBuilder) Impl(buffer *bytes.Buffer) error

Impl writes function declatation code to the buffer.

type Identifier

type Identifier string

func (Identifier) CodeLines

func (id Identifier) CodeLines() []string

type IfBlock

type IfBlock struct {
	Condition  []Statement
	Statements []Statement
}

func (IfBlock) CodeLines

func (b IfBlock) CodeLines() []string

type Implementer

type Implementer interface {
	Impl(buffer *bytes.Buffer) error
}

Implementer is an interface that wraps the basic Impl method for code generation.

type MapPair

type MapPair struct {
	Key   string
	Value Statement
}

func (MapPair) ItemCodeLines

func (p MapPair) ItemCodeLines() []string

type MapStatement

type MapStatement struct {
	Type  string
	Pairs []MapPair
}

func (MapStatement) CodeLines

func (stmt MapStatement) CodeLines() []string

type MethodBuilder

type MethodBuilder struct {
	Receiver MethodReceiver
	Name     string
	Params   []code.Param
	Returns  []code.Type
	Body     FunctionBody
}

MethodBuilder is an implementer of a method.

func (MethodBuilder) GenParams

func (mb MethodBuilder) GenParams() string

func (MethodBuilder) GenReceiver

func (mb MethodBuilder) GenReceiver() string

func (MethodBuilder) GenReturns

func (mb MethodBuilder) GenReturns() string

func (MethodBuilder) Impl

func (mb MethodBuilder) Impl(buffer *bytes.Buffer) error

Impl writes method declatation code to the buffer.

type MethodReceiver

type MethodReceiver struct {
	Name    string
	Type    code.SimpleType
	Pointer bool
}

MethodReceiver describes a specification of a method receiver.

type RawBlock

type RawBlock struct {
	Header     []string
	Statements []Statement
}

func (RawBlock) CodeLines

func (b RawBlock) CodeLines() []string

type RawStatement

type RawStatement string

func (RawStatement) CodeLines

func (stmt RawStatement) CodeLines() []string

type ReturnStatement

type ReturnStatement StatementList

func (ReturnStatement) CodeLines

func (stmt ReturnStatement) CodeLines() []string

type SliceStatement

type SliceStatement struct {
	Type   code.Type
	Values []Statement
}

func (SliceStatement) CodeLines

func (stmt SliceStatement) CodeLines() []string

type Statement

type Statement interface {
	CodeLines() []string
}

type StatementList

type StatementList []Statement

func (StatementList) CodeLines

func (l StatementList) CodeLines() []string

type StructBuilder

type StructBuilder struct {
	Name   string
	Fields code.StructFields
}

StructBuilder is an implementer of a struct.

func (StructBuilder) GenFields

func (sb StructBuilder) GenFields() string

func (StructBuilder) Impl

func (sb StructBuilder) Impl(buffer *bytes.Buffer) error

Impl writes struct declatation code to the buffer.

type StructFieldPair

type StructFieldPair struct {
	Key   string
	Value Statement
}

func (StructFieldPair) ItemCodeLines

func (p StructFieldPair) ItemCodeLines() []string

type StructStatement

type StructStatement struct {
	Type  string
	Pairs []StructFieldPair
}

func (StructStatement) CodeLines

func (stmt StructStatement) CodeLines() []string

Jump to

Keyboard shortcuts

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