Class: Opal::Sexp
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
Returns the value of attribute array
11
12
13
|
# File 'opal/lib/opal/parser/sexp.rb', line 11
def array
@array
end
|
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?
53
54
55
56
57
58
59
|
# File 'opal/lib/opal/parser/sexp.rb', line 53
def ==(other)
if other.is_a? Sexp
@array == other.array
else
@array == other
end
end
|
27
28
29
|
# File 'opal/lib/opal/parser/sexp.rb', line 27
def children
@array[1..-1]
end
|
67
68
69
|
# File 'opal/lib/opal/parser/sexp.rb', line 67
def column
@source && @source[1]
end
|
49
50
51
|
# File 'opal/lib/opal/parser/sexp.rb', line 49
def dup
Sexp.new(@array.dup)
end
|
#inspect ⇒ Object
Also known as:
to_s
71
72
73
|
# File 'opal/lib/opal/parser/sexp.rb', line 71
def inspect
"(#{@array.map { |e| e.inspect }.join ', '})"
end
|
63
64
65
|
# File 'opal/lib/opal/parser/sexp.rb', line 63
def line
@source && @source[0]
end
|
#pretty_inspect ⇒ Object
75
76
77
|
# File 'opal/lib/opal/parser/sexp.rb', line 75
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
|
45
46
47
|
# File 'opal/lib/opal/parser/sexp.rb', line 45
def to_ary
@array
end
|
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
|