Skip to content

Commit

Permalink
Fix solution to not allow "= ="
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerHelmuth committed Oct 23, 2023
1 parent 570390a commit 11910fb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
12 changes: 5 additions & 7 deletions pkg/ottl/grammar.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package ottl // import "github.com/open-telemetry/opentelemetry-collector-contri
import (
"encoding/hex"
"fmt"
"strings"

"github.com/alecthomas/participle/v2/lexer"
)
Expand Down Expand Up @@ -144,9 +143,8 @@ var compareOpTable = map[string]compareOp{

// Capture is how the parser converts an operator string to a compareOp.
func (c *compareOp) Capture(values []string) error {
op, ok := compareOpTable[strings.Join(values, "")]
op, ok := compareOpTable[values[0]]
if !ok {

return fmt.Errorf("'%s' is not a valid operator", values[0])
}
*c = op
Expand Down Expand Up @@ -176,7 +174,7 @@ func (c *compareOp) String() string {
// comparison represents an optional boolean condition.
type comparison struct {
Left value `parser:"@@"`
Op compareOp `parser:"@(OpComparison | Equal Equal)"`
Op compareOp `parser:"@OpComparison"`
Right value `parser:"@@"`
}

Expand Down Expand Up @@ -220,7 +218,7 @@ type converter struct {
}

type argument struct {
Name string `parser:"(@(Lowercase(Uppercase | Lowercase)*) Equal (?! Equal))?"`
Name string `parser:"(@(Lowercase(Uppercase | Lowercase)*) Equal)?"`
Value value `parser:"@@"`
}

Expand Down Expand Up @@ -436,14 +434,14 @@ func buildLexer() *lexer.StatefulDefinition {
{Name: `Float`, Pattern: `[-+]?\d*\.\d+([eE][-+]?\d+)?`},
{Name: `Int`, Pattern: `[-+]?\d+`},
{Name: `String`, Pattern: `"(\\"|[^"])*"`},
{Name: `Equal`, Pattern: `=`},
{Name: `OpNot`, Pattern: `\b(not)\b`},
{Name: `OpOr`, Pattern: `\b(or)\b`},
{Name: `OpAnd`, Pattern: `\b(and)\b`},
{Name: `OpComparison`, Pattern: `!=|>=|<=|>|<`},
{Name: `OpComparison`, Pattern: `==|!=|>=|<=|>|<`},
{Name: `OpAddSub`, Pattern: `\+|\-`},
{Name: `OpMultDiv`, Pattern: `\/|\*`},
{Name: `Boolean`, Pattern: `\b(true|false)\b`},
{Name: `Equal`, Pattern: `=`},
{Name: `LParen`, Pattern: `\(`},
{Name: `RParen`, Pattern: `\)`},
{Name: `Punct`, Pattern: `[,.\[\]]`},
Expand Down
3 changes: 1 addition & 2 deletions pkg/ottl/lexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ func Test_lexer(t *testing.T) {
}},
{"basic_equality", "3==4.9", false, []result{
{"Int", "3"},
{"Equal", "="},
{"Equal", "="},
{"OpComparison", "=="},
{"Float", "4.9"},
}},
{"basic_inequality", "3!=4.9", false, []result{
Expand Down

0 comments on commit 11910fb

Please sign in to comment.