xml: aqwari.net/xml/internal/gen Index | Files

package gen

import "aqwari.net/xml/internal/gen"

Package gen provides functions for generating go source code

The gen package provides wrapper functions around the go/ast and go/token packages to reduce boilerplate.


Package Files


func CommentGroup Uses

func CommentGroup(comments ...string) *ast.CommentGroup

CommentGroup creates a comment group from strings.

func ConstChar Uses

func ConstChar(args ...string) *ast.GenDecl

ConstChar creates a series of character const declarations from the name/value pairs in args.

func ConstFloat Uses

func ConstFloat(args ...string) *ast.GenDecl

ConstFloat creates a series of floating-point const declarations from the name/value pairs in args.

func ConstImaginary Uses

func ConstImaginary(args ...string) *ast.GenDecl

ConstImaginary creates a series of imaginary const declarations from the name/value pairs in args.

func ConstInt Uses

func ConstInt(args ...string) *ast.GenDecl

ConstInt creates a series of numeric const declarations from the name/value pairs in args.

func ConstString Uses

func ConstString(args ...string) *ast.GenDecl

ConstString creates a series of string const declarations from the name/value pairs in args.

func Declarations Uses

func Declarations(blocks ...string) ([]ast.Decl, error)

Declarations parses a list of Go source code blocks and converts them into *ast.Decl values. If a parsing error occurs, it is returned immediately and no further parsing takes place.

func ExprString Uses

func ExprString(expr ast.Expr) string

ExprString converts an ast.Expr to the Go source it represents.

func FieldList Uses

func FieldList(fields ...string) (*ast.FieldList, error)

FieldList generates a field list from strings in the form "[name] expr".

func FormattedSource Uses

func FormattedSource(file *ast.File, output string) ([]byte, error)

FormattedSource converts an abstract syntax tree to formatted Go source code.

func PackageDoc Uses

func PackageDoc(file *ast.File, comments ...string) *ast.File

PackageDoc inserts package-level comments into a file, preceding the "package" statement.

func Public Uses

func Public(name string) *ast.Ident

Public turns a string into a public (uppercase) identifier.

func Sanitize Uses

func Sanitize(name string) string

Sanitize modifies any names that are reserved in Go, so that they may be used as identifiers without causing a syntax error.

func SimpleType Uses

func SimpleType(name string) ast.Expr

SimpleType creates an identifier suitable for use as a type expression.

func Snippets Uses

func Snippets(val interface{}, snippets ...string) ([]ast.Decl, error)

Snippets evaluates zero or more input templates with dot set to val and parses them as Go source code.

func String Uses

func String(s string) *ast.BasicLit

String generates a literal string. If the string contains a double quote, backticks are used for quoting instead.

func Struct Uses

func Struct(args ...ast.Expr) *ast.StructType

Struct creates a struct{} expression. The arguments are a series of name/type/tag tuples. Name must be of type *ast.Ident, type must be of type ast.Expr, and tag must be of type *ast.BasicLit, The number of arguments must be a multiple of 3, or a run-time panic will occur.

func TagKey Uses

func TagKey(field *ast.Field, key string) string

TagKey gets the struct tag item with the given key.

func ToString Uses

func ToString(expr ast.Expr) (string, error)

ToString converts the expression to a Go source string.

func TypeDecl Uses

func TypeDecl(name *ast.Ident, typ ast.Expr) *ast.GenDecl

TypeDecl generates a type declaration with the given name.

type Function Uses

type Function struct {
    // contains filtered or unexported fields

func Func Uses

func Func(name string) *Function

func (*Function) Args Uses

func (fn *Function) Args(args ...string) *Function

Args sets the arguments that a function takes.

func (*Function) Body Uses

func (fn *Function) Body(format string, v ...interface{}) *Function

Body sets the body of a function. The body should not include enclosing braces.

func (*Function) BodyTmpl Uses

func (fn *Function) BodyTmpl(tmpl string, dot interface{}) *Function

BodyTmpl allows use of the text/template package to construct the body of a function.

func (*Function) Comment Uses

func (fn *Function) Comment(s string) *Function

Comments sets the Godoc comments for the function.

func (*Function) Decl Uses

func (fn *Function) Decl() (*ast.FuncDecl, error)

Decl generates Go source for a Func. an error is returned if the body, or parameters cannot be parsed.

func (*Function) MustDecl Uses

func (fn *Function) MustDecl() *ast.FuncDecl

MustDecl is like Decl, but panics if an error is returned.

func (*Function) Name Uses

func (fn *Function) Name() string

Name returns the name of the function.

func (*Function) Receiver Uses

func (fn *Function) Receiver(receiver string) *Function

Receiver turns the function into a method operating on the specified type.

func (*Function) Returns Uses

func (fn *Function) Returns(values ...string) *Function

Returns sets the return values of a function. Each return value should be a string matching the Go syntax for a single return value.

Package gen imports 15 packages (graph) and is imported by 3 packages. Updated 2019-01-08. Refresh now. Tools for package owners.