Skip to content

Commit

Permalink
fixing logic
Browse files Browse the repository at this point in the history
Signed-off-by: odubajDT <[email protected]>
  • Loading branch information
odubajDT committed Jan 2, 2025
1 parent b14f3b4 commit 371c41a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
6 changes: 0 additions & 6 deletions pkg/ottl/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,6 @@ func (p *Parser[K]) newKeys(keys []key) ([]Key[K], error) {
}
par = arg
}
if f := keys[i].Expression.Float; f != nil {
par = literal[K]{value: *f}
}
if i := keys[i].Expression.Int; i != nil {
par = literal[K]{value: *i}
}
if keys[i].Expression.Converter != nil {
g, err := p.newGetterFromConverter(*keys[i].Expression.Converter)
if err != nil {
Expand Down
21 changes: 20 additions & 1 deletion pkg/ottl/grammar.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,18 +270,37 @@ type path struct {
Fields []field `parser:"@@ ( '.' @@ )*"`
}

func (p *path) accept(v grammarVisitor) {
v.visitPath(p)
for _, arg := range p.Fields {
arg.accept(v)
}
}

// field is an item within a path.
type field struct {
Name string `parser:"@Lowercase"`
Keys []key `parser:"( @@ )*"`
}

func (f *field) accept(v grammarVisitor) {
for _, arg := range f.Keys {
arg.accept(v)
}
}

type key struct {
String *string `parser:"'[' (@String "`
Int *int64 `parser:"| @Int"`
Expression *mathExprLiteral `parser:"| @@ ) ']'"`
}

func (k *key) accept(v grammarVisitor) {
if k.Expression != nil {
k.Expression.accept(v)
}
}

type list struct {
Values []value `parser:"'[' (@@)* (',' @@)* ']'"`
}
Expand Down Expand Up @@ -344,7 +363,7 @@ type mathExprLiteral struct {
func (m *mathExprLiteral) accept(v grammarVisitor) {
v.visitMathExprLiteral(m)
if m.Path != nil {
v.visitPath(m.Path)
m.Path.accept(v)
}
if m.Editor != nil {
m.Editor.accept(v)
Expand Down

0 comments on commit 371c41a

Please sign in to comment.