syntax_tree 5.1.0 → 5.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +4 -0
- data/.github/workflows/auto-merge.yml +1 -1
- data/.github/workflows/gh-pages.yml +1 -1
- data/.github/workflows/main.yml +5 -2
- data/.gitmodules +9 -0
- data/.rubocop.yml +11 -1
- data/CHANGELOG.md +29 -1
- data/Gemfile.lock +10 -10
- data/README.md +1 -0
- data/Rakefile +7 -0
- data/exe/yarv +63 -0
- data/lib/syntax_tree/cli.rb +3 -2
- data/lib/syntax_tree/formatter.rb +23 -2
- data/lib/syntax_tree/index.rb +374 -0
- data/lib/syntax_tree/node.rb +146 -107
- data/lib/syntax_tree/parser.rb +20 -3
- data/lib/syntax_tree/plugin/disable_ternary.rb +7 -0
- data/lib/syntax_tree/version.rb +1 -1
- data/lib/syntax_tree/yarv/assembler.rb +17 -13
- data/lib/syntax_tree/yarv/bf.rb +13 -16
- data/lib/syntax_tree/yarv/compiler.rb +25 -14
- data/lib/syntax_tree/yarv/decompiler.rb +10 -1
- data/lib/syntax_tree/yarv/disassembler.rb +3 -2
- data/lib/syntax_tree/yarv/instruction_sequence.rb +191 -87
- data/lib/syntax_tree/yarv/instructions.rb +1011 -42
- data/lib/syntax_tree/yarv/legacy.rb +59 -3
- data/lib/syntax_tree/yarv/vm.rb +628 -0
- data/lib/syntax_tree/yarv.rb +0 -269
- data/lib/syntax_tree.rb +16 -0
- metadata +9 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3261679bf963ba7263bb3ae21e826ed1fa7a28c6afbf2a2b65b42101be16b7ac
|
4
|
+
data.tar.gz: 653c6c79a34db7686ceeadf83f0d8adb47093d1ab1d946636008ee4c31144258
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9cefe2a22c594efc74aa0fbe300c986a414c890efb7204633481345ceb9b0bd3578d836046ca64e289621ce31ea343f0da40db1f9b3d2d7dbd7f0a11b020c725
|
7
|
+
data.tar.gz: 628ed098064cb9e6dc720666d59b5e9d8653f7e06cb7e0774887dfeb4ed4a5bdb217ea644b93f52a3730e2dfdc14334c0690018d145728a89fa99cbd041e4301
|
data/.github/dependabot.yml
CHANGED
data/.github/workflows/main.yml
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
name: Main
|
2
|
+
|
2
3
|
on:
|
3
4
|
- push
|
4
5
|
- pull_request
|
6
|
+
|
5
7
|
jobs:
|
6
8
|
ci:
|
7
9
|
strategy:
|
@@ -11,13 +13,14 @@ jobs:
|
|
11
13
|
- '2.7.0'
|
12
14
|
- '3.0'
|
13
15
|
- '3.1'
|
16
|
+
- '3.2'
|
14
17
|
- head
|
15
18
|
- truffleruby-head
|
16
19
|
name: CI
|
17
20
|
runs-on: ubuntu-latest
|
18
21
|
env:
|
19
22
|
CI: true
|
20
|
-
TESTOPTS: --verbose
|
23
|
+
# TESTOPTS: --verbose
|
21
24
|
steps:
|
22
25
|
- uses: actions/checkout@master
|
23
26
|
- uses: ruby/setup-ruby@v1
|
@@ -37,7 +40,7 @@ jobs:
|
|
37
40
|
- uses: ruby/setup-ruby@v1
|
38
41
|
with:
|
39
42
|
bundler-cache: true
|
40
|
-
ruby-version: '3.
|
43
|
+
ruby-version: '3.2'
|
41
44
|
- name: Check
|
42
45
|
run: |
|
43
46
|
bundle exec rake stree:check
|
data/.gitmodules
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
[submodule "mspec"]
|
2
|
+
path = spec/mspec
|
3
|
+
url = git@github.com:ruby/mspec.git
|
4
|
+
[submodule "spec"]
|
5
|
+
path = spec/ruby
|
6
|
+
url = git@github.com:ruby/spec.git
|
7
|
+
[submodule "test/ruby-syntax-fixtures"]
|
8
|
+
path = test/ruby-syntax-fixtures
|
9
|
+
url = https://github.com/ruby-syntax-tree/ruby-syntax-fixtures
|
data/.rubocop.yml
CHANGED
@@ -7,9 +7,13 @@ AllCops:
|
|
7
7
|
SuggestExtensions: false
|
8
8
|
TargetRubyVersion: 2.7
|
9
9
|
Exclude:
|
10
|
-
- '{.git,.github,bin,coverage,pkg,test/fixtures,vendor,tmp}/**/*'
|
10
|
+
- '{.git,.github,bin,coverage,pkg,spec,test/fixtures,vendor,tmp}/**/*'
|
11
|
+
- test/ruby-syntax-fixtures/**/*
|
11
12
|
- test.rb
|
12
13
|
|
14
|
+
Gemspec/DevelopmentDependencies:
|
15
|
+
Enabled: false
|
16
|
+
|
13
17
|
Layout/LineLength:
|
14
18
|
Max: 80
|
15
19
|
|
@@ -43,6 +47,9 @@ Lint/NonLocalExitFromIterator:
|
|
43
47
|
Lint/RedundantRequireStatement:
|
44
48
|
Enabled: false
|
45
49
|
|
50
|
+
Lint/RescueException:
|
51
|
+
Enabled: false
|
52
|
+
|
46
53
|
Lint/SuppressedException:
|
47
54
|
Enabled: false
|
48
55
|
|
@@ -144,3 +151,6 @@ Style/SpecialGlobalVars:
|
|
144
151
|
|
145
152
|
Style/StructInheritance:
|
146
153
|
Enabled: false
|
154
|
+
|
155
|
+
Style/YodaExpression:
|
156
|
+
Enabled: false
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,32 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [5.3.0] - 2023-01-26
|
10
|
+
|
11
|
+
### Added
|
12
|
+
|
13
|
+
- `#arity` has been added to `DefNode`, `BlockNode`, and `Params`. The method returns a range where the lower bound is the minimum and the upper bound is the maximum number of arguments that can be used to invoke that block/method definition.
|
14
|
+
- `#arity` has been added to `CallNode`, `Command`, `CommandCall`, and `VCall` nodes. The method returns the number of arguments included in the invocation. For splats, double splats, or argument forwards, this method returns `Float::INFINITY`.
|
15
|
+
- `SyntaxTree::index` and `SyntaxTree::index_file` APIs have been added to collect a list of classes, modules, and methods defined in a given source string or file, respectively. These APIs are experimental and subject to change.
|
16
|
+
- A `plugin/disable_auto_ternary` plugin has been added the disables the formatted that automatically changes permissable `if/else` clauses into ternaries.
|
17
|
+
|
18
|
+
### Changed
|
19
|
+
|
20
|
+
- Files are now only written from the CLI if the content of them changes, which should match watching files less chaotic.
|
21
|
+
- In the case that `rb_iseq_load` cannot be found, `Fiddle::DLError` is now rescued.
|
22
|
+
- Previously if there were invalid UTF-8 byte sequences after the `__END__` keyword the parser could potentially have crashed when parsing comments. This has been fixed.
|
23
|
+
- Previously there was special formatting for array literals that contained only variable references (either locals, method calls, or constants). For consistency, this has been removed and all array literals are now formatted the same way.
|
24
|
+
|
25
|
+
## [5.2.0] - 2023-01-04
|
26
|
+
|
27
|
+
### Added
|
28
|
+
|
29
|
+
- An experiment in evaluating compiled instruction sequences has been added to Syntax Tree. This is subject to change, so it will not be well documented or testing at the moment. It does not impact other functionality.
|
30
|
+
|
31
|
+
### Changed
|
32
|
+
|
33
|
+
- Empty parentheses on method calls will now be left in place. Previously they were left in place if the method being called looked like a constant. Now they are left in place for all method calls since the method name can mirror the name of a local variable, in which case the parentheses are required.
|
34
|
+
|
9
35
|
## [5.1.0] - 2022-12-28
|
10
36
|
|
11
37
|
### Added
|
@@ -471,7 +497,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
|
|
471
497
|
|
472
498
|
- 🎉 Initial release! 🎉
|
473
499
|
|
474
|
-
[unreleased]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v5.
|
500
|
+
[unreleased]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v5.3.0...HEAD
|
501
|
+
[5.3.0]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v5.2.0...v5.3.0
|
502
|
+
[5.2.0]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v5.1.0...v5.2.0
|
475
503
|
[5.1.0]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v5.0.1...v5.1.0
|
476
504
|
[5.0.1]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v5.0.0...v5.0.1
|
477
505
|
[5.0.0]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v4.3.0...v5.0.0
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
syntax_tree (5.
|
4
|
+
syntax_tree (5.3.0)
|
5
5
|
prettier_print (>= 1.2.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -10,26 +10,26 @@ GEM
|
|
10
10
|
ast (2.4.2)
|
11
11
|
docile (1.4.0)
|
12
12
|
json (2.6.3)
|
13
|
-
minitest (5.
|
13
|
+
minitest (5.17.0)
|
14
14
|
parallel (1.22.1)
|
15
|
-
parser (3.
|
15
|
+
parser (3.2.0.0)
|
16
16
|
ast (~> 2.4.1)
|
17
17
|
prettier_print (1.2.0)
|
18
18
|
rainbow (3.1.1)
|
19
19
|
rake (13.0.6)
|
20
|
-
regexp_parser (2.6.
|
20
|
+
regexp_parser (2.6.2)
|
21
21
|
rexml (3.2.5)
|
22
|
-
rubocop (1.
|
22
|
+
rubocop (1.44.1)
|
23
23
|
json (~> 2.3)
|
24
24
|
parallel (~> 1.10)
|
25
|
-
parser (>= 3.
|
25
|
+
parser (>= 3.2.0.0)
|
26
26
|
rainbow (>= 2.2.2, < 4.0)
|
27
27
|
regexp_parser (>= 1.8, < 3.0)
|
28
28
|
rexml (>= 3.2.5, < 4.0)
|
29
|
-
rubocop-ast (>= 1.
|
29
|
+
rubocop-ast (>= 1.24.1, < 2.0)
|
30
30
|
ruby-progressbar (~> 1.7)
|
31
|
-
unicode-display_width (>=
|
32
|
-
rubocop-ast (1.24.
|
31
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
32
|
+
rubocop-ast (1.24.1)
|
33
33
|
parser (>= 3.1.1.0)
|
34
34
|
ruby-progressbar (1.11.0)
|
35
35
|
simplecov (0.22.0)
|
@@ -38,7 +38,7 @@ GEM
|
|
38
38
|
simplecov_json_formatter (~> 0.1)
|
39
39
|
simplecov-html (0.12.3)
|
40
40
|
simplecov_json_formatter (0.1.4)
|
41
|
-
unicode-display_width (2.
|
41
|
+
unicode-display_width (2.4.2)
|
42
42
|
|
43
43
|
PLATFORMS
|
44
44
|
arm64-darwin-21
|
data/README.md
CHANGED
@@ -658,6 +658,7 @@ To register plugins, define a file somewhere in your load path named `syntax_tre
|
|
658
658
|
|
659
659
|
* `plugin/single_quotes` - This will change all of your string literals to use single quotes instead of the default double quotes.
|
660
660
|
* `plugin/trailing_comma` - This will put trailing commas into multiline array literals, hash literals, and method calls that can support trailing commas.
|
661
|
+
* `plugin/disable_auto_ternary` - This will prevent the automatic conversion of `if ... else` to ternary expressions.
|
661
662
|
|
662
663
|
If you're using Syntax Tree as a library, you can require those files directly or manually pass those options to the formatter initializer through the `SyntaxTree::Formatter::Options` class.
|
663
664
|
|
data/Rakefile
CHANGED
@@ -26,3 +26,10 @@ end
|
|
26
26
|
|
27
27
|
SyntaxTree::Rake::CheckTask.new(&configure)
|
28
28
|
SyntaxTree::Rake::WriteTask.new(&configure)
|
29
|
+
|
30
|
+
desc "Run mspec tests using YARV emulation"
|
31
|
+
task :spec do
|
32
|
+
Dir["./spec/ruby/language/**/*_spec.rb"].each do |filepath|
|
33
|
+
sh "exe/yarv ./spec/mspec/bin/mspec-tag #{filepath}"
|
34
|
+
end
|
35
|
+
end
|
data/exe/yarv
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
$:.unshift(File.expand_path("../lib", __dir__))
|
5
|
+
|
6
|
+
require "syntax_tree"
|
7
|
+
|
8
|
+
# Require these here so that we can run binding.irb without having them require
|
9
|
+
# anything that we've already patched.
|
10
|
+
require "irb"
|
11
|
+
require "irb/completion"
|
12
|
+
require "irb/color_printer"
|
13
|
+
require "readline"
|
14
|
+
|
15
|
+
# First, create an instance of our virtual machine.
|
16
|
+
events =
|
17
|
+
if ENV["DEBUG"]
|
18
|
+
SyntaxTree::YARV::VM::STDOUTEvents.new
|
19
|
+
else
|
20
|
+
SyntaxTree::YARV::VM::NullEvents.new
|
21
|
+
end
|
22
|
+
|
23
|
+
vm = SyntaxTree::YARV::VM.new(events)
|
24
|
+
|
25
|
+
# Next, set up a bunch of aliases for methods that we're going to hook into in
|
26
|
+
# order to set up our virtual machine.
|
27
|
+
class << Kernel
|
28
|
+
alias yarv_require require
|
29
|
+
alias yarv_require_relative require_relative
|
30
|
+
alias yarv_load load
|
31
|
+
alias yarv_eval eval
|
32
|
+
alias yarv_throw throw
|
33
|
+
alias yarv_catch catch
|
34
|
+
end
|
35
|
+
|
36
|
+
# Next, patch the methods that we just aliased so that they use our virtual
|
37
|
+
# machine's versions instead. This allows us to load Ruby files and have them
|
38
|
+
# execute in our virtual machine instead of the runtime environment.
|
39
|
+
[Kernel, Kernel.singleton_class].each do |klass|
|
40
|
+
klass.define_method(:require) { |filepath| vm.require(filepath) }
|
41
|
+
|
42
|
+
klass.define_method(:load) { |filepath| vm.load(filepath) }
|
43
|
+
|
44
|
+
# klass.define_method(:require_relative) do |filepath|
|
45
|
+
# vm.require_relative(filepath)
|
46
|
+
# end
|
47
|
+
|
48
|
+
# klass.define_method(:eval) do |
|
49
|
+
# source,
|
50
|
+
# binding = TOPLEVEL_BINDING,
|
51
|
+
# filename = "(eval)",
|
52
|
+
# lineno = 1
|
53
|
+
# |
|
54
|
+
# vm.eval(source, binding, filename, lineno)
|
55
|
+
# end
|
56
|
+
|
57
|
+
# klass.define_method(:throw) { |tag, value = nil| vm.throw(tag, value) }
|
58
|
+
|
59
|
+
# klass.define_method(:catch) { |tag, &block| vm.catch(tag, &block) }
|
60
|
+
end
|
61
|
+
|
62
|
+
# Finally, require the file that we want to execute.
|
63
|
+
vm.require_resolved(ARGV.shift)
|
data/lib/syntax_tree/cli.rb
CHANGED
@@ -303,10 +303,11 @@ module SyntaxTree
|
|
303
303
|
options.print_width,
|
304
304
|
options: options.formatter_options
|
305
305
|
)
|
306
|
+
changed = source != formatted
|
306
307
|
|
307
|
-
File.write(filepath, formatted) if item.writable?
|
308
|
+
File.write(filepath, formatted) if item.writable? && changed
|
308
309
|
|
309
|
-
color =
|
310
|
+
color = changed ? filepath : Color.gray(filepath)
|
310
311
|
delta = ((Time.now - start) * 1000).round
|
311
312
|
|
312
313
|
puts "#{color} #{delta}ms"
|
@@ -21,11 +21,15 @@ module SyntaxTree
|
|
21
21
|
# that folks have become entrenched in their ways, we decided to provide a
|
22
22
|
# small amount of configurability.
|
23
23
|
class Options
|
24
|
-
attr_reader :quote,
|
24
|
+
attr_reader :quote,
|
25
|
+
:trailing_comma,
|
26
|
+
:disable_auto_ternary,
|
27
|
+
:target_ruby_version
|
25
28
|
|
26
29
|
def initialize(
|
27
30
|
quote: :default,
|
28
31
|
trailing_comma: :default,
|
32
|
+
disable_auto_ternary: :default,
|
29
33
|
target_ruby_version: :default
|
30
34
|
)
|
31
35
|
@quote =
|
@@ -50,6 +54,17 @@ module SyntaxTree
|
|
50
54
|
trailing_comma
|
51
55
|
end
|
52
56
|
|
57
|
+
@disable_auto_ternary =
|
58
|
+
if disable_auto_ternary == :default
|
59
|
+
# We ship with a disable ternary plugin that will define this
|
60
|
+
# constant. That constant is responsible for determining the default
|
61
|
+
# disable ternary value. If it's defined, then we default to true.
|
62
|
+
# Otherwise we default to false.
|
63
|
+
defined?(DISABLE_TERNARY)
|
64
|
+
else
|
65
|
+
disable_auto_ternary
|
66
|
+
end
|
67
|
+
|
53
68
|
@target_ruby_version =
|
54
69
|
if target_ruby_version == :default
|
55
70
|
# The default target Ruby version is the current version of Ruby.
|
@@ -69,8 +84,13 @@ module SyntaxTree
|
|
69
84
|
|
70
85
|
# These options are overridden in plugins to we need to make sure they are
|
71
86
|
# available here.
|
72
|
-
attr_reader :quote,
|
87
|
+
attr_reader :quote,
|
88
|
+
:trailing_comma,
|
89
|
+
:disable_auto_ternary,
|
90
|
+
:target_ruby_version
|
91
|
+
|
73
92
|
alias trailing_comma? trailing_comma
|
93
|
+
alias disable_auto_ternary? disable_auto_ternary
|
74
94
|
|
75
95
|
def initialize(source, *args, options: Options.new)
|
76
96
|
super(*args)
|
@@ -81,6 +101,7 @@ module SyntaxTree
|
|
81
101
|
# Memoizing these values to make access faster.
|
82
102
|
@quote = options.quote
|
83
103
|
@trailing_comma = options.trailing_comma
|
104
|
+
@disable_auto_ternary = options.disable_auto_ternary
|
84
105
|
@target_ruby_version = options.target_ruby_version
|
85
106
|
end
|
86
107
|
|