aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/ast/clone.go
diff options
context:
space:
mode:
authorAleksandr Nogikh <nogikh@google.com>2023-11-29 16:01:41 +0100
committerAleksandr Nogikh <nogikh@google.com>2024-02-19 11:54:01 +0000
commite59ec59b027f921a6bfbe5014b15c2a802445ada (patch)
tree1c69d1db1b34e0b53d620f9fe272cf9f374b1400 /pkg/ast/clone.go
parent164800ebad7f26d05eefb0095d190462ed97bee0 (diff)
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.
Diffstat (limited to 'pkg/ast/clone.go')
-rw-r--r--pkg/ast/clone.go15
1 files changed, 14 insertions, 1 deletions
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))