syntax_tree 6.1.1 → 6.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/auto-merge.yml +1 -1
- data/.github/workflows/gh-pages.yml +6 -6
- data/.github/workflows/main.yml +2 -1
- data/.rubocop.yml +10 -1
- data/CHANGELOG.md +28 -1
- data/Gemfile +2 -0
- data/Gemfile.lock +30 -20
- data/README.md +3 -3
- data/lib/syntax_tree/cli.rb +69 -14
- data/lib/syntax_tree/database.rb +331 -0
- data/lib/syntax_tree/formatter.rb +1 -1
- data/lib/syntax_tree/language_server.rb +8 -2
- data/lib/syntax_tree/node.rb +70 -67
- data/lib/syntax_tree/parser.rb +8 -3
- data/lib/syntax_tree/pattern.rb +1 -0
- data/lib/syntax_tree/plugin/{disable_ternary.rb → disable_auto_ternary.rb} +1 -1
- data/lib/syntax_tree/reflection.rb +1 -1
- data/lib/syntax_tree/version.rb +1 -1
- data/lib/syntax_tree/with_scope.rb +1 -4
- data/lib/syntax_tree/yarv/assembler.rb +2 -3
- data/lib/syntax_tree/yarv/calldata.rb +21 -15
- data/lib/syntax_tree/yarv/decompiler.rb +6 -6
- data/lib/syntax_tree/yarv/instruction_sequence.rb +56 -10
- data/lib/syntax_tree/yarv/instructions.rb +165 -64
- data/lib/syntax_tree/yarv/legacy.rb +104 -0
- data/lib/syntax_tree.rb +1 -0
- data/tasks/whitequark.rake +7 -2
- metadata +5 -9
- data/.ruby-version +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d2e2bb8b41f091f6895ef5207081790c08ddaab126e8d5ddac324d9c13ea012
|
4
|
+
data.tar.gz: 9383e5f306415f9ad9e52c1cc58766fc629ae612644006a794229641a68cc7e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1da6c505691e7a07716c26c57e536f38cae5b4c13a370a9e95e75aeda01e460bb6c9d7e21bc2cc8c226cdba412d064d4a386a8b6418e729af2243913b86c1087
|
7
|
+
data.tar.gz: b72d5dc5173edbeba46427278297f6b5c90d755f5806fa154084faef72978895e1a84ebb2cb3a52401b231b1c73e07c3f90f7268c14d115dc4036cee0632c0c2
|
@@ -5,8 +5,8 @@ on:
|
|
5
5
|
branches:
|
6
6
|
- main
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
# Allows you to run this workflow manually from the Actions tab
|
9
|
+
workflow_dispatch:
|
10
10
|
|
11
11
|
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
|
12
12
|
permissions:
|
@@ -25,9 +25,9 @@ jobs:
|
|
25
25
|
runs-on: ubuntu-latest
|
26
26
|
steps:
|
27
27
|
- name: Checkout
|
28
|
-
uses: actions/checkout@
|
28
|
+
uses: actions/checkout@v4
|
29
29
|
- name: Setup Pages
|
30
|
-
uses: actions/configure-pages@
|
30
|
+
uses: actions/configure-pages@v5
|
31
31
|
- name: Set up Ruby
|
32
32
|
uses: ruby/setup-ruby@v1
|
33
33
|
with:
|
@@ -39,7 +39,7 @@ jobs:
|
|
39
39
|
rdoc --main README.md --op _site --exclude={Gemfile,Rakefile,"coverage/*","vendor/*","bin/*","test/*","tmp/*"}
|
40
40
|
cp -r doc _site/doc
|
41
41
|
- name: Upload artifact
|
42
|
-
uses: actions/upload-pages-artifact@
|
42
|
+
uses: actions/upload-pages-artifact@v3
|
43
43
|
|
44
44
|
# Deployment job
|
45
45
|
deploy:
|
@@ -51,4 +51,4 @@ jobs:
|
|
51
51
|
steps:
|
52
52
|
- name: Deploy to GitHub Pages
|
53
53
|
id: deployment
|
54
|
-
uses: actions/deploy-pages@
|
54
|
+
uses: actions/deploy-pages@v4
|
data/.github/workflows/main.yml
CHANGED
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,sorbet,spec,test/fixtures,vendor,tmp}/**/*'
|
10
|
+
- '{.git,.github,.ruby-lsp,bin,coverage,doc,pkg,sorbet,spec,test/fixtures,vendor,tmp}/**/*'
|
11
11
|
- test.rb
|
12
12
|
|
13
13
|
Gemspec/DevelopmentDependencies:
|
@@ -136,6 +136,9 @@ Style/KeywordParametersOrder:
|
|
136
136
|
Style/MissingRespondToMissing:
|
137
137
|
Enabled: false
|
138
138
|
|
139
|
+
Style/MultipleComparison:
|
140
|
+
Enabled: false
|
141
|
+
|
139
142
|
Style/MutableConstant:
|
140
143
|
Enabled: false
|
141
144
|
|
@@ -154,6 +157,12 @@ Style/ParallelAssignment:
|
|
154
157
|
Style/PerlBackrefs:
|
155
158
|
Enabled: false
|
156
159
|
|
160
|
+
Style/RedundantArrayConstructor:
|
161
|
+
Enabled: false
|
162
|
+
|
163
|
+
Style/RedundantParentheses:
|
164
|
+
Enabled: false
|
165
|
+
|
157
166
|
Style/SafeNavigation:
|
158
167
|
Enabled: false
|
159
168
|
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,30 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [6.3.0] - 2025-07-16
|
10
|
+
|
11
|
+
### Added
|
12
|
+
|
13
|
+
- The `--extension` command line option has been added to the CLI to specify what type of content is coming from stdin.
|
14
|
+
- The `--config` command line option has been added to the CLI to specify the path to the configuration file.
|
15
|
+
|
16
|
+
### Changed
|
17
|
+
|
18
|
+
- Fix formatting of character literals when single quotes is enabled.
|
19
|
+
- Pass ignore files option to the language server.
|
20
|
+
- Hash keys should remain unchanged when there are any omitted values in the hash.
|
21
|
+
- We now properly handle compilation errors in the parser.
|
22
|
+
|
23
|
+
## [6.2.0] - 2023-09-20
|
24
|
+
|
25
|
+
### Added
|
26
|
+
|
27
|
+
- Fix `WithScope` for destructured post arguments.
|
28
|
+
|
29
|
+
### Changed
|
30
|
+
|
31
|
+
- Always use `do`/`end` for multi-line lambdas.
|
32
|
+
|
9
33
|
## [6.1.1] - 2023-03-21
|
10
34
|
|
11
35
|
### Changed
|
@@ -603,7 +627,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
|
|
603
627
|
|
604
628
|
- 🎉 Initial release! 🎉
|
605
629
|
|
606
|
-
[unreleased]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v6.0
|
630
|
+
[unreleased]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v6.2.0...HEAD
|
631
|
+
[6.2.0]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v6.1.1...v6.2.0
|
632
|
+
[6.1.1]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v6.1.0...v6.1.1
|
633
|
+
[6.1.0]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v6.0.2...v6.1.0
|
607
634
|
[6.0.2]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v6.0.1...v6.0.2
|
608
635
|
[6.0.1]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v6.0.0...v6.0.1
|
609
636
|
[6.0.0]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v5.3.0...v6.0.0
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,44 +1,53 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
syntax_tree (6.
|
4
|
+
syntax_tree (6.3.0)
|
5
5
|
prettier_print (>= 1.2.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
ast (2.4.
|
11
|
-
docile (1.4.
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
10
|
+
ast (2.4.3)
|
11
|
+
docile (1.4.1)
|
12
|
+
fiddle (1.1.8)
|
13
|
+
json (2.12.2)
|
14
|
+
language_server-protocol (3.17.0.5)
|
15
|
+
lint_roller (1.1.0)
|
16
|
+
minitest (5.25.5)
|
17
|
+
parallel (1.27.0)
|
18
|
+
parser (3.3.8.0)
|
16
19
|
ast (~> 2.4.1)
|
20
|
+
racc
|
17
21
|
prettier_print (1.2.1)
|
22
|
+
prism (1.4.0)
|
23
|
+
racc (1.8.1)
|
18
24
|
rainbow (3.1.1)
|
19
|
-
rake (13.0
|
20
|
-
regexp_parser (2.
|
21
|
-
|
22
|
-
rubocop (1.48.1)
|
25
|
+
rake (13.3.0)
|
26
|
+
regexp_parser (2.10.0)
|
27
|
+
rubocop (1.78.0)
|
23
28
|
json (~> 2.3)
|
29
|
+
language_server-protocol (~> 3.17.0.2)
|
30
|
+
lint_roller (~> 1.1.0)
|
24
31
|
parallel (~> 1.10)
|
25
|
-
parser (>= 3.
|
32
|
+
parser (>= 3.3.0.2)
|
26
33
|
rainbow (>= 2.2.2, < 4.0)
|
27
|
-
regexp_parser (>=
|
28
|
-
|
29
|
-
rubocop-ast (>= 1.26.0, < 2.0)
|
34
|
+
regexp_parser (>= 2.9.3, < 3.0)
|
35
|
+
rubocop-ast (>= 1.45.1, < 2.0)
|
30
36
|
ruby-progressbar (~> 1.7)
|
31
|
-
unicode-display_width (>= 2.4.0, <
|
32
|
-
rubocop-ast (1.
|
33
|
-
parser (>= 3.
|
37
|
+
unicode-display_width (>= 2.4.0, < 4.0)
|
38
|
+
rubocop-ast (1.45.1)
|
39
|
+
parser (>= 3.3.7.2)
|
40
|
+
prism (~> 1.4)
|
34
41
|
ruby-progressbar (1.13.0)
|
35
42
|
simplecov (0.22.0)
|
36
43
|
docile (~> 1.1)
|
37
44
|
simplecov-html (~> 0.11)
|
38
45
|
simplecov_json_formatter (~> 0.1)
|
39
|
-
simplecov-html (0.
|
46
|
+
simplecov-html (0.13.1)
|
40
47
|
simplecov_json_formatter (0.1.4)
|
41
|
-
unicode-display_width (
|
48
|
+
unicode-display_width (3.1.4)
|
49
|
+
unicode-emoji (~> 4.0, >= 4.0.4)
|
50
|
+
unicode-emoji (4.0.4)
|
42
51
|
|
43
52
|
PLATFORMS
|
44
53
|
arm64-darwin-21
|
@@ -49,6 +58,7 @@ PLATFORMS
|
|
49
58
|
|
50
59
|
DEPENDENCIES
|
51
60
|
bundler
|
61
|
+
fiddle
|
52
62
|
minitest
|
53
63
|
rake
|
54
64
|
rubocop
|
data/README.md
CHANGED
@@ -187,7 +187,7 @@ SyntaxTree::Binary[
|
|
187
187
|
|
188
188
|
### format
|
189
189
|
|
190
|
-
This command will output the formatted version of each of the listed files. Importantly, it will not write that content back to the source files
|
190
|
+
This command will output the formatted version of each of the listed files to stdout. Importantly, it will not write that content back to the source files – for that, you want [`write`](#write).
|
191
191
|
|
192
192
|
```sh
|
193
193
|
stree format path/to/file.rb
|
@@ -297,7 +297,7 @@ Note that the output of the `match` CLI command creates a valid pattern that can
|
|
297
297
|
|
298
298
|
### write
|
299
299
|
|
300
|
-
This command will format the listed files and write that formatted version back to the source files. Note that this overwrites the original content,
|
300
|
+
This command will format the listed files and write that formatted version back to the source files. Note that this overwrites the original content, so be sure to be using a version control system.
|
301
301
|
|
302
302
|
```sh
|
303
303
|
stree write path/to/file.rb
|
@@ -525,7 +525,7 @@ With visitors, you only define handlers for the nodes that you need. You can fin
|
|
525
525
|
* call `visit(child)` with each child that you want to visit
|
526
526
|
* call nothing if you're sure you don't want to descend further
|
527
527
|
|
528
|
-
There are a couple of visitors that ship with Syntax Tree that can be used as examples. They live in the [lib/syntax_tree
|
528
|
+
There are a couple of visitors that ship with Syntax Tree that can be used as examples. They live in the [lib/syntax_tree](lib/syntax_tree) directory.
|
529
529
|
|
530
530
|
### visit_method
|
531
531
|
|
data/lib/syntax_tree/cli.rb
CHANGED
@@ -63,12 +63,13 @@ module SyntaxTree
|
|
63
63
|
class ScriptItem
|
64
64
|
attr_reader :source
|
65
65
|
|
66
|
-
def initialize(source)
|
66
|
+
def initialize(source, extension)
|
67
67
|
@source = source
|
68
|
+
@extension = extension
|
68
69
|
end
|
69
70
|
|
70
71
|
def handler
|
71
|
-
HANDLERS[
|
72
|
+
HANDLERS[@extension]
|
72
73
|
end
|
73
74
|
|
74
75
|
def filepath
|
@@ -82,8 +83,12 @@ module SyntaxTree
|
|
82
83
|
|
83
84
|
# An item of work that correspond to the content passed in via stdin.
|
84
85
|
class STDINItem
|
86
|
+
def initialize(extension)
|
87
|
+
@extension = extension
|
88
|
+
end
|
89
|
+
|
85
90
|
def handler
|
86
|
-
HANDLERS[
|
91
|
+
HANDLERS[@extension]
|
87
92
|
end
|
88
93
|
|
89
94
|
def filepath
|
@@ -159,7 +164,7 @@ module SyntaxTree
|
|
159
164
|
attr_reader :entries
|
160
165
|
|
161
166
|
def initialize(options)
|
162
|
-
super
|
167
|
+
super
|
163
168
|
@entries = []
|
164
169
|
end
|
165
170
|
|
@@ -450,14 +455,26 @@ module SyntaxTree
|
|
450
455
|
#{Color.bold("stree write [--plugins=...] [--print-width=NUMBER] [-e SCRIPT] FILE")}
|
451
456
|
Read, format, and write back the source of the given files
|
452
457
|
|
458
|
+
--ignore-files=...
|
459
|
+
A glob pattern to ignore files when processing. This can be specified
|
460
|
+
multiple times to ignore multiple patterns.
|
461
|
+
|
453
462
|
--plugins=...
|
454
463
|
A comma-separated list of plugins to load.
|
455
464
|
|
456
|
-
--print-width
|
465
|
+
--print-width=...
|
457
466
|
The maximum line width to use when formatting.
|
458
467
|
|
459
|
-
-e
|
460
|
-
Parse an inline
|
468
|
+
-e ...
|
469
|
+
Parse an inline string.
|
470
|
+
|
471
|
+
--extension=...
|
472
|
+
A file extension matching the content passed in via STDIN or -e.
|
473
|
+
Defaults to '.rb'.
|
474
|
+
|
475
|
+
--config=...
|
476
|
+
Path to a configuration file. Defaults to .streerc in the current
|
477
|
+
working directory.
|
461
478
|
HELP
|
462
479
|
|
463
480
|
# This represents all of the options that can be passed to the CLI. It is
|
@@ -468,6 +485,7 @@ module SyntaxTree
|
|
468
485
|
:plugins,
|
469
486
|
:print_width,
|
470
487
|
:scripts,
|
488
|
+
:extension,
|
471
489
|
:target_ruby_version
|
472
490
|
|
473
491
|
def initialize
|
@@ -475,6 +493,7 @@ module SyntaxTree
|
|
475
493
|
@plugins = []
|
476
494
|
@print_width = DEFAULT_PRINT_WIDTH
|
477
495
|
@scripts = []
|
496
|
+
@extension = ".rb"
|
478
497
|
@target_ruby_version = DEFAULT_RUBY_VERSION
|
479
498
|
end
|
480
499
|
|
@@ -523,6 +542,13 @@ module SyntaxTree
|
|
523
542
|
# it and add it to the list of scripts to run.
|
524
543
|
opts.on("-e SCRIPT") { |script| @scripts << script }
|
525
544
|
|
545
|
+
# If there is a extension specified, then parse it and use it for
|
546
|
+
# STDIN and scripts.
|
547
|
+
opts.on("--extension=EXTENSION") do |extension|
|
548
|
+
# Both ".rb" and "rb" are going to work
|
549
|
+
@extension = ".#{extension.delete_prefix(".")}"
|
550
|
+
end
|
551
|
+
|
526
552
|
# If there is a target ruby version specified on the command line,
|
527
553
|
# parse that out and use it when formatting.
|
528
554
|
opts.on("--target-ruby-version=VERSION") do |version|
|
@@ -546,8 +572,16 @@ module SyntaxTree
|
|
546
572
|
|
547
573
|
attr_reader :filepath
|
548
574
|
|
549
|
-
def initialize
|
550
|
-
|
575
|
+
def initialize(filepath = nil)
|
576
|
+
if filepath
|
577
|
+
if File.readable?(filepath)
|
578
|
+
@filepath = filepath
|
579
|
+
else
|
580
|
+
raise ArgumentError, "Invalid configuration file: #{filepath}"
|
581
|
+
end
|
582
|
+
else
|
583
|
+
@filepath = File.join(Dir.pwd, FILENAME)
|
584
|
+
end
|
551
585
|
end
|
552
586
|
|
553
587
|
def exists?
|
@@ -565,8 +599,24 @@ module SyntaxTree
|
|
565
599
|
def run(argv)
|
566
600
|
name, *arguments = argv
|
567
601
|
|
568
|
-
|
569
|
-
|
602
|
+
# First, we need to check if there's a --config option specified
|
603
|
+
# so we can use the custom config file path.
|
604
|
+
config_filepath = nil
|
605
|
+
arguments.each_with_index do |arg, index|
|
606
|
+
if arg.start_with?("--config=")
|
607
|
+
config_filepath = arg.split("=", 2)[1]
|
608
|
+
arguments.delete_at(index)
|
609
|
+
break
|
610
|
+
elsif arg == "--config" && arguments[index + 1]
|
611
|
+
config_filepath = arguments[index + 1]
|
612
|
+
arguments.delete_at(index + 1)
|
613
|
+
arguments.delete_at(index)
|
614
|
+
break
|
615
|
+
end
|
616
|
+
end
|
617
|
+
|
618
|
+
config_file = ConfigFile.new(config_filepath)
|
619
|
+
arguments = config_file.arguments.concat(arguments)
|
570
620
|
|
571
621
|
options = Options.new
|
572
622
|
options.parse(arguments)
|
@@ -593,7 +643,10 @@ module SyntaxTree
|
|
593
643
|
when "j", "json"
|
594
644
|
Json.new(options)
|
595
645
|
when "lsp"
|
596
|
-
LanguageServer.new(
|
646
|
+
LanguageServer.new(
|
647
|
+
print_width: options.print_width,
|
648
|
+
ignore_files: options.ignore_files
|
649
|
+
).run
|
597
650
|
return 0
|
598
651
|
when "m", "match"
|
599
652
|
Match.new(options)
|
@@ -630,9 +683,11 @@ module SyntaxTree
|
|
630
683
|
end
|
631
684
|
end
|
632
685
|
|
633
|
-
options.scripts.each
|
686
|
+
options.scripts.each do |script|
|
687
|
+
queue << ScriptItem.new(script, options.extension)
|
688
|
+
end
|
634
689
|
else
|
635
|
-
queue << STDINItem.new
|
690
|
+
queue << STDINItem.new(options.extension)
|
636
691
|
end
|
637
692
|
|
638
693
|
# At the end, we're going to return whether or not this worker ever
|