Module: Minjs::ECMA262::BinaryOperation
- Included in:
- ExpAdd, ExpAnd, ExpComma, ExpDiv, ExpEq, ExpGt, ExpGtEq, ExpIn, ExpInstanceOf, ExpLShift, ExpLogicalAnd, ExpLogicalOr, ExpLt, ExpLtEq, ExpMod, ExpMul, ExpNotEq, ExpOr, ExpRShift, ExpStrictEq, ExpStrictNotEq, ExpSub, ExpURShift, ExpXor
- Defined in:
- lib/minjs/ecma262/expression.rb
Overview
Module of typically binary operation expression.
Typically binary operation expression has two values(val, val2) and operation symbol.
Instance Attribute Summary collapse
-
#val ⇒ Object
readonly
Returns the value of attribute val.
-
#val2 ⇒ Object
readonly
Returns the value of attribute val2.
Instance Method Summary collapse
-
#==(obj) ⇒ Object
compare object.
-
#add_paren ⇒ Object
add parenthesis if need.
-
#deep_dup ⇒ Object
duplicate object.
-
#remove_paren ⇒ Object
remove parenthesis if possible.
-
#replace(from, to) ⇒ Object
Replaces children object.
-
#to_js(options = {}) ⇒ Object
Returns a ECMAScript string containg the representation of element.
-
#traverse(parent) {|parent, _self| ... } ⇒ Object
Traverses this children and itself with given block.
Instance Attribute Details
#val ⇒ Object (readonly)
Returns the value of attribute val.
65 66 67 |
# File 'lib/minjs/ecma262/expression.rb', line 65 def val @val end |
#val2 ⇒ Object (readonly)
Returns the value of attribute val2.
65 66 67 |
# File 'lib/minjs/ecma262/expression.rb', line 65 def val2 @val2 end |
Instance Method Details
#==(obj) ⇒ Object
compare object
91 92 93 |
# File 'lib/minjs/ecma262/expression.rb', line 91 def ==(obj) self.class == obj.class and self.val == obj.val and self.val2 == obj.val2 end |
#add_paren ⇒ Object
add parenthesis if need
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/minjs/ecma262/expression.rb', line 79 def add_paren if @val.priority > self.priority @val = ExpParen.new(@val) end if @val2.priority > self.priority @val2 = ExpParen.new(@val2) end self end |
#deep_dup ⇒ Object
duplicate object
97 98 99 |
# File 'lib/minjs/ecma262/expression.rb', line 97 def deep_dup self.class.new(@val.deep_dup, @val2.deep_dup) end |
#remove_paren ⇒ Object
remove parenthesis if possible
68 69 70 71 72 73 74 75 76 |
# File 'lib/minjs/ecma262/expression.rb', line 68 def remove_paren if @val.kind_of? ExpParen and @val.val.priority <= self.priority @val = @val.val if @val.remove_paren? end if @val2.kind_of? ExpParen and @val2.val.priority < self.priority @val2 = @val2.val end self end |
#replace(from, to) ⇒ Object
Replaces children object.
103 104 105 106 107 108 109 |
# File 'lib/minjs/ecma262/expression.rb', line 103 def replace(from, to) if @val .eql? from @val = to elsif @val2 .eql? from @val2 = to end end |
#to_js(options = {}) ⇒ Object
Returns a ECMAScript string containg the representation of element.
121 122 123 |
# File 'lib/minjs/ecma262/expression.rb', line 121 def to_js( = {}) concat , @val, sym, @val2 end |
#traverse(parent) {|parent, _self| ... } ⇒ Object
Traverses this children and itself with given block.
113 114 115 116 117 |
# File 'lib/minjs/ecma262/expression.rb', line 113 def traverse(parent, &block) @val.traverse(self, &block) @val2.traverse(self, &block) yield parent, self end |