Documentation
¶
Overview ¶
Package gogen contains a few functions for ad-hoc generation of Go source snippets.
Index ¶
- func AField(name string, typeExpr ast.Expr) *ast.Field
- func AppendDecl(f *ast.File, decl ast.Decl)
- func Assign(lhs, rhs ast.Expr, tok ...token.Token) *ast.AssignStmt
- func AssignMulti(lhs, rhs []ast.Expr, tok ...token.Token) *ast.AssignStmt
- func Binary(x ast.Expr, op token.Token, y ast.Expr) *ast.BinaryExpr
- func Block(statements ...ast.Stmt) *ast.BlockStmt
- func Call(fun ast.Expr, args ...ast.Expr) *ast.CallExpr
- func CaptureHandler(name, subhandler string) *ast.FuncDecl
- func Case(expr []ast.Expr, stmt ...ast.Stmt) *ast.CaseClause
- func Char(val string) *ast.BasicLit
- func CharClassHandler(name string, cc *charclass.CharClass) *ast.FuncDecl
- func ChoiceHandler(name, subhandler string, subhandlers ...string) *ast.FuncDecl
- func Composite(ty ast.Expr, elts []ast.Expr) *ast.CompositeLit
- func Const(name string, ty, val ast.Expr) *ast.GenDecl
- func DeclStmt(decl ast.Decl) *ast.DeclStmt
- func DotHandler(name string) *ast.FuncDecl
- func E(elts ...ast.Expr) []ast.Expr
- func Else(ifstmt *ast.IfStmt, els ast.Stmt) *ast.IfStmt
- func Expr(expr string) ast.Expr
- func ExprStmt(x ast.Expr) *ast.ExprStmt
- func Field(names []*ast.Ident, typeExpr ast.Expr) *ast.Field
- func Fields(args ...*ast.Field) []*ast.Field
- func For(init ast.Stmt, cond ast.Expr, post ast.Stmt, statements ...ast.Stmt) *ast.ForStmt
- func Func(name string, funcType *ast.FuncType, stmt ...ast.Stmt) *ast.FuncDecl
- func FuncType(args, returns []*ast.Field) *ast.FuncType
- func GroupHandler(name string, subhandlers []string) *ast.FuncDecl
- func Ident(name string) *ast.Ident
- func If(init ast.Stmt, cond ast.Expr, statements ...ast.Stmt) *ast.IfStmt
- func Index(x, index ast.Expr) *ast.IndexExpr
- func Int(val string) *ast.BasicLit
- func KeyValue(key, value ast.Expr) *ast.KeyValueExpr
- func LiteralHandler(name, literal string) *ast.FuncDecl
- func MapType(key, value ast.Expr) *ast.MapType
- func Package(name string, imports []string, decls ...ast.Decl) *ast.File
- func ParseStmt(stmt string) (ast.Stmt, error)
- func ParseStmts(stmts string) ([]ast.Stmt, error)
- func PlusHandler(name, subhandler string) *ast.FuncDecl
- func PredicateHandler(name, subhandler string, negative bool) *ast.FuncDecl
- func QuestionHandler(name, subhandler string) *ast.FuncDecl
- func Range(key, value, x ast.Expr, stmt ...ast.Stmt) *ast.RangeStmt
- func Render(node interface{}) (string, error)
- func Return(vals ...ast.Expr) *ast.ReturnStmt
- func S(elts ...ast.Stmt) []ast.Stmt
- func Sel(x ast.Expr, sel string) *ast.SelectorExpr
- func SelIdent(name string) ast.Expr
- func Slice(x, low, high ast.Expr, other ...ast.Expr) *ast.SliceExpr
- func SliceType(x ast.Expr) *ast.ArrayType
- func Star(x ast.Expr) *ast.StarExpr
- func StarHandler(name, subhandler string) *ast.FuncDecl
- func Stmt(stmt string) ast.Stmt
- func Stmts(stmts string) []ast.Stmt
- func String(val string) *ast.BasicLit
- func Struct(fields ...*ast.Field) ast.Expr
- func StructLiteral(name string, elts ...ast.Expr) ast.Expr
- func Switch(init ast.Stmt, tag ast.Expr, cases ...ast.Stmt) *ast.SwitchStmt
- func Type(name string, ty ast.Expr) *ast.GenDecl
- func Unary(op token.Token, x ast.Expr) *ast.UnaryExpr
- func Var(name string, ty, val ast.Expr) *ast.GenDecl
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssignMulti ¶
func CaptureHandler ¶
func CharClassHandler ¶
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 DotHandler ¶
func Expr ¶
Expr returns the ast.Expr parsed from a string. It panics if the string cannot be parsed as Go expression.
func LiteralHandler ¶
LiteralHandler generates Go AST for the literal handler.
func PlusHandler ¶
func QuestionHandler ¶
func StarHandler ¶
func Stmt ¶
Stmt returns the ast.Stmt parsed from a string. It panics if the string cannot be parsed as Go statement.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.