From e59ec59b027f921a6bfbe5014b15c2a802445ada Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Wed, 29 Nov 2023 16:01:41 +0100 Subject: pkg/ast: support expressions with ast.Type So far they have the following grammar: OP = "==", "!=", "&" value-expr = value-expr OP value-expr | factor factor = "(" and-expr ")" | integer | identifier | string Operators are left associative, e.g. A & B & C is the same as (A & B) & C. Further restrictions will be imposed in pkg/compiler. This will help implement conditionally included fields. --- pkg/ast/clone.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'pkg/ast/clone.go') diff --git a/pkg/ast/clone.go b/pkg/ast/clone.go index 0c9c831f0..e23a9eb70 100644 --- a/pkg/ast/clone.go +++ b/pkg/ast/clone.go @@ -157,7 +157,7 @@ func (n *Int) Clone() Node { } func (n *Type) Clone() Node { - return &Type{ + ret := &Type{ Pos: n.Pos, Value: n.Value, ValueFmt: n.ValueFmt, @@ -168,6 +168,10 @@ func (n *Type) Clone() Node { Colon: cloneTypes(n.Colon), Args: cloneTypes(n.Args), } + if n.Expression != nil { + ret.Expression = n.Expression.Clone().(*BinaryExpression) + } + return ret } func (n *Field) Clone() Node { @@ -181,6 +185,15 @@ func (n *Field) Clone() Node { } } +func (n *BinaryExpression) Clone() Node { + return &BinaryExpression{ + Pos: n.Pos, + Operator: n.Operator, + Left: n.Left.Clone().(*Type), + Right: n.Right.Clone().(*Type), + } +} + func cloneFields(list []*Field) (res []*Field) { for _, n := range list { res = append(res, n.Clone().(*Field)) -- cgit mrf-deployment