mvz-live_ast 1.3.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.rdoc +8 -1
  3. data/README.rdoc +3 -3
  4. data/Rakefile +20 -20
  5. data/lib/live_ast.rb +4 -4
  6. data/lib/live_ast/ast_eval.rb +1 -1
  7. data/lib/live_ast/ast_load.rb +1 -1
  8. data/lib/live_ast/base.rb +13 -12
  9. data/lib/live_ast/common.rb +2 -10
  10. data/lib/live_ast/evaler.rb +3 -3
  11. data/lib/live_ast/full.rb +2 -2
  12. data/lib/live_ast/irb_spy.rb +4 -4
  13. data/lib/live_ast/loader.rb +2 -2
  14. data/lib/live_ast/reader.rb +1 -1
  15. data/lib/live_ast/replace_eval.rb +12 -13
  16. data/lib/live_ast/replace_load.rb +1 -1
  17. data/lib/live_ast/replace_raise.rb +3 -3
  18. data/lib/live_ast/ruby_parser.rb +4 -4
  19. data/lib/live_ast/ruby_parser/test.rb +12 -0
  20. data/lib/live_ast/ruby_parser/unparser.rb +1 -1
  21. data/lib/live_ast/to_ast.rb +13 -18
  22. data/lib/live_ast/to_ruby.rb +8 -18
  23. data/lib/live_ast/version.rb +1 -1
  24. data/test/alias_test.rb +1 -1
  25. data/test/ast_eval/ast_eval_test.rb +2 -2
  26. data/test/ast_load/ast_load_test.rb +2 -2
  27. data/test/attr_test.rb +1 -1
  28. data/test/backtrace_test.rb +4 -4
  29. data/test/base/noninvasive_test.rb +1 -1
  30. data/test/base/reload_test.rb +1 -1
  31. data/test/covert_define_method_test.rb +1 -1
  32. data/test/def_test.rb +1 -1
  33. data/test/define_method_test.rb +2 -2
  34. data/test/define_singleton_method_test.rb +1 -1
  35. data/test/encoding_test.rb +1 -1
  36. data/test/error_test.rb +3 -3
  37. data/test/eval_test.rb +1 -1
  38. data/test/flush_cache_test.rb +3 -1
  39. data/test/full/ast_reload_test.rb +1 -1
  40. data/test/full/replace_eval_test.rb +8 -8
  41. data/test/irb_test.rb +2 -2
  42. data/test/lambda_test.rb +2 -2
  43. data/test/load_path_test.rb +2 -2
  44. data/test/load_test.rb +3 -3
  45. data/test/main.rb +18 -18
  46. data/test/nested_test.rb +1 -1
  47. data/test/readme_test.rb +3 -3
  48. data/test/recursive_eval_test.rb +1 -1
  49. data/test/redefine_method_test.rb +1 -1
  50. data/test/rubygems_test.rb +4 -4
  51. data/test/rubyspec_test.rb +8 -8
  52. data/test/singleton_test.rb +1 -1
  53. data/test/stdlib_test.rb +1 -1
  54. data/test/thread_test.rb +2 -2
  55. data/test/to_ast/to_ast_feature_test.rb +2 -2
  56. data/test/to_ruby/to_ruby_feature_test.rb +2 -2
  57. data/test/to_ruby/to_ruby_test.rb +15 -15
  58. metadata +74 -60
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 14243cf3ff6a019d43ede0de0ff3ef18e66a7b3dd67b90b4ff9962c94f67d050
4
- data.tar.gz: 428709d2937e21ffec0dca92b93af53717275d1817709796628db2f3d11ff9b4
3
+ metadata.gz: e96ab3dab36ef2a9b745f3a878b71b79bb8b8ecfd870b0c8ad29dcef5520a943
4
+ data.tar.gz: b8b7f606c175caff1522b70db8287392160d8352e44f57fca8e6709011599bd5
5
5
  SHA512:
6
- metadata.gz: 5e4534a5bee591b83ff08f21d8b80e906838bf1934698da9652024918d85d9f415fe492291eca81f164165f61900d96155e8b3e0ac1c70c8859de6751e46122e
7
- data.tar.gz: d787544a791a87615fb1754a67481743c3c7f85cb71b5a747895056c4d2b5b398708c66d8fe2031251a0c17aa9533f6352d5684743c09f3c7328de63ff30a37e
6
+ metadata.gz: ac889c697aa0c722078437135a3c57db7b05126178920e1224e4728616ab38cabbcb682d6eae3194a9361f2032400a6b55d2e89726f95abe006fa33d9e8c6ef9
7
+ data.tar.gz: ecc774511be6e4bb0d89559c8e6186ec766aa30ad31376f6e310ef5e9d0e116f603b648ce1a8f8a722116daadc1150913bdcbb977ed653c2784b0e84525c59c7
@@ -1,6 +1,13 @@
1
-
2
1
  = live_ast Changes
3
2
 
3
+ == Version 2.0.0
4
+
5
+ * Breaking change: Use bindings gem instead of binding_of_caller.
6
+ If you've been using the full integration mode, you will have to replace
7
+ binding_of_caller with bindings.
8
+ * Add support for Ruby 3.0
9
+ * Drop support for Ruby 2.3, 2.4 and 2.5
10
+
4
11
  == Version 1.3.2
5
12
 
6
13
  * Add support for Ruby 2.6
@@ -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 +binding_of_caller+ gem
133
- (https://github.com/banister/binding_of_caller).
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
- +binding_of_caller+ should work with <code>live_ast/full</code>.
152
+ +bindings+ should work with <code>live_ast/full</code>.
153
153
 
154
154
  == Limitations
155
155
 
data/Rakefile CHANGED
@@ -1,52 +1,52 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rake/clean'
4
- require 'bundler/gem_tasks'
5
- require 'rake/testtask'
6
- require 'rdoc/task'
3
+ require "rake/clean"
4
+ require "bundler/gem_tasks"
5
+ require "rake/testtask"
6
+ require "rdoc/task"
7
7
 
8
8
  namespace :test do
9
- desc 'run tests'
9
+ desc "run tests"
10
10
  Rake::TestTask.new(:main) do |t|
11
- t.libs = ['lib']
11
+ t.libs = ["lib"]
12
12
  t.ruby_opts += ["-w -Itest"]
13
- t.test_files = FileList['test/*_test.rb']
13
+ t.test_files = FileList["test/*_test.rb"]
14
14
  end
15
15
 
16
16
  Rake::TestTask.new(:base) do |t|
17
- t.libs = ['lib']
17
+ t.libs = ["lib"]
18
18
  t.ruby_opts += ["-w -Itest"]
19
- t.test_files = FileList['test/base/*_test.rb']
19
+ t.test_files = FileList["test/base/*_test.rb"]
20
20
  end
21
21
 
22
22
  Rake::TestTask.new(:ast_load) do |t|
23
- t.libs = ['lib']
23
+ t.libs = ["lib"]
24
24
  t.ruby_opts += ["-w -Itest"]
25
- t.test_files = FileList['test/ast_load/*_test.rb']
25
+ t.test_files = FileList["test/ast_load/*_test.rb"]
26
26
  end
27
27
 
28
28
  Rake::TestTask.new(:ast_eval) do |t|
29
- t.libs = ['lib']
29
+ t.libs = ["lib"]
30
30
  t.ruby_opts += ["-w -Itest"]
31
- t.test_files = FileList['test/ast_eval/*_test.rb']
31
+ t.test_files = FileList["test/ast_eval/*_test.rb"]
32
32
  end
33
33
 
34
34
  Rake::TestTask.new(:to_ast) do |t|
35
- t.libs = ['lib']
35
+ t.libs = ["lib"]
36
36
  t.ruby_opts += ["-w -Itest"]
37
- t.test_files = FileList['test/to_ast/*_test.rb']
37
+ t.test_files = FileList["test/to_ast/*_test.rb"]
38
38
  end
39
39
 
40
40
  Rake::TestTask.new(:to_ruby) do |t|
41
- t.libs = ['lib']
41
+ t.libs = ["lib"]
42
42
  t.ruby_opts += ["-w -Itest"]
43
- t.test_files = FileList['test/to_ruby/*_test.rb']
43
+ t.test_files = FileList["test/to_ruby/*_test.rb"]
44
44
  end
45
45
 
46
46
  Rake::TestTask.new(:full) do |t|
47
- t.libs = ['lib']
47
+ t.libs = ["lib"]
48
48
  t.ruby_opts += ["-w -Itest"]
49
- t.test_files = FileList['test/full/*_test.rb']
49
+ t.test_files = FileList["test/full/*_test.rb"]
50
50
  end
51
51
 
52
52
  task all: [:main, :base, :ast_load, :to_ast, :to_ruby, :full]
@@ -59,4 +59,4 @@ RDoc::Task.new(:rdoc) do |t|
59
59
  t.rdoc_files.include("README.rdoc", "CHANGES.rdoc", "lib")
60
60
  end
61
61
 
62
- task default: 'test:all'
62
+ task default: "test:all"
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'live_ast/base'
4
- require 'live_ast/to_ast'
5
- require 'live_ast/ast_eval'
6
- require 'live_ast/replace_load'
3
+ require "live_ast/base"
4
+ require "live_ast/to_ast"
5
+ require "live_ast/ast_eval"
6
+ require "live_ast/replace_load"
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'live_ast/base'
3
+ require "live_ast/base"
4
4
 
5
5
  module Kernel
6
6
  private
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'live_ast/base'
3
+ require "live_ast/base"
4
4
 
5
5
  module Kernel
6
6
  private
@@ -1,14 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'thread'
3
+ require "thread"
4
4
 
5
- require 'live_ast/common'
6
- require 'live_ast/reader'
7
- require 'live_ast/evaler'
8
- require 'live_ast/linker'
9
- require 'live_ast/loader'
10
- require 'live_ast/error'
11
- require 'live_ast/irb_spy' if defined?(IRB)
5
+ require "live_ast/common"
6
+ require "live_ast/reader"
7
+ require "live_ast/evaler"
8
+ require "live_ast/linker"
9
+ require "live_ast/loader"
10
+ require "live_ast/error"
11
+ require "live_ast/irb_spy" if defined?(IRB)
12
12
 
13
13
  module LiveAST
14
14
  NATIVE_EVAL = Kernel.method(:eval) #:nodoc:
@@ -17,10 +17,11 @@ module LiveAST
17
17
  attr_writer :parser #:nodoc:
18
18
 
19
19
  def parser #:nodoc:
20
- @parser ||= begin
21
- require 'live_ast/ruby_parser'
22
- LiveAST::RubyParser
23
- end
20
+ @parser ||=
21
+ begin
22
+ require "live_ast/ruby_parser"
23
+ LiveAST::RubyParser
24
+ end
24
25
  end
25
26
 
26
27
  #
@@ -18,11 +18,7 @@ module LiveAST
18
18
  rescue NameError
19
19
  thing = arg.nil? ? nil : arg.class
20
20
 
21
- message = if RUBY_VERSION >= "2.6.0"
22
- "wrong argument type #{thing.inspect} (expected String)"
23
- else
24
- "no implicit conversion of #{thing.inspect} into String"
25
- end
21
+ message = "wrong argument type #{thing.inspect} (expected String)"
26
22
  raise TypeError, message
27
23
  end
28
24
 
@@ -48,11 +44,7 @@ module LiveAST
48
44
  if bind
49
45
  case location.size
50
46
  when 0
51
- if RUBY_VERSION < "2.6.0"
52
- NATIVE_EVAL.call("[__FILE__, __LINE__]", bind)
53
- else
54
- bind.source_location
55
- end
47
+ bind.source_location
56
48
  when 1
57
49
  [location.first, 1]
58
50
  else
@@ -15,9 +15,9 @@ module LiveAST
15
15
 
16
16
  begin
17
17
  NATIVE_EVAL.call(evaler_source, bind, key, line)
18
- rescue Exception => ex
19
- ex.backtrace.map! { |s| LiveAST.strip_token s }
20
- raise ex
18
+ rescue Exception => e
19
+ e.backtrace.map! { |s| LiveAST.strip_token s }
20
+ raise e
21
21
  end
22
22
  end
23
23
 
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'live_ast'
4
- require 'live_ast/replace_eval'
3
+ require "live_ast"
4
+ require "live_ast/replace_eval"
@@ -8,8 +8,8 @@ module LiveAST
8
8
  attr_writer :history
9
9
 
10
10
  def code_at(line)
11
- code = +''
12
- checked_history[line..-1].each do |code_line|
11
+ code = +""
12
+ checked_history[line..].each do |code_line|
13
13
  code << code_line << "\n"
14
14
  return code if can_parse code
15
15
  end
@@ -25,7 +25,7 @@ module LiveAST
25
25
  return @history if @history
26
26
 
27
27
  raise NotImplementedError,
28
- "LiveAST cannot access history for this IRB input method"
28
+ "LiveAST cannot access history for this IRB input method"
29
29
  end
30
30
  end
31
31
  end
@@ -33,7 +33,7 @@ end
33
33
 
34
34
  [
35
35
  defined?(IRB::StdioInputMethod) ? IRB::StdioInputMethod : nil,
36
- defined?(IRB::ReadlineInputMethod) ? IRB::ReadlineInputMethod : nil,
36
+ defined?(IRB::ReadlineInputMethod) ? IRB::ReadlineInputMethod : nil
37
37
  ].compact.each do |klass|
38
38
  klass.module_eval do
39
39
  alias_method :live_ast_original_gets, :gets
@@ -10,7 +10,7 @@ module LiveAST
10
10
  header, footer, warnings_ok = header_footer(wrap)
11
11
 
12
12
  parser_src = Reader.read(file)
13
- evaler_src = +'' << header << parser_src << footer
13
+ evaler_src = +"" << header << parser_src << footer
14
14
 
15
15
  run = lambda do
16
16
  Evaler.eval(parser_src, evaler_src, TOPLEVEL_BINDING, file, 1)
@@ -52,7 +52,7 @@ module LiveAST
52
52
  return file if File.file? file
53
53
 
54
54
  $LOAD_PATH.each do |path|
55
- target = path + "/" + file
55
+ target = File.join(path, file)
56
56
  return target if File.file? target
57
57
  end
58
58
  nil
@@ -18,7 +18,7 @@ module LiveAST
18
18
  end
19
19
 
20
20
  def self.strip_special(encoding)
21
- if encoding =~ /\Autf8-mac\Z/i
21
+ if /\Autf8-mac\Z/i.match?(encoding)
22
22
  "UTF8-MAC"
23
23
  else
24
24
  encoding.sub(/-(unix|dos|mac)\Z/i, "")
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'live_ast/base'
4
- require 'binding_of_caller'
3
+ require "live_ast/base"
4
+ require "bindings"
5
5
 
6
6
  module LiveAST
7
7
  module ReplaceEval
@@ -57,9 +57,8 @@ module Kernel
57
57
  LiveAST::Common.check_arity(args, 1..4)
58
58
  LiveAST.eval(
59
59
  args[0],
60
- args[1] || binding.of_caller(1),
61
- *LiveAST::Common.location_for_eval(*args[1..3])
62
- )
60
+ args[1] || Binding.of_caller(1),
61
+ *LiveAST::Common.location_for_eval(*args[1..3]))
63
62
  end
64
63
  end
65
64
 
@@ -68,7 +67,7 @@ class Binding
68
67
  alias live_ast_original_binding_eval eval
69
68
 
70
69
  def eval(*args)
71
- LiveAST.eval(args[0], self, *args[1..-1])
70
+ LiveAST.eval(args[0], self, *args[1..])
72
71
  end
73
72
  end
74
73
 
@@ -80,11 +79,11 @@ class BasicObject
80
79
  if block
81
80
  live_ast_original_instance_eval(*args, &block)
82
81
  else
83
- ::LiveAST::ReplaceEval.
84
- module_or_instance_eval(:instance,
85
- self,
86
- ::Kernel.binding.of_caller(1),
87
- args)
82
+ ::LiveAST::ReplaceEval
83
+ .module_or_instance_eval(:instance,
84
+ self,
85
+ ::Binding.of_caller(1),
86
+ args)
88
87
  end
89
88
  end
90
89
  end
@@ -97,8 +96,8 @@ class Module
97
96
  if block
98
97
  live_ast_original_module_eval(*args, &block)
99
98
  else
100
- LiveAST::ReplaceEval.
101
- module_or_instance_eval(:module, self, binding.of_caller(1), args)
99
+ LiveAST::ReplaceEval
100
+ .module_or_instance_eval(:module, self, Binding.of_caller(1), args)
102
101
  end
103
102
  end
104
103
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'live_ast/base'
3
+ require "live_ast/base"
4
4
 
5
5
  module Kernel
6
6
  alias live_ast_original_load load
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'live_ast/base'
3
+ require "live_ast/base"
4
4
 
5
5
  module Kernel
6
6
  private
@@ -10,8 +10,8 @@ module Kernel
10
10
  def raise(*args)
11
11
  ex = begin
12
12
  live_ast_original_raise(*args)
13
- rescue Exception => t
14
- t
13
+ rescue Exception => e
14
+ e
15
15
  end
16
16
  ex.backtrace.reject! { |line| line.index __FILE__ }
17
17
  ex.backtrace.map! { |line| LiveAST.strip_token line }
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'ruby_parser'
4
- require 'live_ast/base'
3
+ require "ruby_parser"
4
+ require "live_ast/base"
5
5
 
6
6
  module LiveAST
7
7
  class RubyParser
@@ -33,7 +33,7 @@ module LiveAST
33
33
  end
34
34
  end
35
35
 
36
- LiveAST::RubyParser.autoload :Unparser, 'live_ast/ruby_parser/unparser'
37
- LiveAST::RubyParser.autoload :Test, 'live_ast/ruby_parser/test'
36
+ LiveAST::RubyParser.autoload :Unparser, "live_ast/ruby_parser/unparser"
37
+ LiveAST::RubyParser.autoload :Test, "live_ast/ruby_parser/test"
38
38
 
39
39
  LiveAST.parser = LiveAST::RubyParser
@@ -150,6 +150,18 @@ module LiveAST
150
150
  s(:call, s(:lvar, :x), op, s(:lvar, :y)))
151
151
  end
152
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
+
153
165
  #
154
166
  # binop_proc_new(:*) returns the ast of
155
167
  #
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'ruby2ruby'
3
+ require "ruby2ruby"
4
4
 
5
5
  #
6
6
  # Used by +to_ruby+ in LiveAST.
@@ -1,28 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'live_ast/base'
3
+ require "live_ast/base"
4
4
 
5
- [Method, UnboundMethod].each do |klass|
6
- klass.class_eval do
7
- def to_ast #:nodoc:
5
+ module LiveAST
6
+ module MethodToAST
7
+ # Extract the AST of this object.
8
+ def to_ast
8
9
  LiveAST::Linker.find_method_ast(owner, name, *source_location)
9
10
  end
10
11
  end
11
- end
12
12
 
13
- class Proc
14
- # Extract the AST of this object.
15
- def to_ast
16
- LiveAST::Linker.find_proc_ast(self)
13
+ module ProcToAST
14
+ # Extract the AST of this object.
15
+ def to_ast
16
+ LiveAST::Linker.find_proc_ast(self)
17
+ end
17
18
  end
18
19
  end
19
20
 
20
- class Method
21
- # :method: to_ast
22
- # Extract the AST of this object.
23
- end
24
-
25
- class UnboundMethod
26
- # :method: to_ast
27
- # Extract the AST of this object.
28
- end
21
+ Method.include LiveAST::MethodToAST
22
+ UnboundMethod.include LiveAST::MethodToAST
23
+ Proc.include LiveAST::ProcToAST