ruby-next-core 0.9.1 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +6 -2
- data/lib/ruby-next/commands/nextify.rb +41 -10
- data/lib/ruby-next/language.rb +19 -6
- data/lib/ruby-next/language/parser.rb +3 -0
- data/lib/ruby-next/language/rewriters/args_forward.rb +1 -0
- data/lib/ruby-next/language/rewriters/endless_method.rb +1 -0
- data/lib/ruby-next/language/rewriters/endless_range.rb +1 -0
- data/lib/ruby-next/language/rewriters/method_reference.rb +1 -0
- data/lib/ruby-next/language/rewriters/numbered_params.rb +1 -0
- data/lib/ruby-next/language/rewriters/pattern_matching.rb +1 -0
- data/lib/ruby-next/language/rewriters/right_hand_assignment.rb +1 -0
- data/lib/ruby-next/language/unparser.rb +14 -0
- data/lib/ruby-next/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 31bef7eea12c9a2c8b04f3daa62816e96b764bcbaf7cfc0f01d4bf1b040f34b9
|
4
|
+
data.tar.gz: 793834fef3c0a00944b7026a975f7ee4b97219ae42b2b3ebfb5327d4a3e5311c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 690f42ac5954bbe4b2c6a0e4ee0a05f4842c87a4ade5bccb3f7be90d76b92df89e715a07c785f5286bb4137ac3357fe4341e90b41f010db8716fab5a9bdcfb83
|
7
|
+
data.tar.gz: 48bd02bbd66656cd9892cad1c8fe767c205bfba5eb47c59cfacdf3060af3c7cf886fbba6396283f3e19eb1da66cd53e9b6a5125595ec694cd8c37ad6ecb4e0f1
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,13 @@
|
|
2
2
|
|
3
3
|
## master
|
4
4
|
|
5
|
+
## 0.9.2 (2020-06-24)
|
6
|
+
|
7
|
+
- Support passing rewriters to CLI. ([@sl4vr][])
|
8
|
+
|
9
|
+
Use `nextify --list-rewriters` to view all available rewriters.
|
10
|
+
Use `nextify` with `--rewrite=REWRITERS...` option to specify which particular rewriters to use.
|
11
|
+
|
5
12
|
## 0.9.1 (2020-06-05)
|
6
13
|
|
7
14
|
- Keep `ruby-next` version in sync with `ruby-next-core`. ([@palkan][])
|
@@ -195,3 +202,4 @@ p a #=> 1
|
|
195
202
|
|
196
203
|
[@palkan]: https://github.com/palkan
|
197
204
|
[backports]: https://github.com/marcandre/backports
|
205
|
+
[@sl4vr]: https://github.com/sl4vr
|
data/README.md
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
[![Cult Of Martians](http://cultofmartians.com/assets/badges/badge.svg)](https://cultofmartians.com/tasks/ruby-next-cli-rewriters.html#task)
|
1
2
|
[![Gem Version](https://badge.fury.io/rb/ruby-next.svg)](https://rubygems.org/gems/ruby-next) [![Build](https://github.com/ruby-next/ruby-next/workflows/Build/badge.svg)](https://github.com/ruby-next/ruby-next/actions)
|
2
3
|
[![JRuby Build](https://github.com/ruby-next/ruby-next/workflows/JRuby%20Build/badge.svg)](https://github.com/ruby-next/ruby-next/actions?query=workflow%3A%22TruffleRuby+Build%22)
|
3
4
|
[![TruffleRuby Build](https://github.com/ruby-next/ruby-next/workflows/TruffleRuby%20Build/badge.svg)](https://github.com/ruby-next/ruby-next/actions?query=workflow%3A%22TruffleRuby+Build%22)
|
@@ -200,12 +201,15 @@ It has the following interface:
|
|
200
201
|
```sh
|
201
202
|
$ ruby-next nextify
|
202
203
|
Usage: ruby-next nextify DIRECTORY_OR_FILE [options]
|
203
|
-
-o, --output=OUTPUT Specify output directory or file or stdout
|
204
|
+
-o, --output=OUTPUT Specify output directory or file or stdout
|
204
205
|
--min-version=VERSION Specify the minimum Ruby version to support
|
205
206
|
--single-version Only create one version of a file (for the earliest Ruby version)
|
206
|
-
--
|
207
|
+
--edge Enable edge (master) Ruby features
|
208
|
+
--proposed Enable proposed/experimental Ruby features
|
207
209
|
--transpile-mode=MODE Transpiler mode (ast or rewrite). Default: ast
|
208
210
|
--[no-]refine Do not inject `using RubyNext`
|
211
|
+
--list-rewriters List available rewriters
|
212
|
+
--rewrite=REWRITERS... Specify particular Ruby features to rewrite
|
209
213
|
-h, --help Print help
|
210
214
|
-V Turn on verbose mode
|
211
215
|
--dry-run Print verbose output without generating files
|
@@ -10,7 +10,7 @@ module RubyNext
|
|
10
10
|
class Nextify < Base
|
11
11
|
using RubyNext
|
12
12
|
|
13
|
-
attr_reader :lib_path, :paths, :out_path, :min_version, :single_version
|
13
|
+
attr_reader :lib_path, :paths, :out_path, :min_version, :single_version, :specified_rewriters
|
14
14
|
|
15
15
|
def run
|
16
16
|
log "RubyNext core strategy: #{RubyNext::Core.strategy}"
|
@@ -18,6 +18,8 @@ module RubyNext
|
|
18
18
|
|
19
19
|
remove_rbnext!
|
20
20
|
|
21
|
+
@min_version ||= MIN_SUPPORTED_VERSION
|
22
|
+
|
21
23
|
paths.each do |path|
|
22
24
|
contents = File.read(path)
|
23
25
|
transpile path, contents
|
@@ -26,7 +28,8 @@ module RubyNext
|
|
26
28
|
|
27
29
|
def parse!(args)
|
28
30
|
print_help = false
|
29
|
-
|
31
|
+
print_rewriters = false
|
32
|
+
rewriter_names = []
|
30
33
|
@single_version = false
|
31
34
|
|
32
35
|
optparser = base_parser do |opts|
|
@@ -63,6 +66,14 @@ module RubyNext
|
|
63
66
|
Core.strategy = :core_ext unless val
|
64
67
|
end
|
65
68
|
|
69
|
+
opts.on("--list-rewriters", "List available rewriters") do |val|
|
70
|
+
print_rewriters = true
|
71
|
+
end
|
72
|
+
|
73
|
+
opts.on("--rewrite=REWRITERS...", "Specify particular Ruby features to rewrite") do |val|
|
74
|
+
rewriter_names << val
|
75
|
+
end
|
76
|
+
|
66
77
|
opts.on("-h", "--help", "Print help") do
|
67
78
|
print_help = true
|
68
79
|
end
|
@@ -77,12 +88,35 @@ module RubyNext
|
|
77
88
|
exit 0
|
78
89
|
end
|
79
90
|
|
91
|
+
if print_rewriters
|
92
|
+
Language.rewriters.each do |rewriter|
|
93
|
+
$stdout.puts "#{rewriter::NAME} (\"#{rewriter::SYNTAX_PROBE}\")"
|
94
|
+
end
|
95
|
+
exit 0
|
96
|
+
end
|
97
|
+
|
80
98
|
unless lib_path&.then(&File.method(:exist?))
|
81
99
|
$stdout.puts "Path not found: #{lib_path}"
|
82
100
|
$stdout.puts optparser.help
|
83
101
|
exit 2
|
84
102
|
end
|
85
103
|
|
104
|
+
if rewriter_names.any? && min_version
|
105
|
+
$stdout.puts "--rewrite cannot be used with --min-version simultaneously"
|
106
|
+
exit 2
|
107
|
+
end
|
108
|
+
|
109
|
+
@specified_rewriters =
|
110
|
+
if rewriter_names.any?
|
111
|
+
begin
|
112
|
+
Language.select_rewriters(*rewriter_names)
|
113
|
+
rescue Language::RewriterNotFoundError => error
|
114
|
+
$stdout.puts error.message
|
115
|
+
$stdout.puts "Try --list-rewriters to see list of available rewriters"
|
116
|
+
exit 2
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
86
120
|
@paths =
|
87
121
|
if File.directory?(lib_path)
|
88
122
|
Dir[File.join(lib_path, "**/*.rb")]
|
@@ -96,16 +130,11 @@ module RubyNext
|
|
96
130
|
private
|
97
131
|
|
98
132
|
def transpile(path, contents, version: min_version)
|
99
|
-
rewriters = Language.rewriters.select { |rw| rw.unsupported_version?(version) }
|
133
|
+
rewriters = specified_rewriters || Language.rewriters.select { |rw| rw.unsupported_version?(version) }
|
100
134
|
|
101
135
|
context = Language::TransformContext.new
|
102
136
|
|
103
|
-
new_contents =
|
104
|
-
if Gem::Version.new(version) >= Gem::Version.new("2.7.0") && !defined?(Unparser::Emitter::CaseMatch)
|
105
|
-
Language.rewrite contents, context: context, rewriters: rewriters
|
106
|
-
else
|
107
|
-
Language.transform contents, context: context, rewriters: rewriters
|
108
|
-
end
|
137
|
+
new_contents = Language.transform contents, context: context, rewriters: rewriters
|
109
138
|
|
110
139
|
return unless context.dirty?
|
111
140
|
|
@@ -161,7 +190,9 @@ module RubyNext
|
|
161
190
|
out_path == "stdout"
|
162
191
|
end
|
163
192
|
|
164
|
-
|
193
|
+
def single_version?
|
194
|
+
single_version || specified_rewriters
|
195
|
+
end
|
165
196
|
end
|
166
197
|
end
|
167
198
|
end
|
data/lib/ruby-next/language.rb
CHANGED
@@ -23,6 +23,8 @@ module RubyNext
|
|
23
23
|
require "ruby-next/language/parser"
|
24
24
|
require "ruby-next/language/unparser"
|
25
25
|
|
26
|
+
RewriterNotFoundError = Class.new(StandardError)
|
27
|
+
|
26
28
|
class TransformContext
|
27
29
|
attr_reader :versions, :use_ruby_next
|
28
30
|
|
@@ -85,12 +87,6 @@ module RubyNext
|
|
85
87
|
def runtime!
|
86
88
|
require "ruby-next/language/rewriters/runtime"
|
87
89
|
|
88
|
-
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.7.0") && !defined?(Unparser::Emitter::CaseMatch)
|
89
|
-
RubyNext.warn "Ruby Next fallbacks to \"rewrite\" transpiling mode since Unparser doesn't support 2.7 AST yet.\n" \
|
90
|
-
"See https://github.com/mbj/unparser/pull/142"
|
91
|
-
self.mode = :rewrite
|
92
|
-
end
|
93
|
-
|
94
90
|
@runtime = true
|
95
91
|
end
|
96
92
|
|
@@ -104,6 +100,13 @@ module RubyNext
|
|
104
100
|
else
|
105
101
|
regenerate(*args, **kwargs)
|
106
102
|
end
|
103
|
+
rescue Unparser::UnknownEmitterError
|
104
|
+
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.7.0")
|
105
|
+
RubyNext.warn "Ruby Next fallbacks to \"rewrite\" transpiling mode since Unparser doesn't support 2.7+ AST yet.\n" \
|
106
|
+
"See https://github.com/mbj/unparser/pull/142"
|
107
|
+
self.mode = :rewrite
|
108
|
+
end
|
109
|
+
rewrite(*args, **kwargs)
|
107
110
|
end
|
108
111
|
|
109
112
|
def regenerate(source, rewriters: self.rewriters, using: RubyNext::Core.refine?, context: TransformContext.new)
|
@@ -149,6 +152,16 @@ module RubyNext
|
|
149
152
|
@current_rewriters ||= rewriters.select(&:unsupported_syntax?)
|
150
153
|
end
|
151
154
|
|
155
|
+
# This method guarantees that rewriters will be returned in order they defined in Language module
|
156
|
+
def select_rewriters(*names)
|
157
|
+
rewriters_delta = names - rewriters.map { |rewriter| rewriter::NAME }
|
158
|
+
if rewriters_delta.any?
|
159
|
+
raise RewriterNotFoundError, "Rewriters not found: #{rewriters_delta.join(",")}"
|
160
|
+
end
|
161
|
+
|
162
|
+
rewriters.select { |rewriter| names.include?(rewriter::NAME) }
|
163
|
+
end
|
164
|
+
|
152
165
|
private
|
153
166
|
|
154
167
|
attr_writer :watch_dirs
|
@@ -6,3 +6,17 @@ require "parser/current"
|
|
6
6
|
$VERBOSE = save_verbose
|
7
7
|
|
8
8
|
require "unparser"
|
9
|
+
|
10
|
+
unless defined?(Unparser::UnknownEmitterError)
|
11
|
+
module Unparser
|
12
|
+
class UnknownEmitterError < ArgumentError
|
13
|
+
end
|
14
|
+
|
15
|
+
Emitter.singleton_class.prepend(Module.new do
|
16
|
+
def emitter(node, parent)
|
17
|
+
raise UnknownEmitterError, "No emitter for node: #{node.type.inspect}" unless Emitter::REGISTRY.key?(node.type)
|
18
|
+
super
|
19
|
+
end
|
20
|
+
end)
|
21
|
+
end
|
22
|
+
end
|
data/lib/ruby-next/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-next-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vladimir Dementyev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-06-
|
11
|
+
date: 2020-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-next-parser
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 2.8.0.
|
19
|
+
version: 2.8.0.7
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 2.8.0.
|
26
|
+
version: 2.8.0.7
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: unparser
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|