From b42f727dc514c22d73a874466fa30050b7b7f144 Mon Sep 17 00:00:00 2001 From: Tyler Helmuth <12352919+TylerHelmuth@users.noreply.github.com> Date: Fri, 15 Dec 2023 13:29:31 -0700 Subject: [PATCH] Unexport the grammar's enumSymbol --- pkg/ottl/boolean_value_test.go | 4 ++-- pkg/ottl/expression.go | 2 +- pkg/ottl/expression_test.go | 2 +- pkg/ottl/functions.go | 4 +++- pkg/ottl/functions_test.go | 6 +++--- pkg/ottl/grammar.go | 4 ++-- pkg/ottl/parser_test.go | 6 +++--- 7 files changed, 15 insertions(+), 13 deletions(-) diff --git a/pkg/ottl/boolean_value_test.go b/pkg/ottl/boolean_value_test.go index 757db6eae8fc..143b8d4a4a23 100644 --- a/pkg/ottl/boolean_value_test.go +++ b/pkg/ottl/boolean_value_test.go @@ -38,7 +38,7 @@ func valueFor(x any) value { } case strings.Contains(v, "ENUM"): // if the string contains ENUM construct an EnumSymbol from it. - val.Enum = (*EnumSymbol)(ottltest.Strp(v)) + val.Enum = (*enumSymbol)(ottltest.Strp(v)) case v == "dur1" || v == "dur2": val.Literal = &mathExprLiteral{ Path: &path{ @@ -198,7 +198,7 @@ func Test_newConditionEvaluator_invalid(t *testing.T) { name: "unknown path", comparison: &comparison{ Left: value{ - Enum: (*EnumSymbol)(ottltest.Strp("SYMBOL_NOT_FOUND")), + Enum: (*enumSymbol)(ottltest.Strp("SYMBOL_NOT_FOUND")), }, Op: EQ, Right: value{ diff --git a/pkg/ottl/expression.go b/pkg/ottl/expression.go index 863fe1c0e6c7..770c055e7630 100644 --- a/pkg/ottl/expression.go +++ b/pkg/ottl/expression.go @@ -616,7 +616,7 @@ func (p *Parser[K]) newGetter(val value) (Getter[K], error) { } if val.Enum != nil { - enum, err := p.enumParser(val.Enum) + enum, err := p.enumParser((*EnumSymbol)(val.Enum)) if err != nil { return nil, err } diff --git a/pkg/ottl/expression_test.go b/pkg/ottl/expression_test.go index 1b33b4ed9f9c..4e18958d3822 100644 --- a/pkg/ottl/expression_test.go +++ b/pkg/ottl/expression_test.go @@ -240,7 +240,7 @@ func Test_newGetter(t *testing.T) { { name: "enum", val: value{ - Enum: (*EnumSymbol)(ottltest.Strp("TEST_ENUM_ONE")), + Enum: (*enumSymbol)(ottltest.Strp("TEST_ENUM_ONE")), }, want: int64(1), }, diff --git a/pkg/ottl/functions.go b/pkg/ottl/functions.go index 7a1fc1e89a3e..801a80289ad1 100644 --- a/pkg/ottl/functions.go +++ b/pkg/ottl/functions.go @@ -19,6 +19,8 @@ type EnumParser func(*EnumSymbol) (*Enum, error) type Enum int64 +type EnumSymbol string + func newPath[K any](fields []field) Path[K] { if len(fields) == 0 { return nil @@ -430,7 +432,7 @@ func (p *Parser[K]) buildArg(argVal value, argType reflect.Type) (any, error) { } return StandardTimeGetter[K]{Getter: arg.Get}, nil case name == "Enum": - arg, err := p.enumParser(argVal.Enum) + arg, err := p.enumParser((*EnumSymbol)(argVal.Enum)) if err != nil { return nil, fmt.Errorf("must be an Enum") } diff --git a/pkg/ottl/functions_test.go b/pkg/ottl/functions_test.go index b886748f3578..3e88e6555f23 100644 --- a/pkg/ottl/functions_test.go +++ b/pkg/ottl/functions_test.go @@ -368,7 +368,7 @@ func Test_NewFunctionCall_invalid(t *testing.T) { Arguments: []argument{ { Value: value{ - Enum: (*EnumSymbol)(ottltest.Strp("SYMBOL_NOT_FOUND")), + Enum: (*enumSymbol)(ottltest.Strp("SYMBOL_NOT_FOUND")), }, }, }, @@ -568,7 +568,7 @@ func Test_NewFunctionCall(t *testing.T) { Bool: (*boolean)(ottltest.Boolp(true)), }, { - Enum: (*EnumSymbol)(ottltest.Strp("TEST_ENUM")), + Enum: (*enumSymbol)(ottltest.Strp("TEST_ENUM")), }, { List: &list{ @@ -1384,7 +1384,7 @@ func Test_NewFunctionCall(t *testing.T) { Arguments: []argument{ { Value: value{ - Enum: (*EnumSymbol)(ottltest.Strp("TEST_ENUM")), + Enum: (*enumSymbol)(ottltest.Strp("TEST_ENUM")), }, }, }, diff --git a/pkg/ottl/grammar.go b/pkg/ottl/grammar.go index 0cd63ae7feb9..7cbacccd39b9 100644 --- a/pkg/ottl/grammar.go +++ b/pkg/ottl/grammar.go @@ -235,7 +235,7 @@ type value struct { Bytes *byteSlice `parser:"| @Bytes"` String *string `parser:"| @String"` Bool *boolean `parser:"| @Boolean"` - Enum *EnumSymbol `parser:"| @Uppercase (?! Lowercase)"` + Enum *enumSymbol `parser:"| @Uppercase (?! Lowercase)"` FunctionName *string `parser:"| @(Uppercase(Uppercase | Lowercase)*)"` List *list `parser:"| @@)"` } @@ -423,7 +423,7 @@ func (m *mathOp) String() string { } } -type EnumSymbol string +type enumSymbol string // buildLexer constructs a SimpleLexer definition. // Note that the ordering of these rules matters. diff --git a/pkg/ottl/parser_test.go b/pkg/ottl/parser_test.go index 56c26a2c0abc..d026ae4fae2a 100644 --- a/pkg/ottl/parser_test.go +++ b/pkg/ottl/parser_test.go @@ -219,7 +219,7 @@ func Test_parse(t *testing.T) { }, { Value: value{ - Enum: (*EnumSymbol)(ottltest.Strp("SHA256")), + Enum: (*enumSymbol)(ottltest.Strp("SHA256")), }, }, }, @@ -289,7 +289,7 @@ func Test_parse(t *testing.T) { }, { Value: value{ - Enum: (*EnumSymbol)(ottltest.Strp("S")), + Enum: (*enumSymbol)(ottltest.Strp("S")), }, }, }, @@ -700,7 +700,7 @@ func Test_parse(t *testing.T) { }, { Value: value{ - Enum: (*EnumSymbol)(ottltest.Strp("TEST_ENUM")), + Enum: (*enumSymbol)(ottltest.Strp("TEST_ENUM")), }, }, },