Module: LiveAST::RubyParser::Test
- Defined in:
- lib/live_ast/ruby_parser/test.rb
Class Method Summary collapse
-
.unified_sexp? ⇒ Boolean
Whether this is Ryan Davis’s unified sexp format.
-
.unparser_matches_ruby2ruby? ⇒ Boolean
Whether the unparser output matches that of ruby2ruby.
Instance Method Summary collapse
-
#binop_block(name, op) ⇒ Object
binop_block(:foo, :+) returns the ast of.
-
#binop_def(name, op) ⇒ Object
binop_def(:f, :+) returns the ast of.
-
#binop_define_method(name, op, using = :define_method) ⇒ Object
binop_define_method(:f, :*) returns the ast of.
-
#binop_define_method_with_var(var_name, op) ⇒ Object
binop_define_method_with_var(:method_name, :/) returns the ast of.
-
#binop_define_singleton_method(name, op, receiver) ⇒ Object
binop_define_singleton_method(:f, :+, :a) returns the ast of.
-
#binop_proc_new(op) ⇒ Object
binop_proc_new(:*) returns the ast of.
-
#nested_defs(u, v, str) ⇒ Object
nested_defs(:f, :g, “foo”) returns the ast of.
-
#nested_lambdas(str) ⇒ Object
nested_lambdas(“foo”) returns the ast of.
-
#no_arg_block(name, ret) ⇒ Object
no_arg_block(:foo, “bar”) returns the ast of.
-
#no_arg_def(name, ret) ⇒ Object
no_arg_def(:f, “A#f”) returns the ast of.
-
#no_arg_def_return(ast) ⇒ Object
no_arg_def_return(no_arg_def(:f, “A#f”)) == “A#f”.
-
#singleton_binop_def(const, name, op) ⇒ Object
singleton_binop_def(:A, :f, :+) returns the ast of.
-
#singleton_no_arg_def(name, ret) ⇒ Object
singleton_no_arg_def(:f, “foo”) returns the ast of.
Class Method Details
.unified_sexp? ⇒ Boolean
Whether this is Ryan Davis’s unified sexp format.
12 13 14 |
# File 'lib/live_ast/ruby_parser/test.rb', line 12 def unified_sexp? true end |
.unparser_matches_ruby2ruby? ⇒ Boolean
Whether the unparser output matches that of ruby2ruby.
19 20 21 |
# File 'lib/live_ast/ruby_parser/test.rb', line 19 def unparser_matches_ruby2ruby? true end |
Instance Method Details
#binop_block(name, op) ⇒ Object
binop_block(:foo, :+) returns the ast of
foo { |x, y| x + y }
145 146 147 148 149 150 |
# File 'lib/live_ast/ruby_parser/test.rb', line 145 def binop_block(name, op) s(:iter, s(:call, nil, name), s(:args, :x, :y), s(:call, s(:lvar, :x), op, s(:lvar, :y))) end |
#binop_def(name, op) ⇒ Object
binop_def(:f, :+) returns the ast of
def f(x, y)
x + y
end
60 61 62 63 64 65 |
# File 'lib/live_ast/ruby_parser/test.rb', line 60 def binop_def(name, op) s(:defn, name, s(:args, :x, :y), s(:call, s(:lvar, :x), op, s(:lvar, :y))) end |
#binop_define_method(name, op, using = :define_method) ⇒ Object
binop_define_method(:f, :*) returns the ast of
define_method :f do |x, y|
x * y
end
binop_define_method(:f, :-, :my_def) returns the ast of
my_def :f do |x, y|
x - y
end
95 96 97 98 99 100 |
# File 'lib/live_ast/ruby_parser/test.rb', line 95 def binop_define_method(name, op, using = :define_method) s(:iter, s(:call, nil, using, s(:lit, name)), s(:args, :x, :y), s(:call, s(:lvar, :x), op, s(:lvar, :y))) end |
#binop_define_method_with_var(var_name, op) ⇒ Object
binop_define_method_with_var(:method_name, :/) returns the ast of
define_method method_name do |x, y|
x / y
end
109 110 111 112 113 114 |
# File 'lib/live_ast/ruby_parser/test.rb', line 109 def binop_define_method_with_var(var_name, op) s(:iter, s(:call, nil, :define_method, s(:lvar, var_name)), s(:args, :x, :y), s(:call, s(:lvar, :x), op, s(:lvar, :y))) end |
#binop_define_singleton_method(name, op, receiver) ⇒ Object
binop_define_singleton_method(:f, :+, :a) returns the ast of
a.define_singleton_method :f do |x, y|
x + y
end
123 124 125 126 127 128 129 |
# File 'lib/live_ast/ruby_parser/test.rb', line 123 def binop_define_singleton_method(name, op, receiver) s(:iter, s(:call, s(:lvar, receiver), :define_singleton_method, s(:lit, name)), s(:args, :x, :y), s(:call, s(:lvar, :x), op, s(:lvar, :y))) end |
#binop_proc_new(op) ⇒ Object
binop_proc_new(:*) returns the ast of
Proc.new { |x, y| x * y }
157 158 159 160 161 162 |
# File 'lib/live_ast/ruby_parser/test.rb', line 157 def binop_proc_new(op) s(:iter, s(:call, s(:const, :Proc), :new), s(:args, :x, :y), s(:call, s(:lvar, :x), op, s(:lvar, :y))) end |
#nested_defs(u, v, str) ⇒ Object
nested_defs(:f, :g, “foo”) returns the ast of
def f
Class.new do
def g
"foo"
end
end
end
190 191 192 193 194 195 196 197 198 |
# File 'lib/live_ast/ruby_parser/test.rb', line 190 def nested_defs(u, v, str) s(:defn, u, s(:args), s(:iter, s(:call, s(:const, :Class), :new), 0, s(:defn, v, s(:args), s(:str, str)))) end |
#nested_lambdas(str) ⇒ Object
nested_lambdas(“foo”) returns the ast of
lambda {
lambda {
"foo"
}
}
173 174 175 176 177 178 |
# File 'lib/live_ast/ruby_parser/test.rb', line 173 def nested_lambdas(str) s(:iter, s(:call, nil, :lambda), 0, s(:iter, s(:call, nil, :lambda), 0, s(:str, str))) end |
#no_arg_block(name, ret) ⇒ Object
no_arg_block(:foo, “bar”) returns the ast of
foo { "bar" }
136 137 138 |
# File 'lib/live_ast/ruby_parser/test.rb', line 136 def no_arg_block(name, ret) s(:iter, s(:call, nil, name), 0, s(:str, ret)) end |
#no_arg_def(name, ret) ⇒ Object
no_arg_def(:f, “A#f”) returns the ast of
def f
"A#f"
end
31 32 33 |
# File 'lib/live_ast/ruby_parser/test.rb', line 31 def no_arg_def(name, ret) s(:defn, name, s(:args), s(:str, ret)) end |
#no_arg_def_return(ast) ⇒ Object
no_arg_def_return(no_arg_def(:f, “A#f”)) == “A#f”
49 50 51 |
# File 'lib/live_ast/ruby_parser/test.rb', line 49 def no_arg_def_return(ast) ast[3][1] end |
#singleton_binop_def(const, name, op) ⇒ Object
singleton_binop_def(:A, :f, :+) returns the ast of
def A.f(x, y)
x + y
end
74 75 76 77 78 79 80 |
# File 'lib/live_ast/ruby_parser/test.rb', line 74 def singleton_binop_def(const, name, op) s(:defs, s(:const, const), name, s(:args, :x, :y), s(:call, s(:lvar, :x), op, s(:lvar, :y))) end |
#singleton_no_arg_def(name, ret) ⇒ Object
singleton_no_arg_def(:f, “foo”) returns the ast of
def self.f
"foo"
end
42 43 44 |
# File 'lib/live_ast/ruby_parser/test.rb', line 42 def singleton_no_arg_def(name, ret) s(:defs, s(:self), name, s(:args), s(:str, ret)) end |