(x string)
| 9 | ) |
| 10 | |
| 11 | func ParseFunction(x string) (function, error) { |
| 12 | function := function{ |
| 13 | Src: x, |
| 14 | } |
| 15 | code := "package p;" + x |
| 16 | file, err := parser.ParseFile(token.NewFileSet(), "", code, 0) |
| 17 | if err != nil { |
| 18 | return function, err |
| 19 | } |
| 20 | funcDecl := file.Decls[0].(*ast.FuncDecl) |
| 21 | function.Name = funcDecl.Name.Name |
| 22 | returnVariables := funcDecl.Type.Results |
| 23 | if returnVariables == nil { |
| 24 | return function, nil |
| 25 | } |
| 26 | for _, variable := range returnVariables.List { |
| 27 | ident, ok := variable.Type.(*ast.Ident) |
| 28 | if ok { |
| 29 | function.returnVariables = append(function.returnVariables, ident.Name) |
| 30 | } |
| 31 | } |
| 32 | return function, nil |
| 33 | } |
| 34 | |
| 35 | // ParseStatement is a modified version of go/parser.ParseExpr |
| 36 | func ParseStatement(x string) (*AstVisitor, error) { |
no outgoing calls