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
35
36
37
|
# File 'opal/lib/opal/parser/sexp.rb', line 35
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
39
40
41
42
|
# File 'opal/lib/opal/parser/sexp.rb', line 39
def <<(other)
@array << other
self
end
|
#==(other) ⇒ Object
Also known as:
eql?
62
63
64
65
66
67
68
|
# File 'opal/lib/opal/parser/sexp.rb', line 62
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
76
77
78
|
# File 'opal/lib/opal/parser/sexp.rb', line 76
def column
@source && @source[1]
end
|
#concat(children) ⇒ Object
49
50
51
52
|
# File 'opal/lib/opal/parser/sexp.rb', line 49
def concat(children)
@array.concat(children)
self
end
|
#dup ⇒ Object
58
59
60
|
# File 'opal/lib/opal/parser/sexp.rb', line 58
def dup
Sexp.new(@array.dup)
end
|
#inspect ⇒ Object
Also known as:
to_s
80
81
82
|
# File 'opal/lib/opal/parser/sexp.rb', line 80
def inspect
"(#{@array.map { |e| e.inspect }.join ', '})"
end
|
#line ⇒ Object
72
73
74
|
# File 'opal/lib/opal/parser/sexp.rb', line 72
def line
@source && @source[0]
end
|
31
32
33
|
# File 'opal/lib/opal/parser/sexp.rb', line 31
def meta
@meta ||= {}
end
|
#pretty_inspect ⇒ Object
84
85
86
|
# File 'opal/lib/opal/parser/sexp.rb', line 84
def pretty_inspect
"(#{line ? "#{line} " : ''}#{@array.map { |e| e.inspect }.join ', '})"
end
|
#push(*parts) ⇒ Object
44
45
46
47
|
# File 'opal/lib/opal/parser/sexp.rb', line 44
def push(*parts)
@array.push(*parts)
self
end
|
#to_ary ⇒ Object
54
55
56
|
# File 'opal/lib/opal/parser/sexp.rb', line 54
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
|