Class: Atomy::Grammar::AST::Infix

Inherits:
Node show all
Defined in:
lib/atomy/grammar.rb,
lib/atomy/node/meta.rb,
lib/atomy/node/pretty.rb,
lib/atomy/node/equality.rb,
lib/atomy/node/constructable.rb

Instance Attribute Summary collapse

Attributes inherited from Node

#line

Instance Method Summary collapse

Methods inherited from Node

#accept, #attributes, basename, #children

Constructor Details

#initialize(left, right, operator) ⇒ Infix

Returns a new instance of Infix.



87
88
89
90
91
# File 'lib/atomy/grammar.rb', line 87

def initialize(left, right, operator)
  @left = left
  @right = right
  @operator = operator
end

Instance Attribute Details

#leftObject (readonly)

Returns the value of attribute left.



92
93
94
# File 'lib/atomy/grammar.rb', line 92

def left
  @left
end

#operatorObject (readonly)

Returns the value of attribute operator.



94
95
96
# File 'lib/atomy/grammar.rb', line 94

def operator
  @operator
end

#rightObject (readonly)

Returns the value of attribute right.



93
94
95
# File 'lib/atomy/grammar.rb', line 93

def right
  @right
end

Instance Method Details

#==(other) ⇒ Object



72
73
74
75
76
77
# File 'lib/atomy/node/equality.rb', line 72

def ==(other)
  super || other.is_a?(self.class) && \
    @operator == other.operator && \
    @left == other.left && \
    @right == other.right
end

#construct(gen) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
# File 'lib/atomy/node/constructable.rb', line 106

def construct(gen)
  push_node(gen, :Infix)
  if @left
    @left.construct(gen)
  else
    gen.push_nil
  end
  @right.construct(gen)
  gen.push_literal(@operator)
  gen.send(:new, 3)
end

#each_attribute {|:operator, @operator| ... } ⇒ Object

Yields:



145
146
147
# File 'lib/atomy/node/meta.rb', line 145

def each_attribute
  yield :operator, @operator
end

#each_child {|:left, @left| ... } ⇒ Object

Yields:



149
150
151
152
# File 'lib/atomy/node/meta.rb', line 149

def each_child
  yield :left, @left if @left
  yield :right, @right
end

#throughObject



154
155
156
# File 'lib/atomy/node/meta.rb', line 154

def through
  self.class.new(@left && yield(@left), yield(@right), @operator)
end

#to_sObject



66
67
68
69
70
71
72
# File 'lib/atomy/node/pretty.rb', line 66

def to_s
  if @left
    "(#@left #@operator #@right)"
  else
    "(#@operator #@right)"
  end
end