dynamo-browse/internal/dynamo-browse/models/modexpr/ast.go
Leon Mika b51c13dfb1
Issue 32: Fixed some TODOs in query expressions
- Fixed the gaps in conjunctions, disjunctions, and equality operator for expression value evaluation.
- Fixed the issue in which '^=' was treated as two separate tokens, it's now a single token.
2022-10-11 22:16:20 +11:00

35 lines
685 B
Go

package modexpr
import (
"github.com/alecthomas/participle/v2"
"github.com/pkg/errors"
)
type astExpr struct {
Attributes []*astAttribute `parser:"@@ (',' @@)*"`
}
type astAttribute struct {
Names *astKeyList `parser:"@@ '='"`
Value *astLiteralValue `parser:"@@"`
}
type astKeyList struct {
Names []string `parser:"@Ident ('/' @Ident)*"`
}
type astLiteralValue struct {
String string `parser:"@String"`
}
var parser = participle.MustBuild[astExpr]()
func Parse(expr string) (*ModExpr, error) {
ast, err := parser.ParseString("expr", expr)
if err != nil {
return nil, errors.Wrapf(err, "cannot parse expression: '%v'", expr)
}
return &ModExpr{ast: ast}, nil
}