Class: Minjs::ECMA262::StBlock
- Defined in:
- lib/minjs/ecma262/statement.rb
Overview
Base class of ECMA262 Block element.
Instance Attribute Summary collapse
-
#statement_list ⇒ Object
readonly
Returns the value of attribute statement_list.
Attributes inherited from Base
Instance Method Summary collapse
-
#==(obj) ⇒ Object
compare object.
-
#[](i) ⇒ Statement
Returns the statement at index.
-
#deep_dup ⇒ Object
duplicate object.
-
#empty? ⇒ Boolean
True if block is empty.
-
#initialize(statement_list) ⇒ StBlock
constructor
A new instance of StBlock.
-
#remove_empty_statement ⇒ Object
Removes empty statement in this block.
-
#replace(from, to) ⇒ Object
Replaces children object.
-
#to_exp(options = {}) ⇒ Object
Converts block to expression and returns it.
-
#to_exp? ⇒ Boolean
true if block can convert to expression.
-
#to_js(options = {}) ⇒ Object
Returns a ECMAScript string containg the representation of element.
-
#to_return ⇒ Object
Converts block to ‘return statement’ and returns it.
-
#to_return? ⇒ Boolean
True if block can convert to ‘return statement’.
-
#to_statement ⇒ Object
Converts block to single statement and return it.
-
#to_statement? ⇒ Boolean
True if block can convert to single statement.
-
#traverse(parent) {|parent, _self| ... } ⇒ Object
Traverses this children and itself with given block.
Methods inherited from Statement
Methods inherited from Base
Constructor Details
#initialize(statement_list) ⇒ StBlock
Returns a new instance of StBlock.
35 36 37 38 39 40 41 |
# File 'lib/minjs/ecma262/statement.rb', line 35 def initialize(statement_list) if statement_list.kind_of? Array @statement_list = StatementList.new(statement_list) else @statement_list = statement_list end end |
Instance Attribute Details
#statement_list ⇒ Object (readonly)
Returns the value of attribute statement_list.
32 33 34 |
# File 'lib/minjs/ecma262/statement.rb', line 32 def statement_list @statement_list end |
Instance Method Details
#==(obj) ⇒ Object
compare object
66 67 68 69 |
# File 'lib/minjs/ecma262/statement.rb', line 66 def ==(obj) self.class == obj.class and @statement_list == obj.statement_list end |
#[](i) ⇒ Statement
Returns the statement at index
133 134 135 |
# File 'lib/minjs/ecma262/statement.rb', line 133 def [](i) @statement_list[i] end |
#deep_dup ⇒ Object
duplicate object
45 46 47 |
# File 'lib/minjs/ecma262/statement.rb', line 45 def deep_dup self.class.new(@statement_list.deep_dup) end |
#empty? ⇒ Boolean
Returns true if block is empty.
124 125 126 127 128 |
# File 'lib/minjs/ecma262/statement.rb', line 124 def empty? @statement_list.statement_list.select{|s| s.class != StEmpty }.length == 0 end |
#remove_empty_statement ⇒ Object
Removes empty statement in this block.
138 139 140 |
# File 'lib/minjs/ecma262/statement.rb', line 138 def remove_empty_statement statement_list.remove_empty_statement end |
#replace(from, to) ⇒ Object
Replaces children object.
51 52 53 54 55 |
# File 'lib/minjs/ecma262/statement.rb', line 51 def replace(from, to) if from == @statement_list @statement_list = to end end |
#to_exp(options = {}) ⇒ Object
Converts block to expression and returns it.
86 87 88 89 90 |
# File 'lib/minjs/ecma262/statement.rb', line 86 def to_exp( = {}) @statement_list.statement_list.select{|s| s.class != StEmpty }[0].to_exp.deep_dup end |
#to_exp? ⇒ Boolean
true if block can convert to expression
78 79 80 81 82 83 |
# File 'lib/minjs/ecma262/statement.rb', line 78 def to_exp? t = @statement_list.statement_list.select{|s| s.class != StEmpty } t.length == 1 and t[0].to_exp? end |
#to_js(options = {}) ⇒ Object
Returns a ECMAScript string containg the representation of element.
73 74 75 |
# File 'lib/minjs/ecma262/statement.rb', line 73 def to_js( = {}) concat(, "{", @statement_list, "}") end |
#to_return ⇒ Object
Converts block to ‘return statement’ and returns it
119 120 121 |
# File 'lib/minjs/ecma262/statement.rb', line 119 def to_return to_statement.to_return end |
#to_return? ⇒ Boolean
Returns true if block can convert to ‘return statement’.
114 115 116 |
# File 'lib/minjs/ecma262/statement.rb', line 114 def to_return? to_statement? and to_statement.to_return? end |
#to_statement ⇒ Object
Converts block to single statement and return it.
101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/minjs/ecma262/statement.rb', line 101 def to_statement t = @statement_list.statement_list.select{|s| s.class != StEmpty } if t[0] t[0].deep_dup else StEmpty.new end end |
#to_statement? ⇒ Boolean
Returns true if block can convert to single statement.
93 94 95 96 97 98 |
# File 'lib/minjs/ecma262/statement.rb', line 93 def to_statement? t = @statement_list.statement_list.select{|s| s.class != StEmpty } t.length == 1 || t.length == 0 end |
#traverse(parent) {|parent, _self| ... } ⇒ Object
Traverses this children and itself with given block.
60 61 62 63 |
# File 'lib/minjs/ecma262/statement.rb', line 60 def traverse(parent, &block) @statement_list.traverse(self, &block) yield parent, self end |