Class: Minjs::ECMA262::Base
- Inherits:
-
Object
- Object
- Minjs::ECMA262::Base
- Defined in:
- lib/minjs/ecma262/base.rb
Overview
ECMA262 Elements
Direct Known Subclasses
Instance Attribute Summary collapse
-
#parent ⇒ Object
Returns the value of attribute parent.
Instance Method Summary collapse
-
#==(obj) ⇒ Object
compare object.
-
#add_remove_paren(node = self) ⇒ Object
add / remove parenthesis if need.
-
#concat(options, *args) ⇒ Object
concatenate some of ECMA262 elements and convert it to ECMAScript.
-
#deep_dup ⇒ Object
duplicate object.
-
#replace(from, to) ⇒ Object
Replaces child (if own it) object.
-
#to_js(options = {}) ⇒ String
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
#parent ⇒ Object
Returns the value of attribute parent.
5 6 7 |
# File 'lib/minjs/ecma262/base.rb', line 5 def parent @parent end |
Instance Method Details
#==(obj) ⇒ Object
compare object
82 83 84 85 |
# File 'lib/minjs/ecma262/base.rb', line 82 def ==(obj) puts "warning: #{self.class}: == not implement" raise "warning: #{self.class}: == not implement" end |
#add_remove_paren(node = self) ⇒ Object
add / remove parenthesis if need
88 89 90 91 92 93 94 95 96 |
# File 'lib/minjs/ecma262/base.rb', line 88 def add_remove_paren(node = self) node.traverse(nil) {|st, parent| if st.respond_to? :remove_paren st.add_paren st.remove_paren end } node end |
#concat(options, *args) ⇒ Object
concatenate some of ECMA262 elements and convert it to ECMAScript
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/minjs/ecma262/base.rb', line 19 def concat(, *args) prev = nil j = [] args.flatten.each do|x| sep = '' nl = '' if x.kind_of? Base js = x.to_js(); else js = x.to_s end if prev if prev.match(/[\w\$]\z/) and js.match(/\A[\w\$]/) sep = ' ' end # ';;' means 'empty statement' or separator of 'for statement' # that must not be deleted if prev.match(/;;\Z/) prev.sub!(/;;\Z/, ";") elsif prev.match(/;\Z/) and js == "}" prev.sub!(/;\Z/, "") elsif prev.match(/;\Z/) and js == ";" prev.sub!(/;\Z/, "") elsif prev.match(/[\-]\Z/) and js.match(/^\-/) sep = ' ' elsif prev.match(/[\+]\Z/) and js.match(/^\+/) sep = ' ' end end #for debug unless [:no_debug] if (@logger and @logger.debug?) || [:debug] if js.match(/;\z/) nl = "\n" end if js.match(/}\z/) nl = "\n" end end end js = "#{sep}#{js}#{nl}"; j.push(js) prev = js end j.join("") end |
#deep_dup ⇒ Object
duplicate object
duplicate this object’s children (if own) and itself.
77 78 79 |
# File 'lib/minjs/ecma262/base.rb', line 77 def deep_dup puts "warning: #{self.class}: deep_dup not implement" end |
#replace(from, to) ⇒ Object
Replaces child (if own it) object
70 71 72 |
# File 'lib/minjs/ecma262/base.rb', line 70 def replace(from, to) puts "warning: #{self.class}: replace not implement" end |
#to_js(options = {}) ⇒ String
Returns a ECMAScript string containg the representation of element.
10 11 12 |
# File 'lib/minjs/ecma262/base.rb', line 10 def to_js( = {}) self.class.to_s + "??" end |
#traverse(parent) {|parent, self| ... } ⇒ Object
Traverses this children and itself with given block.
If this element has children, traverse children first, then yield block with parent and self.
107 108 109 |
# File 'lib/minjs/ecma262/base.rb', line 107 def traverse(parent, &block) end |