tree.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package ast
  2. // FilterNode is the the base instance of a tree leaf node, which is a conditional operator
  3. // which contains operands that may also be leaf nodes. A go type-switch should be used to
  4. // reduce the FilterNode to a concrete type to operate on. If only the type of operator is
  5. // required, the `Op()` field can be used.
  6. type FilterNode interface {
  7. Op() FilterOp
  8. }
  9. // FilterGroup is a specialized interface for ops which can collect N operands.
  10. type FilterGroup interface {
  11. FilterNode
  12. // Adds a new leaf node to the FilterGroup
  13. Add(FilterNode)
  14. }
  15. // Identifier is a struct that contains the data required to resolve a specific operand to a concrete
  16. // value during operator compilation.
  17. type Identifier struct {
  18. Field *Field
  19. Key string
  20. }
  21. // Equal returns true if the identifiers are equal
  22. func (id *Identifier) Equal(ident Identifier) bool {
  23. return id.Field.Equal(ident.Field) && id.Key == ident.Key
  24. }
  25. // String returns the string representation for the Identifier
  26. func (id *Identifier) String() string {
  27. if id == nil {
  28. return "<nil>"
  29. }
  30. if id.Field == nil {
  31. return "<nil field>"
  32. }
  33. s := id.Field.Name
  34. if id.Key != "" {
  35. s += "[" + id.Key + "]"
  36. }
  37. return s
  38. }