ParseFunction parses a given parameter list and body as a function and returns the corresponding ast.FunctionLiteral node. The parameter list, if any, should be a comma-separated list of identifiers.
(parameterList, body string, options ...Option)
| 186 | // |
| 187 | // The parameter list, if any, should be a comma-separated list of identifiers. |
| 188 | func ParseFunction(parameterList, body string, options ...Option) (*ast.FunctionLiteral, error) { |
| 189 | |
| 190 | src := "(function(" + parameterList + ") {\n" + body + "\n})" |
| 191 | |
| 192 | parser := _newParser("", src, 1, options...) |
| 193 | program, err := parser.parse() |
| 194 | if err != nil { |
| 195 | return nil, err |
| 196 | } |
| 197 | |
| 198 | return program.Body[0].(*ast.ExpressionStatement).Expression.(*ast.FunctionLiteral), nil |
| 199 | } |
| 200 | |
| 201 | func (self *_parser) slice(idx0, idx1 file.Idx) string { |
| 202 | from := int(idx0) - self.base |
searching dependent graphs…