lpcode

package module
v0.0.0-...-aaf56ab Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2023 License: AGPL-3.0 Imports: 4 Imported by: 0

README

lpcode

Go package to generate Go code

Documentation

Overview

Copyright (c) 2023 thorstenrie. All Rights Reserved. Use is governed with GNU Affero General Public License v3.0 that can be found in the LICENSE file.

Does not check for correct syntax or arguments

Copyright (c) 2023 thorstenrie. All Rights Reserved. Use is governed with GNU Affero General Public License v3.0 that can be found in the LICENSE file.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AssignmentArgs

type AssignmentArgs struct {
	ExprLeft, ExprRight string
}

type Code

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

Code contains the source code as string. The source code is amended by its methods. The source code can be retrieved with String and formatted with Format.

func NewCode

func NewCode() *Code

NewCode returns a pointer to a new Code instance. The source code in the new Code instance is empty.

func (*Code) Addr

func (code *Code) Addr() *Code

Address operator

func (*Code) Assignment

func (code *Code) Assignment(a *AssignmentArgs) *Code

Assignment

func (*Code) BlockEnd

func (code *Code) BlockEnd() *Code

BlockEnd adds a block ending to code: }\n.

func (*Code) Call

func (code *Code) Call(n string) *Code

Call adds a function call to code: n(. The function name is provided by n.

func (*Code) CompositeLit

func (code *Code) CompositeLit(LiteralType string) *Code

Composite Literal

func (*Code) Format

func (code *Code) Format() error

Format formats the source code in code in canonical gfmt style. It uses Source from the go/format package. Format returns an error if code is nil or if go/format returns an error.

func (*Code) Func1

func (code *Code) Func1(a *Func1Args) *Code

func (*Code) FuncEnd

func (code *Code) FuncEnd() *Code

FuncEnd adds a block end and two new lines to code: }\n\n.

func (*Code) Ident

func (code *Code) Ident(n string) *Code

Ident adds an identifier to code: n. The identifier is provided by argument n.

func (*Code) If

func (code *Code) If(a *IfArgs) *Code

If statement

func (*Code) IfErr

func (code *Code) IfErr(a *IfErrArgs) *Code

If statement for error handling using a simple statement

func (*Code) KeyedElement

func (code *Code) KeyedElement(a *KeyedElementArgs) *Code

KeyedElement generates a keyed element of a composite literal: Key: Element,\n. The key and element is provided by a. It returns nil if a is nil.

func (*Code) LineComment

func (code *Code) LineComment(c string) *Code

LineComment adds a line comment and a new line to code: // c\n. The comment is provided by argument c.

func (*Code) List

func (code *Code) List() *Code

List adds an identifier list to code: , .

func (*Code) Listln

func (code *Code) Listln() *Code

Listln adds an identifier list and a new line to code: ,\n.

func (*Code) ParamEnd

func (code *Code) ParamEnd() *Code

ParamEnd adds a parameters ending to code: ).

func (*Code) ParamEndln

func (code *Code) ParamEndln() *Code

ParamEndln adds a parameters ending and a new line to code: )\n.

func (*Code) Return

func (code *Code) Return() *Code

Return

func (*Code) SelField

func (code *Code) SelField(a *SelArgs) *Code

SelField adds a field selector to code: val.sel. The value val and selector sel are provided by a. It returns nil if a is nil.

func (*Code) SelMethod

func (code *Code) SelMethod(a *SelArgs) *Code

SelMethod adds a method selector to code: val.sel(. The value val and selector sel are provided by a. It returns nil if a is nil.

func (*Code) ShortVarDecl

func (code *Code) ShortVarDecl(a *ShortVarDeclArgs) *Code

ShortVarDecl generates a short variable declaration: Ident := Expr\n. The identifier and expression is provided by a. It returns nil if a is nil.

func (*Code) String

func (code *Code) String() string

String returns the source code in code as string. It returns an empty string if code is nil.

func (*Code) Testvariables

func (code *Code) Testvariables(t *Testvars) *Code

Testvariables generates test variables for unit tests. The test variables are generated based on t. A test variable is generated if the corresponding type in t is not equal to zero. It returns nil if t is nil.

func (*Code) TypeStruct

func (code *Code) TypeStruct(n string) *Code

TypeStruct adds a type declaration for a struct type to code: type n struct {\n. The name of the type is provided with n.

func (*Code) VarSpec

func (code *Code) VarSpec(a *VarSpecArgs) *Code

VarSpec adds a variable specification to code: Ident Type\n. The identifier and type is provided by a.

type Codefile

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

func NewCodefile

func NewCodefile(dn tsfio.Directory, fn tsfio.Filename) (*Codefile, error)

func (*Codefile) Filepath

func (cf *Codefile) Filepath() tsfio.Filename

func (*Codefile) FinishFile

func (cf *Codefile) FinishFile() error

func (*Codefile) Format

func (cf *Codefile) Format() error

func (*Codefile) StartFile

func (cf *Codefile) StartFile() error

func (*Codefile) WriteCode

func (cf *Codefile) WriteCode(c string) error

type Func1Args

type Func1Args struct {
	Name, Var, Type, Return string
}

type IfArgs

type IfArgs struct {
	ExprLeft, ExprRight, Operator string
}

Expression

type IfErrArgs

type IfErrArgs struct {
	Method, Operator string
}

type KeyedElementArgs

type KeyedElementArgs struct {
	Key, Elem string
}

KeyedElementArgs contains the key Key and element Elem to generate a keyed element of a composite literal with KeyedElement

type SelArgs

type SelArgs struct {
	Val, Sel string
}

type ShortVarDeclArgs

type ShortVarDeclArgs struct {
	Ident, Expr string
}

ShortVarDeclArgs contains the identifier Ident and expression Expr to generate a short variable declaration with ShortVarDecl

type Testvars

type Testvars struct {
	String, Error, Int, Float int
}

Testvars contains the configuration for the generation of test variables with Testvariables A test variable is generated if the corresponding type is not equal to zero.

type VarSpecArgs

type VarSpecArgs struct {
	Ident, Type string
}

VarSpecArgs contains the identifier Ident and type Type to generate a variable specification with VarSpec

Jump to

Keyboard shortcuts

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