diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d66084e2..306a3dd87 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Changelog +## v1.0.0-beta2 [unreleased] + +### Release Notes + +### Features + +### Bugfixes + +- [#656](https://github.com/influxdata/kapacitor/pull/656): Fix issues where an expression could not be passed as a function parameter in TICKscript. + ## v1.0.0-beta2 [2016-06-17] ### Release Notes diff --git a/tick/ast/parser.go b/tick/ast/parser.go index 05d67433a..247f0c587 100644 --- a/tick/ast/parser.go +++ b/tick/ast/parser.go @@ -359,15 +359,7 @@ func (p *parser) parameters() (args []Node) { } func (p *parser) parameter() (n Node) { - switch p.peek().typ { - case TokenIdent: - n = p.expression() - case TokenLambda: - n = p.lambda() - default: - n = p.primary() - } - return + return p.expression() } //parse a string list diff --git a/tick/ast/parser_test.go b/tick/ast/parser_test.go index 9a9c850cf..8527922d5 100644 --- a/tick/ast/parser_test.go +++ b/tick/ast/parser_test.go @@ -676,6 +676,80 @@ func TestParseStatements(t *testing.T) { }, }, }, + { + script: `f('first ' + string(5m) + 'third')`, + Root: &ProgramNode{ + position: position{ + pos: 0, + line: 1, + char: 1, + }, + Nodes: []Node{ + &FunctionNode{ + position: position{ + pos: 0, + line: 1, + char: 1, + }, + Type: GlobalFunc, + Func: "f", + Args: []Node{ + &BinaryNode{ + position: position{ + pos: 24, + line: 1, + char: 25, + }, + Operator: TokenPlus, + Left: &BinaryNode{ + position: position{ + pos: 11, + line: 1, + char: 12, + }, + Operator: TokenPlus, + Left: &StringNode{ + position: position{ + pos: 2, + line: 1, + char: 3, + }, + Literal: "first ", + }, + Right: &FunctionNode{ + position: position{ + pos: 13, + line: 1, + char: 14, + }, + Type: GlobalFunc, + Func: "string", + Args: []Node{ + &DurationNode{ + position: position{ + pos: 20, + line: 1, + char: 21, + }, + Dur: 5 * time.Minute, + }, + }, + }, + }, + Right: &StringNode{ + position: position{ + pos: 26, + line: 1, + char: 27, + }, + Literal: "third", + }, + }, + }, + }, + }, + }, + }, { script: `var x = 5 var y = x * 2`, diff --git a/tick/eval_test.go b/tick/eval_test.go index 5227fca9a..32f594bbf 100644 --- a/tick/eval_test.go +++ b/tick/eval_test.go @@ -848,6 +848,25 @@ f("asdf") } } +func TestEvaluate_Func_Expression_Parameter(t *testing.T) { + script := ` +f('asdf' + string(10) + 'qwerty') +` + + f := func(got string) (interface{}, error) { + if exp := "asdf10qwerty"; got != exp { + t.Errorf("unexpected arg to function: got %s exp %s", got, exp) + } + return nil, nil + } + scope := stateful.NewScope() + scope.Set("f", f) + + if _, err := tick.Evaluate(script, scope, nil, false); err != nil { + t.Fatal(err) + } +} + //------------------------------------ // Types for TestReflectionDescriber //