Class: Opal::Sexp
  
  
  
  
  
    - Inherits:
- 
      Object
      
        
        show all
      
    
    - Defined in:
- opal/lib/opal/parser/sexp.rb
 
Overview
  
    [Opal::Sexp] is used to build up the syntax tree inside [Opal::Parser]. The
compiler then steps through the sexp trees to generate the javascript code.
For example, an array of integers [1, 2] might be represented by:
s(:array, s(:int, 1), s(:int, 2))
   
 
  
  Instance Attribute Summary collapse
  
  
    
      Instance Method Summary
      collapse
    
    
  
  Constructor Details
  
    
  
  
    #initialize(args)  ⇒ Sexp 
  
  
  
  
    Returns a new instance of Sexp
   
 
  
  
    | 
15
16
17 | # File 'opal/lib/opal/parser/sexp.rb', line 15
def initialize(args)
  @array = args
end | 
 
  
 
  Dynamic Method Handling
  
    This class handles dynamic methods through the method_missing method
    
  
  
    
  
  
    #method_missing(sym, *args, &block)  ⇒ Object 
  
  
  
  
    | 
31
32
33 | # File 'opal/lib/opal/parser/sexp.rb', line 31
def method_missing(sym, *args, &block)
  @array.send sym, *args, &block
end | 
 
  
 
  
    Instance Attribute Details
    
      
      
      
  
  
    #array  ⇒ Object  
  
  
  
  
    Returns the value of attribute array
   
 
  
  
    | 
11
12
13 | # File 'opal/lib/opal/parser/sexp.rb', line 11
def array
  @array
end | 
 
    
      
      
      
  
  
    #source  ⇒ Object 
  
  
  
  
    Returns the value of attribute source
   
 
  
  
    | 
13
14
15 | # File 'opal/lib/opal/parser/sexp.rb', line 13
def source
  @source
end | 
 
    
   
  
    Instance Method Details
    
      
  
  
    #<<(other)  ⇒ Object 
  
  
  
  
    | 
35
36
37
38 | # File 'opal/lib/opal/parser/sexp.rb', line 35
def <<(other)
  @array << other
  self
end | 
 
    
      
  
  
    #==(other)  ⇒ Object 
  
  
    Also known as:
    eql?
    
  
  
  
    | 
58
59
60
61
62
63
64 | # File 'opal/lib/opal/parser/sexp.rb', line 58
def ==(other)
  if other.is_a? Sexp
    @array == other.array
  else
    @array == other
  end
end | 
 
    
      
  
  
    #children  ⇒ Object 
  
  
  
  
    | 
27
28
29 | # File 'opal/lib/opal/parser/sexp.rb', line 27
def children
  @array[1..-1]
end | 
 
    
      
  
  
    #column  ⇒ Object 
  
  
  
  
    | 
72
73
74 | # File 'opal/lib/opal/parser/sexp.rb', line 72
def column
  @source && @source[1]
end | 
 
    
      
  
  
    #concat(children)  ⇒ Object 
  
  
  
  
    | 
45
46
47
48 | # File 'opal/lib/opal/parser/sexp.rb', line 45
def concat(children)
  @array.concat(children)
  self
end | 
 
    
      
  
  
    #dup  ⇒ Object 
  
  
  
  
    | 
54
55
56 | # File 'opal/lib/opal/parser/sexp.rb', line 54
def dup
  Sexp.new(@array.dup)
end | 
 
    
      
  
  
    #inspect  ⇒ Object 
  
  
    Also known as:
    to_s
    
  
  
  
    | 
76
77
78 | # File 'opal/lib/opal/parser/sexp.rb', line 76
def inspect
  "(#{@array.map { |e| e.inspect }.join ', '})"
end | 
 
    
      
  
  
    #line  ⇒ Object 
  
  
  
  
    | 
68
69
70 | # File 'opal/lib/opal/parser/sexp.rb', line 68
def line
  @source && @source[0]
end | 
 
    
      
  
  
    #pretty_inspect  ⇒ Object 
  
  
  
  
    | 
80
81
82 | # File 'opal/lib/opal/parser/sexp.rb', line 80
def pretty_inspect
  "(#{line ? "#{line} " : ''}#{@array.map { |e| e.inspect }.join ', '})"
end | 
 
    
      
  
  
    #push(*parts)  ⇒ Object 
  
  
  
  
    | 
40
41
42
43 | # File 'opal/lib/opal/parser/sexp.rb', line 40
def push(*parts)
  @array.push(*parts)
  self
end | 
 
    
      
  
  
    #to_ary  ⇒ Object 
  
  
  
  
    | 
50
51
52 | # File 'opal/lib/opal/parser/sexp.rb', line 50
def to_ary
  @array
end | 
 
    
      
  
  
    #type  ⇒ Object 
  
  
  
  
    | 
19
20
21 | # File 'opal/lib/opal/parser/sexp.rb', line 19
def type
  @array[0]
end | 
 
    
      
  
  
    #type=(type)  ⇒ Object 
  
  
  
  
    | 
23
24
25 | # File 'opal/lib/opal/parser/sexp.rb', line 23
def type=(type)
  @array[0] = type
end |