syntax_tree 2.3.1 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/main.yml +20 -1
- data/.rubocop.yml +80 -0
- data/CHANGELOG.md +19 -1
- data/Gemfile +2 -0
- data/Gemfile.lock +22 -1
- data/README.md +113 -0
- data/Rakefile +27 -5
- data/config/rubocop.yml +64 -0
- data/lib/syntax_tree/cli.rb +63 -27
- data/lib/syntax_tree/formatter.rb +6 -5
- data/lib/syntax_tree/language_server/inlay_hints.rb +87 -38
- data/lib/syntax_tree/language_server.rb +50 -14
- data/lib/syntax_tree/node.rb +494 -305
- data/lib/syntax_tree/parser.rb +439 -110
- data/lib/syntax_tree/prettyprint.rb +28 -25
- data/lib/syntax_tree/version.rb +1 -1
- data/lib/syntax_tree/visitor/field_visitor.rb +1115 -0
- data/lib/syntax_tree/visitor/json_visitor.rb +25 -1305
- data/lib/syntax_tree/visitor/match_visitor.rb +122 -0
- data/lib/syntax_tree/visitor/pretty_print_visitor.rb +35 -1163
- data/lib/syntax_tree/visitor.rb +6 -1
- data/lib/syntax_tree.rb +19 -1
- data/syntax_tree.gemspec +21 -19
- metadata +7 -3
data/lib/syntax_tree/visitor.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module SyntaxTree
|
4
|
+
# Visitor is a parent class that provides the ability to walk down the tree
|
5
|
+
# and handle a subset of nodes. By defining your own subclass, you can
|
6
|
+
# explicitly handle a node type by defining a visit_* method.
|
4
7
|
class Visitor
|
5
8
|
# This is raised when you use the Visitor.visit_method method and it fails.
|
6
9
|
# It is correctable to through DidYouMean.
|
@@ -24,7 +27,9 @@ module SyntaxTree
|
|
24
27
|
|
25
28
|
def corrections
|
26
29
|
@corrections ||=
|
27
|
-
DidYouMean::SpellChecker.new(
|
30
|
+
DidYouMean::SpellChecker.new(
|
31
|
+
dictionary: Visitor.visit_methods
|
32
|
+
).correct(visit_method)
|
28
33
|
end
|
29
34
|
|
30
35
|
DidYouMean.correct_error(VisitMethodError, self)
|
data/lib/syntax_tree.rb
CHANGED
@@ -11,7 +11,9 @@ require_relative "syntax_tree/node"
|
|
11
11
|
require_relative "syntax_tree/parser"
|
12
12
|
require_relative "syntax_tree/version"
|
13
13
|
require_relative "syntax_tree/visitor"
|
14
|
+
require_relative "syntax_tree/visitor/field_visitor"
|
14
15
|
require_relative "syntax_tree/visitor/json_visitor"
|
16
|
+
require_relative "syntax_tree/visitor/match_visitor"
|
15
17
|
require_relative "syntax_tree/visitor/pretty_print_visitor"
|
16
18
|
|
17
19
|
# If PrettyPrint::Align isn't defined, then we haven't gotten the updated
|
@@ -28,6 +30,20 @@ unless PrettyPrint.const_defined?(:Align)
|
|
28
30
|
end
|
29
31
|
end
|
30
32
|
|
33
|
+
# When PP is running, it expects that everything that interacts with it is going
|
34
|
+
# to flow through PP.pp, since that's the main entry into the module from the
|
35
|
+
# perspective of its uses in core Ruby. In doing so, it calls guard_inspect_key
|
36
|
+
# at the top of the PP.pp method, which establishes some thread-local hashes to
|
37
|
+
# check for cycles in the pretty printed tree. This means that if you want to
|
38
|
+
# manually call pp on some object _before_ you have established these hashes,
|
39
|
+
# you're going to break everything. So this call ensures that those hashes have
|
40
|
+
# been set up before anything uses pp manually.
|
41
|
+
PP.new(+"", 0).guard_inspect_key {}
|
42
|
+
|
43
|
+
# Syntax Tree is a suite of tools built on top of the internal CRuby parser. It
|
44
|
+
# provides the ability to generate a syntax tree from source, as well as the
|
45
|
+
# tools necessary to inspect and manipulate that syntax tree. It can be used to
|
46
|
+
# build formatters, linters, language servers, and more.
|
31
47
|
module SyntaxTree
|
32
48
|
# This holds references to objects that respond to both #parse and #format
|
33
49
|
# so that we can use them in the CLI.
|
@@ -61,8 +77,10 @@ module SyntaxTree
|
|
61
77
|
def self.read(filepath)
|
62
78
|
encoding =
|
63
79
|
File.open(filepath, "r") do |file|
|
80
|
+
break Encoding.default_external if file.eof?
|
81
|
+
|
64
82
|
header = file.readline
|
65
|
-
header += file.readline if header.start_with?("#!")
|
83
|
+
header += file.readline if !file.eof? && header.start_with?("#!")
|
66
84
|
Ripper.new(header).tap(&:parse).encoding
|
67
85
|
end
|
68
86
|
|
data/syntax_tree.gemspec
CHANGED
@@ -1,30 +1,32 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
3
|
+
require_relative "lib/syntax_tree/version"
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
|
-
spec.name
|
7
|
-
spec.version
|
8
|
-
spec.authors
|
9
|
-
spec.email
|
6
|
+
spec.name = "syntax_tree"
|
7
|
+
spec.version = SyntaxTree::VERSION
|
8
|
+
spec.authors = ["Kevin Newton"]
|
9
|
+
spec.email = ["kddnewton@gmail.com"]
|
10
10
|
|
11
|
-
spec.summary
|
12
|
-
spec.homepage
|
13
|
-
spec.license
|
14
|
-
spec.metadata
|
11
|
+
spec.summary = "A parser based on ripper"
|
12
|
+
spec.homepage = "https://github.com/kddnewton/syntax_tree"
|
13
|
+
spec.license = "MIT"
|
14
|
+
spec.metadata = { "rubygems_mfa_required" => "true" }
|
15
15
|
|
16
|
-
spec.files
|
17
|
-
|
18
|
-
|
16
|
+
spec.files =
|
17
|
+
Dir.chdir(__dir__) do
|
18
|
+
`git ls-files -z`.split("\x0")
|
19
|
+
.reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
20
|
end
|
20
|
-
end
|
21
21
|
|
22
|
-
spec.
|
23
|
-
|
22
|
+
spec.required_ruby_version = ">= 2.7.3"
|
23
|
+
|
24
|
+
spec.bindir = "exe"
|
25
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
26
|
spec.require_paths = %w[lib]
|
25
27
|
|
26
|
-
spec.add_development_dependency
|
27
|
-
spec.add_development_dependency
|
28
|
-
spec.add_development_dependency
|
29
|
-
spec.add_development_dependency
|
28
|
+
spec.add_development_dependency "bundler"
|
29
|
+
spec.add_development_dependency "minitest"
|
30
|
+
spec.add_development_dependency "rake"
|
31
|
+
spec.add_development_dependency "simplecov"
|
30
32
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: syntax_tree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Newton
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -78,6 +78,7 @@ files:
|
|
78
78
|
- ".github/workflows/gh-pages.yml"
|
79
79
|
- ".github/workflows/main.yml"
|
80
80
|
- ".gitignore"
|
81
|
+
- ".rubocop.yml"
|
81
82
|
- CHANGELOG.md
|
82
83
|
- CODE_OF_CONDUCT.md
|
83
84
|
- Gemfile
|
@@ -88,6 +89,7 @@ files:
|
|
88
89
|
- bin/bench
|
89
90
|
- bin/console
|
90
91
|
- bin/profile
|
92
|
+
- config/rubocop.yml
|
91
93
|
- doc/logo.svg
|
92
94
|
- exe/stree
|
93
95
|
- lib/syntax_tree.rb
|
@@ -100,7 +102,9 @@ files:
|
|
100
102
|
- lib/syntax_tree/prettyprint.rb
|
101
103
|
- lib/syntax_tree/version.rb
|
102
104
|
- lib/syntax_tree/visitor.rb
|
105
|
+
- lib/syntax_tree/visitor/field_visitor.rb
|
103
106
|
- lib/syntax_tree/visitor/json_visitor.rb
|
107
|
+
- lib/syntax_tree/visitor/match_visitor.rb
|
104
108
|
- lib/syntax_tree/visitor/pretty_print_visitor.rb
|
105
109
|
- syntax_tree.gemspec
|
106
110
|
homepage: https://github.com/kddnewton/syntax_tree
|
@@ -116,7 +120,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
116
120
|
requirements:
|
117
121
|
- - ">="
|
118
122
|
- !ruby/object:Gem::Version
|
119
|
-
version:
|
123
|
+
version: 2.7.3
|
120
124
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
125
|
requirements:
|
122
126
|
- - ">="
|