Class: Mulang::Ruby::AstProcessor
- Inherits:
-
AST::Processor
- Object
- AST::Processor
- Mulang::Ruby::AstProcessor
show all
- Includes:
- AST::Sexp, Sexp
- Defined in:
- lib/mulang/ruby/ast_processor.rb
Instance Method Summary
collapse
Methods included from Sexp
#method, #ms, #sequence, #simple_method, #simple_send
Instance Method Details
#handle_send_with_args(node, extra_args = []) ⇒ Object
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
# File 'lib/mulang/ruby/ast_processor.rb', line 170
def handle_send_with_args(node, =[])
receptor, message, *args = *node
receptor ||= s(:self)
if message == :==
message = {tag: :Equal}
elsif message == :!=
message = {tag: :NotEqual}
else
message = {tag: :Reference, contents: message}
end
ms :Send, process(receptor), message, (process_all(args) + )
end
|
#handler_missing(*args) ⇒ Object
165
166
167
168
|
# File 'lib/mulang/ruby/ast_processor.rb', line 165
def handler_missing(*args)
puts args
ms :Other
end
|
#on_and(node) ⇒ Object
50
51
52
53
54
|
# File 'lib/mulang/ruby/ast_processor.rb', line 50
def on_and(node)
value, other = *node
simple_send process(value), '&&', [process(other)]
end
|
#on_arg(node) ⇒ Object
Also known as:
on_restarg, on_procarg0
101
102
103
104
|
# File 'lib/mulang/ruby/ast_processor.rb', line 101
def on_arg(node)
name, _ = *node
ms :VariablePattern, name
end
|
#on_array(node) ⇒ Object
160
161
162
163
|
# File 'lib/mulang/ruby/ast_processor.rb', line 160
def on_array(node)
elements = *node
{tag: :MuList, contents: process_all(elements)}
end
|
#on_begin(node) ⇒ Object
25
26
27
|
# File 'lib/mulang/ruby/ast_processor.rb', line 25
def on_begin(node)
sequence(*process_all(node))
end
|
#on_block(node) ⇒ Object
83
84
85
86
87
|
# File 'lib/mulang/ruby/ast_processor.rb', line 83
def on_block(node)
send, parameters, body = *node
lambda = ms(:Lambda, process_all(parameters), process(body))
handle_send_with_args send, [lambda]
end
|
#on_class(node) ⇒ Object
6
7
8
9
10
11
12
13
14
|
# File 'lib/mulang/ruby/ast_processor.rb', line 6
def on_class(node)
name, superclass, body = *node
body ||= s(:nil)
_, class_name = *name
_, superclass_name = *superclass
ms :Class, class_name, superclass_name, process(body)
end
|
#on_const(node) ⇒ Object
147
148
149
150
|
# File 'lib/mulang/ruby/ast_processor.rb', line 147
def on_const(node)
_ns, value = *node
ms :Reference, value
end
|
#on_def(node) ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/mulang/ruby/ast_processor.rb', line 69
def on_def(node)
id, args, body = *node
body ||= s(:nil)
case id
when :equal?, :eql?, :==
method :EqualMethod, process_all(args), process(body)
when :hash
method :HashMethod, process_all(args), process(body)
else
simple_method id, process_all(args), process(body)
end
end
|
#on_defs(node) ⇒ Object
62
63
64
65
66
67
|
# File 'lib/mulang/ruby/ast_processor.rb', line 62
def on_defs(node)
_target, id, args, body = *node
body ||= s(:nil)
simple_method id, process_all(args), process(body)
end
|
#on_dstr(node) ⇒ Object
39
40
41
42
43
|
# File 'lib/mulang/ruby/ast_processor.rb', line 39
def on_dstr(node)
parts = *node
simple_send ms(:MuList, process_all(parts)), :join, []
end
|
#on_false(_) ⇒ Object
156
157
158
|
# File 'lib/mulang/ruby/ast_processor.rb', line 156
def on_false(_)
ms :MuBool, false
end
|
#on_float(node) ⇒ Object
Also known as:
on_int
119
120
121
122
|
# File 'lib/mulang/ruby/ast_processor.rb', line 119
def on_float(node)
value, _ = *node
ms :MuNumber, value
end
|
#on_if(node) ⇒ Object
126
127
128
129
130
131
132
|
# File 'lib/mulang/ruby/ast_processor.rb', line 126
def on_if(node)
condition, if_true, if_false = *node
if_true ||= s(:nil)
if_false ||= s(:nil)
ms :If, process(condition), process(if_true), process(if_false)
end
|
#on_irange(node) ⇒ Object
29
30
31
|
# File 'lib/mulang/ruby/ast_processor.rb', line 29
def on_irange(node)
ms :Other
end
|
#on_lvar(node) ⇒ Object
Also known as:
on_ivar
134
135
136
137
|
# File 'lib/mulang/ruby/ast_processor.rb', line 134
def on_lvar(node)
value = *node
ms :Reference, value.first
end
|
#on_lvasgn(node) ⇒ Object
Also known as:
on_ivasgn
139
140
141
142
|
# File 'lib/mulang/ruby/ast_processor.rb', line 139
def on_lvasgn(node)
id, value = *node
ms :Assignment, id, process(value)
end
|
#on_module(node) ⇒ Object
16
17
18
19
20
21
22
23
|
# File 'lib/mulang/ruby/ast_processor.rb', line 16
def on_module(node)
name, body = *node
body ||= s(:nil)
_, module_name = *name
ms :Object, module_name, process(body)
end
|
#on_nil(_) ⇒ Object
93
94
95
|
# File 'lib/mulang/ruby/ast_processor.rb', line 93
def on_nil(_)
ms :MuNull
end
|
#on_or(node) ⇒ Object
45
46
47
48
|
# File 'lib/mulang/ruby/ast_processor.rb', line 45
def on_or(node)
value, other = *node
simple_send process(value), '||', [process(other)]
end
|
#on_regexp(node) ⇒ Object
33
34
35
36
37
|
# File 'lib/mulang/ruby/ast_processor.rb', line 33
def on_regexp(node)
value, _ops = *node
simple_send ms(:Reference, :Regexp), :new, [process(value)]
end
|
#on_return(node) ⇒ Object
56
57
58
59
60
|
# File 'lib/mulang/ruby/ast_processor.rb', line 56
def on_return(node)
value = *node
ms(:Return, process(value.first))
end
|
#on_self(_) ⇒ Object
97
98
99
|
# File 'lib/mulang/ruby/ast_processor.rb', line 97
def on_self(_)
ms :Self
end
|
#on_send(node) ⇒ Object
89
90
91
|
# File 'lib/mulang/ruby/ast_processor.rb', line 89
def on_send(node)
handle_send_with_args(node)
end
|
#on_str(node) ⇒ Object
109
110
111
112
|
# File 'lib/mulang/ruby/ast_processor.rb', line 109
def on_str(node)
value, _ = *node
ms :MuString, value
end
|
#on_sym(node) ⇒ Object
114
115
116
117
|
# File 'lib/mulang/ruby/ast_processor.rb', line 114
def on_sym(node)
value, _ = *node
ms :MuSymbol, value.to_s
end
|
#on_true(_) ⇒ Object
152
153
154
|
# File 'lib/mulang/ruby/ast_processor.rb', line 152
def on_true(_)
ms :MuBool, true
end
|