mvz-live_ast 1.3.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGES.rdoc +21 -1
- data/README.rdoc +17 -3
- data/lib/live_ast/ast_eval.rb +3 -1
- data/lib/live_ast/ast_load.rb +3 -1
- data/lib/live_ast/base.rb +20 -19
- data/lib/live_ast/common.rb +11 -1
- data/lib/live_ast/error.rb +2 -0
- data/lib/live_ast/evaler.rb +5 -3
- data/lib/live_ast/full.rb +4 -2
- data/lib/live_ast/irb_spy.rb +7 -5
- data/lib/live_ast/linker.rb +6 -2
- data/lib/live_ast/loader.rb +7 -2
- data/lib/live_ast/reader.rb +4 -3
- data/lib/live_ast/replace_caller.rb +14 -0
- data/lib/live_ast/replace_eval.rb +15 -14
- data/lib/live_ast/replace_load.rb +3 -1
- data/lib/live_ast/replace_raise.rb +5 -3
- data/lib/live_ast/ruby_parser/test.rb +13 -0
- data/lib/live_ast/ruby_parser/unparser.rb +3 -1
- data/lib/live_ast/ruby_parser.rb +6 -4
- data/lib/live_ast/to_ast.rb +15 -18
- data/lib/live_ast/to_ruby.rb +10 -18
- data/lib/live_ast/version.rb +3 -1
- data/lib/live_ast.rb +6 -4
- metadata +106 -134
- data/Rakefile +0 -60
- data/devel/levitate.rb +0 -184
- data/devel/levitate_config.rb +0 -4
- data/test/alias_test.rb +0 -23
- data/test/ast_eval/ast_eval_test.rb +0 -11
- data/test/ast_load/ast_load_test.rb +0 -45
- data/test/attr_test.rb +0 -24
- data/test/backtrace_test.rb +0 -159
- data/test/base/noninvasive_test.rb +0 -53
- data/test/base/reload_test.rb +0 -41
- data/test/covert_define_method_test.rb +0 -23
- data/test/def_test.rb +0 -35
- data/test/define_method_test.rb +0 -67
- data/test/define_singleton_method_test.rb +0 -15
- data/test/encoding_test/bad.rb +0 -1
- data/test/encoding_test/cp932.rb +0 -6
- data/test/encoding_test/default.rb +0 -5
- data/test/encoding_test/eucjp.rb +0 -6
- data/test/encoding_test/koi8.rb +0 -6
- data/test/encoding_test/koi8_shebang.rb +0 -7
- data/test/encoding_test/koi8_with_utf8bom.rb +0 -6
- data/test/encoding_test/usascii.rb +0 -6
- data/test/encoding_test/usascii_with_utf8bom.rb +0 -6
- data/test/encoding_test/utf8.rb +0 -6
- data/test/encoding_test/utf8bom.rb +0 -6
- data/test/encoding_test/utf8bom_only.rb +0 -5
- data/test/encoding_test/utf8dos.rb +0 -6
- data/test/encoding_test/utf8mac.rb +0 -6
- data/test/encoding_test/utf8mac_alt.rb +0 -6
- data/test/encoding_test/utf8unix.rb +0 -6
- data/test/encoding_test.rb +0 -52
- data/test/error_test.rb +0 -116
- data/test/eval_test.rb +0 -269
- data/test/flush_cache_test.rb +0 -98
- data/test/full/ast_reload_test.rb +0 -39
- data/test/full/replace_eval_test.rb +0 -431
- data/test/irb_test.rb +0 -41
- data/test/lambda_test.rb +0 -63
- data/test/load_path_test.rb +0 -75
- data/test/load_test.rb +0 -123
- data/test/main.rb +0 -129
- data/test/nested_test.rb +0 -29
- data/test/readme_test.rb +0 -14
- data/test/recursive_eval_test.rb +0 -51
- data/test/redefine_method_test.rb +0 -83
- data/test/rubygems_test.rb +0 -25
- data/test/rubyspec_test.rb +0 -37
- data/test/singleton_test.rb +0 -25
- data/test/stdlib_test.rb +0 -13
- data/test/thread_test.rb +0 -43
- data/test/to_ast/to_ast_feature_test.rb +0 -11
- data/test/to_ruby/to_ruby_feature_test.rb +0 -11
- data/test/to_ruby/to_ruby_test.rb +0 -99
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c77dc5f539e5e56367987217f1a7389f37806f2da4ec1c3f55fb9b53d03c2172
|
4
|
+
data.tar.gz: 75a943f11e62f41dd4cfcd2984b8d7fd972d180d7e8b551e8f13282d55eba95c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e4a9b8778a9ba187553712fcfb20611df3ed73e6cbf441dea5e2505c3f345d5644acc2a5f8c69977d8ad4fb9fdad6045304b853841f94446d2c99887ab64c40
|
7
|
+
data.tar.gz: c45e2c0739d6c2da44c696779eb61bb69fb47c2f5a9612c949f2cab86ca9378fd4f4e371c3dcebcbd2cdaafdf57cd2461af827048e7db225484c0361178d9b9f
|
data/CHANGES.rdoc
CHANGED
@@ -1,6 +1,26 @@
|
|
1
|
-
|
2
1
|
= live_ast Changes
|
3
2
|
|
3
|
+
== Version 2.1.0
|
4
|
+
|
5
|
+
* Add support for Ruby 3.1
|
6
|
+
* Add `live_ast/replace_caller` similar to `replace_raise`
|
7
|
+
|
8
|
+
== Version 2.0.0
|
9
|
+
|
10
|
+
* Breaking change: Use bindings gem instead of binding_of_caller.
|
11
|
+
If you've been using the full integration mode, you will have to replace
|
12
|
+
binding_of_caller with bindings.
|
13
|
+
* Add support for Ruby 3.0
|
14
|
+
* Drop support for Ruby 2.3, 2.4 and 2.5
|
15
|
+
|
16
|
+
== Version 1.3.2
|
17
|
+
|
18
|
+
* Add support for Ruby 2.6
|
19
|
+
|
20
|
+
== Version 1.3.1
|
21
|
+
|
22
|
+
* Loosen dependency on ruby_parser
|
23
|
+
|
4
24
|
== Version 1.3.0
|
5
25
|
|
6
26
|
* Drop support for Rubies below 2.3
|
data/README.rdoc
CHANGED
@@ -129,8 +129,8 @@ semantics as +eval+ except that the binding argument is required.
|
|
129
129
|
== Full Integration
|
130
130
|
|
131
131
|
In order for LiveAST to be transparent to the user, +eval+ must be
|
132
|
-
replaced. This is accomplished with the help of the +
|
133
|
-
(https://github.com/
|
132
|
+
replaced. This is accomplished with the help of the +bindings+ gem
|
133
|
+
(https://github.com/shreeve/bindings).
|
134
134
|
|
135
135
|
To replace +eval+,
|
136
136
|
|
@@ -149,7 +149,7 @@ below for details).
|
|
149
149
|
# => s(:iter, s(:call, nil, :lambda), 0, s(:str, "dynamic1"))
|
150
150
|
|
151
151
|
Since LiveAST itself is pure ruby, any platforms supported by
|
152
|
-
+
|
152
|
+
+bindings+ should work with <code>live_ast/full</code>.
|
153
153
|
|
154
154
|
== Limitations
|
155
155
|
|
@@ -224,6 +224,20 @@ code. An exception from within a native method will likely still
|
|
224
224
|
contain the token in its backtrace (e.g., in MRI the exception raised
|
225
225
|
by <code>1/0</code> comes from C).
|
226
226
|
|
227
|
+
Similarly to replace_raise, there is a replace_caller for libraries that
|
228
|
+
use the output of Kernel.caller directly to identify files. This has the
|
229
|
+
same caveats as replace_raise.
|
230
|
+
|
231
|
+
require 'live_ast'
|
232
|
+
|
233
|
+
f = ast_eval %{ lambda { caller.first } }, binding
|
234
|
+
f.call
|
235
|
+
=> "(irb)|ast@o:7:in `irb_binding'"
|
236
|
+
|
237
|
+
require 'live_ast/replace_caller'
|
238
|
+
f.call
|
239
|
+
=> "(irb):7:in `block in irb_binding'"
|
240
|
+
|
227
241
|
== Replacing the Parser
|
228
242
|
|
229
243
|
Despite its name, LiveAST knows nothing about ASTs. It merely reports
|
data/lib/live_ast/ast_eval.rb
CHANGED
data/lib/live_ast/ast_load.rb
CHANGED
data/lib/live_ast/base.rb
CHANGED
@@ -1,24 +1,25 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
3
|
+
require "live_ast/common"
|
4
|
+
require "live_ast/reader"
|
5
|
+
require "live_ast/evaler"
|
6
|
+
require "live_ast/linker"
|
7
|
+
require "live_ast/loader"
|
8
|
+
require "live_ast/error"
|
9
|
+
require "live_ast/irb_spy" if defined?(IRB)
|
10
10
|
|
11
11
|
module LiveAST
|
12
|
-
NATIVE_EVAL = Kernel.method(:eval)
|
12
|
+
NATIVE_EVAL = Kernel.method(:eval) # :nodoc:
|
13
13
|
|
14
14
|
class << self
|
15
|
-
attr_writer :parser
|
15
|
+
attr_writer :parser # :nodoc:
|
16
16
|
|
17
|
-
def parser
|
18
|
-
@parser ||=
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
def parser # :nodoc:
|
18
|
+
@parser ||=
|
19
|
+
begin
|
20
|
+
require "live_ast/ruby_parser"
|
21
|
+
LiveAST::RubyParser
|
22
|
+
end
|
22
23
|
end
|
23
24
|
|
24
25
|
#
|
@@ -26,7 +27,7 @@ module LiveAST
|
|
26
27
|
#
|
27
28
|
# Equivalent to <code>obj.to_ast</code>.
|
28
29
|
#
|
29
|
-
def ast(obj)
|
30
|
+
def ast(obj) # :nodoc:
|
30
31
|
case obj
|
31
32
|
when Method, UnboundMethod
|
32
33
|
Linker.find_method_ast(obj.owner, obj.name, *obj.source_location)
|
@@ -50,7 +51,7 @@ module LiveAST
|
|
50
51
|
#
|
51
52
|
# Equivalent to <code>Kernel#ast_eval</code>.
|
52
53
|
#
|
53
|
-
def eval(*args)
|
54
|
+
def eval(*args) # :nodoc:
|
54
55
|
Evaler.eval(args[0], *args)
|
55
56
|
end
|
56
57
|
|
@@ -59,14 +60,14 @@ module LiveAST
|
|
59
60
|
#
|
60
61
|
# Equivalent to <code>Kernel#ast_load</code>.
|
61
62
|
#
|
62
|
-
def load(file, wrap = false)
|
63
|
+
def load(file, wrap = false) # :nodoc:
|
63
64
|
Loader.load(file, wrap)
|
64
65
|
end
|
65
66
|
|
66
67
|
#
|
67
68
|
# strip the revision token from a string
|
68
69
|
#
|
69
|
-
def strip_token(file)
|
70
|
+
def strip_token(file) # :nodoc:
|
70
71
|
file.sub(/#{Regexp.quote Linker::REVISION_TOKEN}[a-z]+/, "")
|
71
72
|
end
|
72
73
|
end
|
data/lib/live_ast/common.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
|
2
3
|
module LiveAST
|
3
4
|
module Common
|
@@ -12,6 +13,15 @@ module LiveAST
|
|
12
13
|
raise TypeError, message
|
13
14
|
end
|
14
15
|
|
16
|
+
def arg_to_str2(arg)
|
17
|
+
arg.to_str
|
18
|
+
rescue NameError
|
19
|
+
thing = arg.nil? ? nil : arg.class
|
20
|
+
|
21
|
+
message = "wrong argument type #{thing.inspect} (expected String)"
|
22
|
+
raise TypeError, message
|
23
|
+
end
|
24
|
+
|
15
25
|
def check_arity(args, range)
|
16
26
|
return if range.include? args.size
|
17
27
|
|
@@ -34,7 +44,7 @@ module LiveAST
|
|
34
44
|
if bind
|
35
45
|
case location.size
|
36
46
|
when 0
|
37
|
-
|
47
|
+
bind.source_location
|
38
48
|
when 1
|
39
49
|
[location.first, 1]
|
40
50
|
else
|
data/lib/live_ast/error.rb
CHANGED
data/lib/live_ast/evaler.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module LiveAST
|
2
4
|
module Evaler
|
3
5
|
class << self
|
@@ -13,9 +15,9 @@ module LiveAST
|
|
13
15
|
|
14
16
|
begin
|
15
17
|
NATIVE_EVAL.call(evaler_source, bind, key, line)
|
16
|
-
rescue Exception =>
|
17
|
-
|
18
|
-
raise
|
18
|
+
rescue Exception => e
|
19
|
+
e.backtrace.map! { |s| LiveAST.strip_token s }
|
20
|
+
raise e
|
19
21
|
end
|
20
22
|
end
|
21
23
|
|
data/lib/live_ast/full.rb
CHANGED
data/lib/live_ast/irb_spy.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
|
2
3
|
module LiveAST
|
3
4
|
@history = nil
|
@@ -7,9 +8,9 @@ module LiveAST
|
|
7
8
|
attr_writer :history
|
8
9
|
|
9
10
|
def code_at(line)
|
10
|
-
code = ""
|
11
|
-
checked_history[line
|
12
|
-
code
|
11
|
+
code = +""
|
12
|
+
checked_history[line..].each do |code_line|
|
13
|
+
code += "#{code_line}\n"
|
13
14
|
return code if can_parse code
|
14
15
|
end
|
15
16
|
end
|
@@ -22,8 +23,9 @@ module LiveAST
|
|
22
23
|
|
23
24
|
def checked_history
|
24
25
|
return @history if @history
|
26
|
+
|
25
27
|
raise NotImplementedError,
|
26
|
-
|
28
|
+
"LiveAST cannot access history for this IRB input method"
|
27
29
|
end
|
28
30
|
end
|
29
31
|
end
|
@@ -31,7 +33,7 @@ end
|
|
31
33
|
|
32
34
|
[
|
33
35
|
defined?(IRB::StdioInputMethod) ? IRB::StdioInputMethod : nil,
|
34
|
-
defined?(IRB::ReadlineInputMethod) ? IRB::ReadlineInputMethod : nil
|
36
|
+
defined?(IRB::ReadlineInputMethod) ? IRB::ReadlineInputMethod : nil
|
35
37
|
].compact.each do |klass|
|
36
38
|
klass.module_eval do
|
37
39
|
alias_method :live_ast_original_gets, :gets
|
data/lib/live_ast/linker.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module LiveAST
|
2
4
|
class Cache
|
3
5
|
def initialize(*args)
|
@@ -39,10 +41,10 @@ module LiveAST
|
|
39
41
|
end
|
40
42
|
|
41
43
|
module Linker
|
42
|
-
REVISION_TOKEN = "|ast@"
|
44
|
+
REVISION_TOKEN = "|ast@"
|
43
45
|
|
44
46
|
@caches = {}
|
45
|
-
@counter = "a"
|
47
|
+
@counter = +"a"
|
46
48
|
@mutex = Mutex.new
|
47
49
|
|
48
50
|
class << self
|
@@ -71,8 +73,10 @@ module LiveAST
|
|
71
73
|
def find_ast(*location)
|
72
74
|
raise ASTNotFoundError unless location.size == 2
|
73
75
|
raise RawEvalError if location.first == "(eval)"
|
76
|
+
|
74
77
|
ast = fetch_from_cache(*location)
|
75
78
|
raise MultipleDefinitionsOnSameLineError if ast == :multiple
|
79
|
+
|
76
80
|
ast
|
77
81
|
end
|
78
82
|
|
data/lib/live_ast/loader.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module LiveAST
|
2
4
|
module Loader
|
3
5
|
class << self
|
@@ -8,7 +10,7 @@ module LiveAST
|
|
8
10
|
header, footer, warnings_ok = header_footer(wrap)
|
9
11
|
|
10
12
|
parser_src = Reader.read(file)
|
11
|
-
evaler_src = header << parser_src << footer
|
13
|
+
evaler_src = +"" << header << parser_src << footer
|
12
14
|
|
13
15
|
run = lambda do
|
14
16
|
Evaler.eval(parser_src, evaler_src, TOPLEVEL_BINDING, file, 1)
|
@@ -19,6 +21,7 @@ module LiveAST
|
|
19
21
|
|
20
22
|
def header_footer(wrap)
|
21
23
|
return "class << Object.new;", ";end", true if wrap
|
24
|
+
|
22
25
|
locals = NATIVE_EVAL.call("local_variables", TOPLEVEL_BINDING)
|
23
26
|
|
24
27
|
params = locals.empty? ? "" : ("|;" + locals.join(",") + "|")
|
@@ -40,14 +43,16 @@ module LiveAST
|
|
40
43
|
if file.index Linker::REVISION_TOKEN
|
41
44
|
raise "refusing to load file with revision token: `#{file}'"
|
42
45
|
end
|
46
|
+
|
43
47
|
search_paths(file) or
|
44
48
|
raise LoadError, "cannot load such file -- #{file}"
|
45
49
|
end
|
46
50
|
|
47
51
|
def search_paths(file)
|
48
52
|
return file if File.file? file
|
53
|
+
|
49
54
|
$LOAD_PATH.each do |path|
|
50
|
-
target = path
|
55
|
+
target = File.join(path, file)
|
51
56
|
return target if File.file? target
|
52
57
|
end
|
53
58
|
nil
|
data/lib/live_ast/reader.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
# encoding: us-ascii
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
module LiveAST
|
4
5
|
module Reader
|
5
|
-
UTF8_BOM = /\A\xef\xbb\xbf
|
6
|
-
MAGIC_COMMENT = /\A(?:#!.*?\n)?\s*\#.*(?:en)?coding\s*[:=]\s*([^\s;]+)
|
6
|
+
UTF8_BOM = /\A\xef\xbb\xbf/.freeze
|
7
|
+
MAGIC_COMMENT = /\A(?:#!.*?\n)?\s*\#.*(?:en)?coding\s*[:=]\s*([^\s;]+)/.freeze
|
7
8
|
|
8
9
|
def self.read(file)
|
9
10
|
contents = File.read(file, encoding: "BINARY")
|
@@ -17,7 +18,7 @@ module LiveAST
|
|
17
18
|
end
|
18
19
|
|
19
20
|
def self.strip_special(encoding)
|
20
|
-
if
|
21
|
+
if /\Autf8-mac\Z/i.match?(encoding)
|
21
22
|
"UTF8-MAC"
|
22
23
|
else
|
23
24
|
encoding.sub(/-(unix|dos|mac)\Z/i, "")
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "live_ast/base"
|
4
|
+
|
5
|
+
module Kernel
|
6
|
+
private
|
7
|
+
|
8
|
+
alias live_ast_original_caller caller
|
9
|
+
def caller(*args)
|
10
|
+
c = live_ast_original_caller(*args)
|
11
|
+
c.shift
|
12
|
+
c.map { |line| LiveAST.strip_token line }
|
13
|
+
end
|
14
|
+
end
|
@@ -1,5 +1,7 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "live_ast/base"
|
4
|
+
require "bindings"
|
3
5
|
|
4
6
|
module LiveAST
|
5
7
|
module ReplaceEval
|
@@ -34,7 +36,7 @@ module LiveAST
|
|
34
36
|
def handle_args(args)
|
35
37
|
LiveAST::Common.check_arity(args, 1..3)
|
36
38
|
args[0] = Common.arg_to_str(args[0])
|
37
|
-
args[1] = Common.
|
39
|
+
args[1] = Common.arg_to_str2(args[1]) if args.length > 1
|
38
40
|
end
|
39
41
|
end
|
40
42
|
end
|
@@ -55,9 +57,8 @@ module Kernel
|
|
55
57
|
LiveAST::Common.check_arity(args, 1..4)
|
56
58
|
LiveAST.eval(
|
57
59
|
args[0],
|
58
|
-
args[1] ||
|
59
|
-
*LiveAST::Common.location_for_eval(*args[1..3])
|
60
|
-
)
|
60
|
+
args[1] || Binding.of_caller(1),
|
61
|
+
*LiveAST::Common.location_for_eval(*args[1..3]))
|
61
62
|
end
|
62
63
|
end
|
63
64
|
|
@@ -66,7 +67,7 @@ class Binding
|
|
66
67
|
alias live_ast_original_binding_eval eval
|
67
68
|
|
68
69
|
def eval(*args)
|
69
|
-
LiveAST.eval(args[0], self, *args[1
|
70
|
+
LiveAST.eval(args[0], self, *args[1..])
|
70
71
|
end
|
71
72
|
end
|
72
73
|
|
@@ -78,11 +79,11 @@ class BasicObject
|
|
78
79
|
if block
|
79
80
|
live_ast_original_instance_eval(*args, &block)
|
80
81
|
else
|
81
|
-
::LiveAST::ReplaceEval
|
82
|
-
module_or_instance_eval(:instance,
|
83
|
-
|
84
|
-
|
85
|
-
|
82
|
+
::LiveAST::ReplaceEval
|
83
|
+
.module_or_instance_eval(:instance,
|
84
|
+
self,
|
85
|
+
::Binding.of_caller(1),
|
86
|
+
args)
|
86
87
|
end
|
87
88
|
end
|
88
89
|
end
|
@@ -95,8 +96,8 @@ class Module
|
|
95
96
|
if block
|
96
97
|
live_ast_original_module_eval(*args, &block)
|
97
98
|
else
|
98
|
-
LiveAST::ReplaceEval
|
99
|
-
module_or_instance_eval(:module, self,
|
99
|
+
LiveAST::ReplaceEval
|
100
|
+
.module_or_instance_eval(:module, self, Binding.of_caller(1), args)
|
100
101
|
end
|
101
102
|
end
|
102
103
|
|
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "live_ast/base"
|
2
4
|
|
3
5
|
module Kernel
|
4
6
|
private
|
@@ -8,8 +10,8 @@ module Kernel
|
|
8
10
|
def raise(*args)
|
9
11
|
ex = begin
|
10
12
|
live_ast_original_raise(*args)
|
11
|
-
rescue Exception =>
|
12
|
-
|
13
|
+
rescue Exception => e
|
14
|
+
e
|
13
15
|
end
|
14
16
|
ex.backtrace.reject! { |line| line.index __FILE__ }
|
15
17
|
ex.backtrace.map! { |line| LiveAST.strip_token line }
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
|
2
3
|
#
|
3
4
|
# Used by the LiveAST test suite.
|
@@ -149,6 +150,18 @@ module LiveAST
|
|
149
150
|
s(:call, s(:lvar, :x), op, s(:lvar, :y)))
|
150
151
|
end
|
151
152
|
|
153
|
+
#
|
154
|
+
# binop_lambda(:+) returns the ast of
|
155
|
+
#
|
156
|
+
# lambda { |x, y| x + y }
|
157
|
+
#
|
158
|
+
def binop_lambda(op)
|
159
|
+
s(:iter,
|
160
|
+
s(:lambda),
|
161
|
+
s(:args, :x, :y),
|
162
|
+
s(:call, s(:lvar, :x), op, s(:lvar, :y)))
|
163
|
+
end
|
164
|
+
|
152
165
|
#
|
153
166
|
# binop_proc_new(:*) returns the ast of
|
154
167
|
#
|
data/lib/live_ast/ruby_parser.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "ruby_parser"
|
4
|
+
require "live_ast/base"
|
3
5
|
|
4
6
|
module LiveAST
|
5
7
|
class RubyParser
|
@@ -31,7 +33,7 @@ module LiveAST
|
|
31
33
|
end
|
32
34
|
end
|
33
35
|
|
34
|
-
LiveAST::RubyParser.autoload :Unparser,
|
35
|
-
LiveAST::RubyParser.autoload :Test,
|
36
|
+
LiveAST::RubyParser.autoload :Unparser, "live_ast/ruby_parser/unparser"
|
37
|
+
LiveAST::RubyParser.autoload :Test, "live_ast/ruby_parser/test"
|
36
38
|
|
37
39
|
LiveAST.parser = LiveAST::RubyParser
|
data/lib/live_ast/to_ast.rb
CHANGED
@@ -1,26 +1,23 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
require "live_ast/base"
|
4
|
+
|
5
|
+
module LiveAST
|
6
|
+
module MethodToAST
|
7
|
+
# Extract the AST of this object.
|
8
|
+
def to_ast
|
6
9
|
LiveAST::Linker.find_method_ast(owner, name, *source_location)
|
7
10
|
end
|
8
11
|
end
|
9
|
-
end
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
module ProcToAST
|
14
|
+
# Extract the AST of this object.
|
15
|
+
def to_ast
|
16
|
+
LiveAST::Linker.find_proc_ast(self)
|
17
|
+
end
|
15
18
|
end
|
16
19
|
end
|
17
20
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
class UnboundMethod
|
24
|
-
# :method: to_ast
|
25
|
-
# Extract the AST of this object.
|
26
|
-
end
|
21
|
+
Method.include LiveAST::MethodToAST
|
22
|
+
UnboundMethod.include LiveAST::MethodToAST
|
23
|
+
Proc.include LiveAST::ProcToAST
|
data/lib/live_ast/to_ruby.rb
CHANGED
@@ -1,24 +1,16 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
require "live_ast/base"
|
4
|
+
|
5
|
+
module LiveAST
|
6
|
+
module CallableToRuby
|
7
|
+
# Generate ruby code which reflects the AST of this object.
|
8
|
+
def to_ruby
|
6
9
|
LiveAST.parser::Unparser.unparse(LiveAST.ast(self))
|
7
10
|
end
|
8
11
|
end
|
9
12
|
end
|
10
13
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
class UnboundMethod
|
17
|
-
# :method: to_ruby
|
18
|
-
# Generate ruby code which reflects the AST of this object.
|
19
|
-
end
|
20
|
-
|
21
|
-
class Proc
|
22
|
-
# :method: to_ruby
|
23
|
-
# Generate ruby code which reflects the AST of this object.
|
24
|
-
end
|
14
|
+
Method.include LiveAST::CallableToRuby
|
15
|
+
UnboundMethod.include LiveAST::CallableToRuby
|
16
|
+
Proc.include LiveAST::CallableToRuby
|
data/lib/live_ast/version.rb
CHANGED
data/lib/live_ast.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "live_ast/base"
|
4
|
+
require "live_ast/to_ast"
|
5
|
+
require "live_ast/ast_eval"
|
6
|
+
require "live_ast/replace_load"
|