MCPcopy Create free account
hub / github.com/ahmedakef/goshell / ParseFunction

Function ParseFunction

parser.go:11–33  ·  view source on GitHub ↗
(x string)

Source from the content-addressed store, hash-verified

9)
10
11func 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
36func ParseStatement(x string) (*AstVisitor, error) {

Callers 2

TestParseFunctionFunction · 0.85
addFunctionMethod · 0.85

Calls

no outgoing calls

Tested by 1

TestParseFunctionFunction · 0.68