Documentation ¶
Overview ¶
Example (AstWalk) ¶
src := ` var fmt = import("fmt") func TestFunc(arg1, arg2, arg3) { return (arg1 + arg2) * arg3 } func Main() { return TestFunc(1, 2, 3) + BuiltinFuncX(1, 2, 3) } fmt.Println(Main()) ` stmts, err := parser.ParseSrc(src) if err != nil { fmt.Println("ERROR: ", err) return } var mainFound bool err = Walk(stmts, func(e interface{}) error { switch e := e.(type) { case *ast.CallExpr: //check if the BuiltinFuncX is getting the right number of args if e.Name == `BuiltinFuncX` && len(e.SubExprs) != 3 { return errors.New("invalid number of arguments to BuiltinFuncX") } case *ast.FuncExpr: if !mainFound && e.Name == `Main` { if len(e.Params) != 0 { return errors.New("Too many args to main") } mainFound = true } else if mainFound && e.Name == `Main` { return errors.New("Main redefined") } } return nil }) if err != nil { fmt.Println("ERROR: ", err) return } if !mainFound { fmt.Println("ERROR: Main not found") }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
Click to show internal directories.
Click to hide internal directories.