syntax_tree 5.0.1 → 5.2.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/main.yml +5 -2
- data/.gitmodules +6 -0
- data/.rubocop.yml +58 -1
- data/CHANGELOG.md +28 -1
- data/Gemfile.lock +12 -12
- data/README.md +5 -5
- data/Rakefile +7 -0
- data/exe/yarv +63 -0
- data/lib/syntax_tree/dsl.rb +1004 -0
- data/lib/syntax_tree/formatter.rb +2 -2
- data/lib/syntax_tree/language_server.rb +2 -0
- data/lib/syntax_tree/node.rb +26 -17
- data/lib/syntax_tree/parser.rb +21 -22
- data/lib/syntax_tree/version.rb +1 -1
- data/lib/syntax_tree/yarv/assembler.rb +459 -0
- data/lib/syntax_tree/yarv/bf.rb +176 -0
- data/lib/syntax_tree/yarv/compiler.rb +2298 -0
- data/lib/syntax_tree/yarv/decompiler.rb +263 -0
- data/lib/syntax_tree/yarv/disassembler.rb +212 -0
- data/lib/syntax_tree/yarv/instruction_sequence.rb +1275 -0
- data/lib/syntax_tree/yarv/instructions.rb +5372 -0
- data/lib/syntax_tree/yarv/legacy.rb +215 -0
- data/lib/syntax_tree/yarv/local_table.rb +89 -0
- data/lib/syntax_tree/yarv/vm.rb +624 -0
- data/lib/syntax_tree/yarv.rb +18 -0
- data/lib/syntax_tree.rb +20 -1
- data/syntax_tree.gemspec +1 -1
- metadata +20 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c5651bab4283bf0f1c451619e5c3b54c9b229d1fb5050a3732918bccb7be177
|
4
|
+
data.tar.gz: 2cda5e4b62a3beac16dddc8ff9298624c161bc99c3b82ba2ecc10d8d643aac4b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81d331f10356569b23ada917cea2ecf5a2dd1073bc927e39ba0b6036ea4b79813ce7b1e4826f39d919559cdbb5925da8a5680d72653d64d0eb05979729356173
|
7
|
+
data.tar.gz: 53b320f073ef5e15efcd2e7d706e959e3ade48f18ab0f131a588a183276aeea3352cf6da0ef2ad842dc0c9bf517ac4c441ee4fbe98fa73dd156e845d5d4007d7
|
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
data/.rubocop.yml
CHANGED
@@ -7,7 +7,7 @@ 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
11
|
- test.rb
|
12
12
|
|
13
13
|
Layout/LineLength:
|
@@ -16,6 +16,15 @@ Layout/LineLength:
|
|
16
16
|
Lint/AmbiguousBlockAssociation:
|
17
17
|
Enabled: false
|
18
18
|
|
19
|
+
Lint/AmbiguousOperatorPrecedence:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
Lint/AmbiguousRange:
|
23
|
+
Enabled: false
|
24
|
+
|
25
|
+
Lint/BooleanSymbol:
|
26
|
+
Enabled: false
|
27
|
+
|
19
28
|
Lint/DuplicateBranch:
|
20
29
|
Enabled: false
|
21
30
|
|
@@ -28,9 +37,21 @@ Lint/InterpolationCheck:
|
|
28
37
|
Lint/MissingSuper:
|
29
38
|
Enabled: false
|
30
39
|
|
40
|
+
Lint/NonLocalExitFromIterator:
|
41
|
+
Enabled: false
|
42
|
+
|
31
43
|
Lint/RedundantRequireStatement:
|
32
44
|
Enabled: false
|
33
45
|
|
46
|
+
Lint/RescueException:
|
47
|
+
Enabled: false
|
48
|
+
|
49
|
+
Lint/SuppressedException:
|
50
|
+
Enabled: false
|
51
|
+
|
52
|
+
Lint/UnderscorePrefixedVariableName:
|
53
|
+
Enabled: false
|
54
|
+
|
34
55
|
Lint/UnusedMethodArgument:
|
35
56
|
AllowUnusedKeywordArguments: true
|
36
57
|
|
@@ -46,15 +67,42 @@ Naming/MethodParameterName:
|
|
46
67
|
Naming/RescuedExceptionsVariableName:
|
47
68
|
PreferredName: error
|
48
69
|
|
70
|
+
Naming/VariableNumber:
|
71
|
+
Enabled: false
|
72
|
+
|
73
|
+
Security/Eval:
|
74
|
+
Enabled: false
|
75
|
+
|
76
|
+
Style/AccessorGrouping:
|
77
|
+
Enabled: false
|
78
|
+
|
49
79
|
Style/CaseEquality:
|
50
80
|
Enabled: false
|
51
81
|
|
82
|
+
Style/CaseLikeIf:
|
83
|
+
Enabled: false
|
84
|
+
|
85
|
+
Style/ClassVars:
|
86
|
+
Enabled: false
|
87
|
+
|
88
|
+
Style/DocumentDynamicEvalDefinition:
|
89
|
+
Enabled: false
|
90
|
+
|
91
|
+
Style/Documentation:
|
92
|
+
Enabled: false
|
93
|
+
|
94
|
+
Style/EndBlock:
|
95
|
+
Enabled: false
|
96
|
+
|
52
97
|
Style/ExplicitBlockArgument:
|
53
98
|
Enabled: false
|
54
99
|
|
55
100
|
Style/FormatString:
|
56
101
|
Enabled: false
|
57
102
|
|
103
|
+
Style/FormatStringToken:
|
104
|
+
Enabled: false
|
105
|
+
|
58
106
|
Style/GuardClause:
|
59
107
|
Enabled: false
|
60
108
|
|
@@ -79,6 +127,9 @@ Style/MutableConstant:
|
|
79
127
|
Style/NegatedIfElseCondition:
|
80
128
|
Enabled: false
|
81
129
|
|
130
|
+
Style/Next:
|
131
|
+
Enabled: false
|
132
|
+
|
82
133
|
Style/NumericPredicate:
|
83
134
|
Enabled: false
|
84
135
|
|
@@ -88,8 +139,14 @@ Style/ParallelAssignment:
|
|
88
139
|
Style/PerlBackrefs:
|
89
140
|
Enabled: false
|
90
141
|
|
142
|
+
Style/SafeNavigation:
|
143
|
+
Enabled: false
|
144
|
+
|
91
145
|
Style/SpecialGlobalVars:
|
92
146
|
Enabled: false
|
93
147
|
|
94
148
|
Style/StructInheritance:
|
95
149
|
Enabled: false
|
150
|
+
|
151
|
+
Style/YodaExpression:
|
152
|
+
Enabled: false
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,31 @@ 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.2.0] - 2023-01-04
|
10
|
+
|
11
|
+
### Added
|
12
|
+
|
13
|
+
- 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.
|
14
|
+
|
15
|
+
### Changed
|
16
|
+
|
17
|
+
- 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.
|
18
|
+
|
19
|
+
## [5.1.0] - 2022-12-28
|
20
|
+
|
21
|
+
### Added
|
22
|
+
|
23
|
+
- An experiment in working with instruction sequences has been added to Syntax Tree. This is subject to change, so it is not well documented or tested at the moment. It does not impact other functionality.
|
24
|
+
- You can now format at a different base layer of indentation. This is an optional third argument to `SyntaxTree::format`.
|
25
|
+
|
26
|
+
### Changed
|
27
|
+
|
28
|
+
- Support forwarding anonymous keyword arguments with `**`.
|
29
|
+
- The `BodyStmt` node now has a more correct location information.
|
30
|
+
- Ignore the `textDocument/documentColor` request coming into the language server to support clients that require that request be received.
|
31
|
+
- Do not attempt to convert `if..else` into ternaries if the predicate has a `Binary` node.
|
32
|
+
- Properly handle nested pattern matching when a rightward assignment is inside a `when` clause.
|
33
|
+
|
9
34
|
## [5.0.1] - 2022-11-10
|
10
35
|
|
11
36
|
### Changed
|
@@ -456,7 +481,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
|
|
456
481
|
|
457
482
|
- 🎉 Initial release! 🎉
|
458
483
|
|
459
|
-
[unreleased]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v5.0
|
484
|
+
[unreleased]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v5.2.0...HEAD
|
485
|
+
[5.2.0]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v5.1.0...v5.2.0
|
486
|
+
[5.1.0]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v5.0.1...v5.1.0
|
460
487
|
[5.0.1]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v5.0.0...v5.0.1
|
461
488
|
[5.0.0]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v4.3.0...v5.0.0
|
462
489
|
[4.3.0]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v4.2.0...v4.3.0
|
data/Gemfile.lock
CHANGED
@@ -1,44 +1,44 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
syntax_tree (5.0
|
5
|
-
prettier_print (>= 1.
|
4
|
+
syntax_tree (5.2.0)
|
5
|
+
prettier_print (>= 1.2.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
10
|
ast (2.4.2)
|
11
11
|
docile (1.4.0)
|
12
|
-
json (2.6.
|
13
|
-
minitest (5.
|
12
|
+
json (2.6.3)
|
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
|
-
prettier_print (1.
|
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.1)
|
21
21
|
rexml (3.2.5)
|
22
|
-
rubocop (1.
|
22
|
+
rubocop (1.42.0)
|
23
23
|
json (~> 2.3)
|
24
24
|
parallel (~> 1.10)
|
25
25
|
parser (>= 3.1.2.1)
|
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
31
|
unicode-display_width (>= 1.4.0, < 3.0)
|
32
|
-
rubocop-ast (1.
|
32
|
+
rubocop-ast (1.24.1)
|
33
33
|
parser (>= 3.1.1.0)
|
34
34
|
ruby-progressbar (1.11.0)
|
35
|
-
simplecov (0.
|
35
|
+
simplecov (0.22.0)
|
36
36
|
docile (~> 1.1)
|
37
37
|
simplecov-html (~> 0.11)
|
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.1)
|
42
42
|
|
43
43
|
PLATFORMS
|
44
44
|
arm64-darwin-21
|
data/README.md
CHANGED
@@ -324,11 +324,11 @@ stree write "**/{[!schema]*,*}.rb"
|
|
324
324
|
|
325
325
|
## Library
|
326
326
|
|
327
|
-
Syntax Tree can be used as a library to access the syntax tree underlying Ruby source code.
|
327
|
+
Syntax Tree can be used as a library to access the syntax tree underlying Ruby source code. The API is described below. For the full library documentation, see the [RDoc documentation](https://ruby-syntax-tree.github.io/syntax_tree/).
|
328
328
|
|
329
329
|
### SyntaxTree.read(filepath)
|
330
330
|
|
331
|
-
This function takes a filepath and returns a string associated with the content of that file. It is similar in functionality to `File.read`, except
|
331
|
+
This function takes a filepath and returns a string associated with the content of that file. It is similar in functionality to `File.read`, except that it takes into account Ruby-level file encoding (through magic comments at the top of the file).
|
332
332
|
|
333
333
|
### SyntaxTree.parse(source)
|
334
334
|
|
@@ -570,7 +570,7 @@ SyntaxTree::Formatter.format(source, program.accept(visitor))
|
|
570
570
|
### WithEnvironment
|
571
571
|
|
572
572
|
The `WithEnvironment` module can be included in visitors to automatically keep track of local variables and arguments
|
573
|
-
defined inside each environment. A `current_environment` accessor is made
|
573
|
+
defined inside each environment. A `current_environment` accessor is made available to the request, allowing it to find
|
574
574
|
all usages and definitions of a local.
|
575
575
|
|
576
576
|
```ruby
|
@@ -611,7 +611,7 @@ The language server also responds to the relatively new inlay hints request. Thi
|
|
611
611
|
1 + 2 * 3
|
612
612
|
```
|
613
613
|
|
614
|
-
|
614
|
+
Implicitly, the `2 * 3` is going to be executed first because the `*` operator has higher precedence than the `+` operator. To ease mental overhead, our language server includes small parentheses to make this explicit, as in:
|
615
615
|
|
616
616
|
```ruby
|
617
617
|
1 + ₍2 * 3₎
|
@@ -686,7 +686,7 @@ Below are listed all of the "official" language plugins hosted under the same Gi
|
|
686
686
|
|
687
687
|
## Integration
|
688
688
|
|
689
|
-
Syntax Tree's goal is to
|
689
|
+
Syntax Tree's goal is to seamlessly integrate into your workflow. To this end, it provides a couple of additional tools beyond the CLI and the Ruby library.
|
690
690
|
|
691
691
|
### Rake
|
692
692
|
|
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)
|