ruby-next 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -1
- data/README.md +11 -7
- metadata +3 -48
- data/bin/parse +0 -19
- data/bin/ruby-next +0 -16
- data/bin/transform +0 -21
- data/lib/ruby-next.rb +0 -37
- data/lib/ruby-next/cli.rb +0 -94
- data/lib/ruby-next/commands/base.rb +0 -42
- data/lib/ruby-next/commands/core_ext.rb +0 -166
- data/lib/ruby-next/commands/nextify.rb +0 -133
- data/lib/ruby-next/core.rb +0 -182
- data/lib/ruby-next/core/array/deconstruct.rb +0 -21
- data/lib/ruby-next/core/array/difference_union_intersection.rb +0 -25
- data/lib/ruby-next/core/constants/no_matching_pattern_error.rb +0 -17
- data/lib/ruby-next/core/enumerable/filter.rb +0 -25
- data/lib/ruby-next/core/enumerable/filter_map.rb +0 -38
- data/lib/ruby-next/core/enumerable/tally.rb +0 -14
- data/lib/ruby-next/core/enumerator/produce.rb +0 -20
- data/lib/ruby-next/core/hash/deconstruct_keys.rb +0 -21
- data/lib/ruby-next/core/hash/merge.rb +0 -14
- data/lib/ruby-next/core/kernel/then.rb +0 -10
- data/lib/ruby-next/core/proc/compose.rb +0 -19
- data/lib/ruby-next/core/runtime.rb +0 -10
- data/lib/ruby-next/core/string/split.rb +0 -11
- data/lib/ruby-next/core/struct/deconstruct.rb +0 -7
- data/lib/ruby-next/core/struct/deconstruct_keys.rb +0 -34
- data/lib/ruby-next/core/time/ceil.rb +0 -10
- data/lib/ruby-next/core/time/floor.rb +0 -9
- data/lib/ruby-next/core/unboundmethod/bind_call.rb +0 -9
- data/lib/ruby-next/core_ext.rb +0 -18
- data/lib/ruby-next/language.rb +0 -119
- data/lib/ruby-next/language/bootsnap.rb +0 -26
- data/lib/ruby-next/language/eval.rb +0 -64
- data/lib/ruby-next/language/parser.rb +0 -28
- data/lib/ruby-next/language/rewriters/args_forward.rb +0 -57
- data/lib/ruby-next/language/rewriters/base.rb +0 -105
- data/lib/ruby-next/language/rewriters/endless_range.rb +0 -60
- data/lib/ruby-next/language/rewriters/method_reference.rb +0 -33
- data/lib/ruby-next/language/rewriters/numbered_params.rb +0 -41
- data/lib/ruby-next/language/rewriters/pattern_matching.rb +0 -541
- data/lib/ruby-next/language/runtime.rb +0 -95
- data/lib/ruby-next/language/setup.rb +0 -43
- data/lib/ruby-next/language/unparser.rb +0 -8
- data/lib/ruby-next/utils.rb +0 -36
- data/lib/ruby-next/version.rb +0 -5
- data/lib/uby-next.rb +0 -68
@@ -1,95 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "pathname"
|
4
|
-
|
5
|
-
require "ruby-next"
|
6
|
-
require "ruby-next/utils"
|
7
|
-
require "ruby-next/language"
|
8
|
-
require "ruby-next/language/eval"
|
9
|
-
|
10
|
-
module RubyNext
|
11
|
-
module Language
|
12
|
-
# Module responsible for runtime transformations
|
13
|
-
module Runtime
|
14
|
-
using RubyNext
|
15
|
-
|
16
|
-
class << self
|
17
|
-
include Utils
|
18
|
-
|
19
|
-
def load(path, wrap: false)
|
20
|
-
raise "RubyNext cannot handle `load(smth, wrap: true)`" if wrap
|
21
|
-
|
22
|
-
contents = File.read(path)
|
23
|
-
new_contents = transform contents
|
24
|
-
|
25
|
-
$stdout.puts source_with_lines(new_contents, path) if ENV["RUBY_NEXT_DEBUG"] == "1"
|
26
|
-
|
27
|
-
TOPLEVEL_BINDING.eval(new_contents, path)
|
28
|
-
true
|
29
|
-
end
|
30
|
-
|
31
|
-
def transform(contents, **options)
|
32
|
-
Language.transform(contents, rewriters: Language.current_rewriters, **options)
|
33
|
-
end
|
34
|
-
|
35
|
-
def feature_path(path)
|
36
|
-
path = resolve_feature_path(path)
|
37
|
-
return if path.nil?
|
38
|
-
return if File.extname(path) != ".rb"
|
39
|
-
return unless Language.transformable?(path)
|
40
|
-
path
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
# Patch Kernel to hijack require/require_relative/load/eval
|
48
|
-
module Kernel
|
49
|
-
module_function # rubocop:disable Style/ModuleFunction
|
50
|
-
|
51
|
-
alias_method :require_without_ruby_next, :require
|
52
|
-
def require(path)
|
53
|
-
realpath = RubyNext::Language::Runtime.feature_path(path)
|
54
|
-
return require_without_ruby_next(path) unless realpath
|
55
|
-
|
56
|
-
return false if $LOADED_FEATURES.include?(realpath)
|
57
|
-
|
58
|
-
$LOADED_FEATURES << realpath
|
59
|
-
|
60
|
-
RubyNext::Language::Runtime.load(realpath)
|
61
|
-
|
62
|
-
true
|
63
|
-
rescue => e
|
64
|
-
$LOADED_FEATURES.delete realpath
|
65
|
-
warn "RubyNext failed to require '#{path}': #{e.message}"
|
66
|
-
require_without_ruby_next(path)
|
67
|
-
end
|
68
|
-
|
69
|
-
alias_method :require_relative_without_ruby_next, :require_relative
|
70
|
-
def require_relative(path)
|
71
|
-
from = caller_locations(1..1).first.absolute_path || File.join(Dir.pwd, "main")
|
72
|
-
realpath = File.absolute_path(
|
73
|
-
File.join(
|
74
|
-
File.dirname(File.absolute_path(from)),
|
75
|
-
path
|
76
|
-
)
|
77
|
-
)
|
78
|
-
require(realpath)
|
79
|
-
rescue => e
|
80
|
-
warn "RubyNext failed to require relative '#{path}' from #{from}: #{e.message}"
|
81
|
-
require_relative_without_ruby_next(path)
|
82
|
-
end
|
83
|
-
|
84
|
-
alias_method :load_without_ruby_next, :load
|
85
|
-
def load(path, wrap = false)
|
86
|
-
realpath = RubyNext::Language::Runtime.feature_path(path)
|
87
|
-
|
88
|
-
return load_without_ruby_next(path, wrap) unless realpath
|
89
|
-
|
90
|
-
RubyNext::Language::Runtime.load(realpath, wrap: wrap)
|
91
|
-
rescue => e
|
92
|
-
warn "RubyNext failed to load '#{path}': #{e.message}"
|
93
|
-
load_without_ruby_next(path)
|
94
|
-
end
|
95
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Make sure Core is loaded
|
4
|
-
require "ruby-next"
|
5
|
-
|
6
|
-
module RubyNext
|
7
|
-
module Language
|
8
|
-
class << self
|
9
|
-
def setup_gem_load_path(lib_dir = "lib", rbnext_dir: RUBY_NEXT_DIR)
|
10
|
-
called_from = caller_locations(1, 1).first.path
|
11
|
-
dirname = File.dirname(called_from)
|
12
|
-
|
13
|
-
loop do
|
14
|
-
basename = File.basename(dirname)
|
15
|
-
raise "Couldn't find gem's load dir: #{lib_dir}" if basename == dirname
|
16
|
-
|
17
|
-
break if basename == lib_dir
|
18
|
-
|
19
|
-
dirname = File.dirname(basename)
|
20
|
-
end
|
21
|
-
|
22
|
-
current_index = $LOAD_PATH.index(dirname)
|
23
|
-
|
24
|
-
raise "Gem's lib is not in the $LOAD_PATH: #{dirname}" if current_index.nil?
|
25
|
-
|
26
|
-
version = RubyNext.next_version
|
27
|
-
|
28
|
-
loop do
|
29
|
-
break unless version
|
30
|
-
|
31
|
-
version_dir = File.join(dirname, rbnext_dir, version.segments[0..1].join("."))
|
32
|
-
|
33
|
-
if File.exist?(version_dir)
|
34
|
-
$LOAD_PATH.insert current_index, version_dir
|
35
|
-
current_index += 1
|
36
|
-
end
|
37
|
-
|
38
|
-
version = RubyNext.next_version(version)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
data/lib/ruby-next/utils.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RubyNext
|
4
|
-
module Utils
|
5
|
-
module_function
|
6
|
-
|
7
|
-
if $LOAD_PATH.respond_to?(:resolve_feature_path)
|
8
|
-
def resolve_feature_path(feature)
|
9
|
-
$LOAD_PATH.resolve_feature_path(feature)&.last
|
10
|
-
end
|
11
|
-
else
|
12
|
-
def resolve_feature_path(path)
|
13
|
-
if File.file?(relative = File.expand_path(path))
|
14
|
-
path = relative
|
15
|
-
end
|
16
|
-
|
17
|
-
path = "#{path}.rb" if File.extname(path).empty?
|
18
|
-
|
19
|
-
return path if Pathname.new(path).absolute?
|
20
|
-
|
21
|
-
$LOAD_PATH.find do |lp|
|
22
|
-
lpath = File.join(lp, path)
|
23
|
-
return lpath if File.file?(lpath)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def source_with_lines(source, path)
|
29
|
-
source.lines.map.with_index do |line, i|
|
30
|
-
"#{(i + 1).to_s.rjust(4)}: #{line}"
|
31
|
-
end.tap do |lines|
|
32
|
-
lines.unshift " 0: # source: #{path}"
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
data/lib/ruby-next/version.rb
DELETED
data/lib/uby-next.rb
DELETED
@@ -1,68 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "ruby-next/language/runtime"
|
4
|
-
require "ruby-next/core/runtime"
|
5
|
-
|
6
|
-
using RubyNext
|
7
|
-
|
8
|
-
RubyNext::Language.watch_dirs << Dir.pwd
|
9
|
-
|
10
|
-
require "stringio"
|
11
|
-
|
12
|
-
# Hijack stderr to avoid printing exceptions while executing ruby files
|
13
|
-
stderr = StringIO.new
|
14
|
-
|
15
|
-
orig_stderr, $stderr = $stderr, stderr
|
16
|
-
|
17
|
-
# Capture source code passed via `-e` option
|
18
|
-
e_script = nil
|
19
|
-
|
20
|
-
if $0 == "-e"
|
21
|
-
begin
|
22
|
-
TracePoint.new(:script_compiled) do |tp|
|
23
|
-
next unless tp.path == "-e"
|
24
|
-
e_script = tp.eval_script
|
25
|
-
tp.disable
|
26
|
-
end.enable
|
27
|
-
rescue ArgumentError
|
28
|
-
# script_compiled event is not supported
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
at_exit do
|
33
|
-
$stderr = orig_stderr
|
34
|
-
|
35
|
-
if NoMethodError === $! || SyntaxError === $!
|
36
|
-
if $0 && File.exist?($0)
|
37
|
-
load($0)
|
38
|
-
exit!(0)
|
39
|
-
end
|
40
|
-
|
41
|
-
if $0 == "-e" && e_script.nil?
|
42
|
-
`ps axw`.split("\n").find { |ps| ps[/\A\s*#{$$}/] }.then do |command|
|
43
|
-
next unless command
|
44
|
-
command.tr! '\012', "\n"
|
45
|
-
command.tr! "\\", "\n"
|
46
|
-
command.match(/\-e(.*)/m)
|
47
|
-
end.then do |matches|
|
48
|
-
next unless matches
|
49
|
-
|
50
|
-
args = ["-e", matches[1]]
|
51
|
-
require "optparse"
|
52
|
-
OptionParser.new do |o|
|
53
|
-
o.on("-e SOURCE") do |v|
|
54
|
-
e_script = v
|
55
|
-
end
|
56
|
-
end.parse!(args)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
if e_script
|
61
|
-
new_e_script = RubyNext::Language::Runtime.transform(e_script)
|
62
|
-
TOPLEVEL_BINDING.eval(new_e_script, $0)
|
63
|
-
exit!(0)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
puts(stderr.tap(&:rewind).read)
|
68
|
-
end
|