Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkg/parser/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ const (
EtConst
// EtString is a const for 'String' type expression
EtString
// EtNil is a const for 'None' type expression
EtNil
)

var (
Expand Down
6 changes: 6 additions & 0 deletions pkg/parser/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ func (e *expr) getNamedArg(name string) *expr {
}

func (e *expr) doGetFloatArg() (float64, error) {
if e.etype == EtNil {
return 0, ErrBadType
}
if e.etype != EtConst {
return 0, ErrBadType
}
Expand All @@ -30,6 +33,9 @@ func (e *expr) doGetFloatArg() (float64, error) {
}

func (e *expr) doGetStringArg() (string, error) {
if e.etype == EtNil {
return "", nil
}
if e.etype != EtString {
return "", ErrBadType
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,11 @@ func parseExprWithoutPipe(e string) (Expr, string, error) {
if strings.ToLower(name) == "false" || strings.ToLower(name) == "true" {
return &expr{valStr: name, etype: EtString, target: name}, e, nil
}
//check for none arg explicitly
if strings.EqualFold(name, "none") {
return &expr{valStr: "", etype: EtNil, target: "none"}, e, nil
}

if name == "" {
return nil, e, ErrMissingArgument
}
Expand Down
17 changes: 17 additions & 0 deletions pkg/parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,23 @@ func TestParseExpr(t *testing.T) {
argString: "metric, key=true",
},
},
{
s: "None",
e: &expr{target: "none", etype: EtNil},
},
{
s: "asPercent(metric, None, 1)",
e: &expr{
target: "asPercent",
etype: EtFunc,
args: []*expr{
{target: "metric"},
{target: "none", etype: EtNil},
{val: 1, etype: EtConst},
},
argString: "metric, None, 1",
},
},
{
s: "func(metric, key=1)",
e: &expr{
Expand Down