MCPcopy
hub / github.com/lmorg/murex / parseFunction

Method parseFunction

lang/expressions/parse_function.go:16–61  ·  view source on GitHub ↗
(exec bool, cmd []rune, strOrVal varFormatting)

Source from the content-addressed store, hash-verified

14}
15
16func (tree *ParserT) parseFunction(exec bool, cmd []rune, strOrVal varFormatting) ([]rune, primitives.FunctionT, error) {
17 params, err := tree.parseFunctionParameters(cmd)
18 if err != nil {
19 return nil, nil, fmt.Errorf("cannot parse `function(parameters...)`: %s", err.Error())
20 }
21 r := append(cmd, params...)
22
23 if !exec {
24 return r, nil, nil
25 }
26
27 fn := func() (*primitives.Value, error) {
28 val := new(primitives.Value)
29 var err error
30
31 fork := tree.p.Fork(lang.F_NO_STDIN | lang.F_CREATE_STDOUT)
32 params = append([]rune{' '}, params[1:len(params)-1]...)
33 block := append(cmd, params...)
34 val.ExitNum, err = fork.Execute(block)
35
36 //val.Error = fork.Stderr
37
38 if err != nil {
39 return val, fmt.Errorf("function `%s` compilation error: %s", string(cmd), err.Error())
40 }
41
42 if val.ExitNum != 0 {
43 return val, fmt.Errorf("function `%s` returned non-zero exit number (%d)", string(cmd), val.ExitNum)
44 }
45
46 b, err := fork.Stdout.ReadAll()
47 if err != nil {
48 return val, fmt.Errorf("function `%s` STDOUT read error: %s", string(cmd), err.Error())
49 }
50 b = utils.CrLfTrim(b)
51 val.DataType = fork.Stdout.GetDataType()
52 val.Value, err = formatBytes(tree, b, val.DataType, strOrVal)
53 if err != nil {
54 return nil, fmt.Errorf("function `%s` STDOUT conversion error: %s", string(cmd), err.Error())
55 }
56
57 return val, err
58 }
59
60 return r, fn, nil
61}
62
63func (tree *ParserT) parseFunctionParameters(cmd []rune) ([]rune, error) {
64 var escape bool

Callers 2

parseStatementMethod · 0.95
parseExpressionMethod · 0.95

Calls 8

CrLfTrimFunction · 0.92
formatBytesFunction · 0.85
ForkMethod · 0.80
ExecuteMethod · 0.80
ErrorMethod · 0.65
ReadAllMethod · 0.65
GetDataTypeMethod · 0.65

Tested by

no test coverage detected