gogen

package
v0.0.0-...-65f6afe Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2019 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package gogen contains a few functions for ad-hoc generation of Go source snippets.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AField

func AField(name string, typeExpr ast.Expr) *ast.Field

func AppendDecl

func AppendDecl(f *ast.File, decl ast.Decl)

func Assign

func Assign(lhs, rhs ast.Expr, tok ...token.Token) *ast.AssignStmt

func AssignMulti

func AssignMulti(lhs, rhs []ast.Expr, tok ...token.Token) *ast.AssignStmt

func Binary

func Binary(x ast.Expr, op token.Token, y ast.Expr) *ast.BinaryExpr

func Block

func Block(statements ...ast.Stmt) *ast.BlockStmt

func Call

func Call(fun ast.Expr, args ...ast.Expr) *ast.CallExpr

func CaptureHandler

func CaptureHandler(name, subhandler string) *ast.FuncDecl

func Case

func Case(expr []ast.Expr, stmt ...ast.Stmt) *ast.CaseClause

func Char

func Char(val string) *ast.BasicLit

func CharClassHandler

func CharClassHandler(name string, cc *charclass.CharClass) *ast.FuncDecl

CharClassHandler generates Go AST for the character class handler. Note: it panics on invalid arg string, because checking validity is a responsibility of the PEG parser.

func ChoiceHandler

func ChoiceHandler(name, subhandler string, subhandlers ...string) *ast.FuncDecl

func Composite

func Composite(ty ast.Expr, elts []ast.Expr) *ast.CompositeLit

func Const

func Const(name string, ty, val ast.Expr) *ast.GenDecl

func DeclStmt

func DeclStmt(decl ast.Decl) *ast.DeclStmt

func DotHandler

func DotHandler(name string) *ast.FuncDecl

func E

func E(elts ...ast.Expr) []ast.Expr

func Else

func Else(ifstmt *ast.IfStmt, els ast.Stmt) *ast.IfStmt

Else modifies ast.Ifstmt in-place to add an else clause.

func Expr

func Expr(expr string) ast.Expr

Expr returns the ast.Expr parsed from a string. It panics if the string cannot be parsed as Go expression.

func ExprStmt

func ExprStmt(x ast.Expr) *ast.ExprStmt

func Field

func Field(names []*ast.Ident, typeExpr ast.Expr) *ast.Field

func Fields

func Fields(args ...*ast.Field) []*ast.Field

func For

func For(init ast.Stmt, cond ast.Expr, post ast.Stmt, statements ...ast.Stmt) *ast.ForStmt

func Func

func Func(name string, funcType *ast.FuncType, stmt ...ast.Stmt) *ast.FuncDecl

func FuncType

func FuncType(args, returns []*ast.Field) *ast.FuncType

func GroupHandler

func GroupHandler(name string, subhandlers []string) *ast.FuncDecl

func Ident

func Ident(name string) *ast.Ident

func If

func If(init ast.Stmt, cond ast.Expr, statements ...ast.Stmt) *ast.IfStmt

func Index

func Index(x, index ast.Expr) *ast.IndexExpr

func Int

func Int(val string) *ast.BasicLit

func KeyValue

func KeyValue(key, value ast.Expr) *ast.KeyValueExpr

func LiteralHandler

func LiteralHandler(name, literal string) *ast.FuncDecl

LiteralHandler generates Go AST for the literal handler.

func MapType

func MapType(key, value ast.Expr) *ast.MapType

func Package

func Package(name string, imports []string, decls ...ast.Decl) *ast.File

func ParseStmt

func ParseStmt(stmt string) (ast.Stmt, error)

func ParseStmts

func ParseStmts(stmts string) ([]ast.Stmt, error)

func PlusHandler

func PlusHandler(name, subhandler string) *ast.FuncDecl

func PredicateHandler

func PredicateHandler(name, subhandler string, negative bool) *ast.FuncDecl

func QuestionHandler

func QuestionHandler(name, subhandler string) *ast.FuncDecl

func Range

func Range(key, value, x ast.Expr, stmt ...ast.Stmt) *ast.RangeStmt

func Render

func Render(node interface{}) (string, error)

func Return

func Return(vals ...ast.Expr) *ast.ReturnStmt

func S

func S(elts ...ast.Stmt) []ast.Stmt

func Sel

func Sel(x ast.Expr, sel string) *ast.SelectorExpr

func SelIdent

func SelIdent(name string) ast.Expr

func Slice

func Slice(x, low, high ast.Expr, other ...ast.Expr) *ast.SliceExpr

func SliceType

func SliceType(x ast.Expr) *ast.ArrayType

func Star

func Star(x ast.Expr) *ast.StarExpr

func StarHandler

func StarHandler(name, subhandler string) *ast.FuncDecl

func Stmt

func Stmt(stmt string) ast.Stmt

Stmt returns the ast.Stmt parsed from a string. It panics if the string cannot be parsed as Go statement.

func Stmts

func Stmts(stmts string) []ast.Stmt

func String

func String(val string) *ast.BasicLit

func Struct

func Struct(fields ...*ast.Field) ast.Expr

func StructLiteral

func StructLiteral(name string, elts ...ast.Expr) ast.Expr

func Switch

func Switch(init ast.Stmt, tag ast.Expr, cases ...ast.Stmt) *ast.SwitchStmt

cases should include *ast.CaseClause only.

func Type

func Type(name string, ty ast.Expr) *ast.GenDecl

func Unary

func Unary(op token.Token, x ast.Expr) *ast.UnaryExpr

func Var

func Var(name string, ty, val ast.Expr) *ast.GenDecl

Types

This section is empty.

Jump to

Keyboard shortcuts

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