Class: DrgDSL::Ast::Expression

Inherits:
Object
  • Object
show all
Includes:
Node
Defined in:
lib/drgdsl/ast.rb

Overview

Represents a list of expressions joined with an “OR”, e.g., “exp1 or exp2 or exp3 …”

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Node

#==, #accept, included, #mdc_equality?, node_classes, #pretty_print, #sep_equality?, type, #type

Constructor Details

#initialize(expressions) ⇒ Expression

Returns a new instance of Expression.



82
83
84
# File 'lib/drgdsl/ast.rb', line 82

def initialize(expressions)
  @expressions = expressions
end

Instance Attribute Details

#expressionsObject (readonly)

Returns the value of attribute expressions.



80
81
82
# File 'lib/drgdsl/ast.rb', line 80

def expressions
  @expressions
end

Instance Method Details

#hashObject



102
103
104
# File 'lib/drgdsl/ast.rb', line 102

def hash
  @hash ||= [type, *expressions].hash
end

#only_mdc_equality_nodes?Boolean

Returns whether this expression only contains MDC equality checks.

Returns:

  • (Boolean)

    whether this expression only contains MDC equality checks.



94
95
96
# File 'lib/drgdsl/ast.rb', line 94

def only_mdc_equality_nodes?
  expressions.all?(&:mdc_equality?)
end

#only_sep_equality_nodes?Boolean

Returns whether this expression only contains SEP equality checks.

Returns:

  • (Boolean)

    whether this expression only contains SEP equality checks.



88
89
90
# File 'lib/drgdsl/ast.rb', line 88

def only_sep_equality_nodes?
  expressions.all?(&:sep_equality?)
end

#to_hashObject



98
99
100
# File 'lib/drgdsl/ast.rb', line 98

def to_hash
  { or: [expressions.map(&:to_hash)] }
end