syntax_tree 6.0.1 → 6.0.2
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/CHANGELOG.md +14 -1
- data/Gemfile.lock +4 -4
- data/lib/syntax_tree/field_visitor.rb +2 -0
- data/lib/syntax_tree/parser.rb +6 -0
- data/lib/syntax_tree/reflection.rb +2 -1
- data/lib/syntax_tree/version.rb +1 -1
- data/lib/syntax_tree/with_scope.rb +71 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 20b5dfab3c47b63217fc1b3a6f1fbbd56f51e8358e4b3514e6bf8fd9da083ed6
|
4
|
+
data.tar.gz: f4c18e39ae2b5cb14aae4de6d95494959d41ac78757b01da621b68d514c59bfb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35bff4e2d47a2141e5014771cd30f268408e44ff59d247895dc52bee18f4ff7ebcd163e6ce464eb9908e2027ac7a86785cd5c5573baadfaadb3f690e3689526d
|
7
|
+
data.tar.gz: 82722a335946c31d43753a51efc954e8f28a4e39015dd01c3a983f7cdcd6f2dff9e90cb9046b00c2508ee6d9654e33f1760e40c9b1fd70fdf6343fa74855f8b1
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,18 @@ 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.0.2] - 2023-03-03
|
10
|
+
|
11
|
+
### Added
|
12
|
+
|
13
|
+
- The `WithScope` visitor mixin will now additionally report local variables defined through regular expression named captures.
|
14
|
+
- The `WithScope` visitor mixin now properly handles destructured splat arguments in required positions.
|
15
|
+
|
16
|
+
### Changed
|
17
|
+
|
18
|
+
- Fixed the AST output by adding blocks to `Command` and `CommandCall` nodes in the `FieldVisitor`.
|
19
|
+
- Fixed the location of lambda local variables (e.g., `->(; a) {}`).
|
20
|
+
|
9
21
|
## [6.0.1] - 2023-02-26
|
10
22
|
|
11
23
|
### Added
|
@@ -572,7 +584,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
|
|
572
584
|
|
573
585
|
- 🎉 Initial release! 🎉
|
574
586
|
|
575
|
-
[unreleased]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v6.0.
|
587
|
+
[unreleased]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v6.0.2...HEAD
|
588
|
+
[6.0.2]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v6.0.1...v6.0.2
|
576
589
|
[6.0.1]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v6.0.0...v6.0.1
|
577
590
|
[6.0.0]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v5.3.0...v6.0.0
|
578
591
|
[5.3.0]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v5.2.0...v5.3.0
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
syntax_tree (6.0.
|
4
|
+
syntax_tree (6.0.2)
|
5
5
|
prettier_print (>= 1.2.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -19,7 +19,7 @@ GEM
|
|
19
19
|
rake (13.0.6)
|
20
20
|
regexp_parser (2.7.0)
|
21
21
|
rexml (3.2.5)
|
22
|
-
rubocop (1.
|
22
|
+
rubocop (1.47.0)
|
23
23
|
json (~> 2.3)
|
24
24
|
parallel (~> 1.10)
|
25
25
|
parser (>= 3.2.0.0)
|
@@ -29,9 +29,9 @@ GEM
|
|
29
29
|
rubocop-ast (>= 1.26.0, < 2.0)
|
30
30
|
ruby-progressbar (~> 1.7)
|
31
31
|
unicode-display_width (>= 2.4.0, < 3.0)
|
32
|
-
rubocop-ast (1.
|
32
|
+
rubocop-ast (1.27.0)
|
33
33
|
parser (>= 3.2.1.0)
|
34
|
-
ruby-progressbar (1.
|
34
|
+
ruby-progressbar (1.12.0)
|
35
35
|
simplecov (0.22.0)
|
36
36
|
docile (~> 1.1)
|
37
37
|
simplecov-html (~> 0.11)
|
@@ -263,6 +263,7 @@ module SyntaxTree
|
|
263
263
|
node(node, "command") do
|
264
264
|
field("message", node.message)
|
265
265
|
field("arguments", node.arguments)
|
266
|
+
field("block", node.block) if node.block
|
266
267
|
comments(node)
|
267
268
|
end
|
268
269
|
end
|
@@ -273,6 +274,7 @@ module SyntaxTree
|
|
273
274
|
field("operator", node.operator)
|
274
275
|
field("message", node.message)
|
275
276
|
field("arguments", node.arguments) if node.arguments
|
277
|
+
field("block", node.block) if node.block
|
276
278
|
comments(node)
|
277
279
|
end
|
278
280
|
end
|
data/lib/syntax_tree/parser.rb
CHANGED
@@ -2391,8 +2391,14 @@ module SyntaxTree
|
|
2391
2391
|
}
|
2392
2392
|
}
|
2393
2393
|
|
2394
|
+
parent_line = lineno - 1
|
2395
|
+
parent_column =
|
2396
|
+
consume_token(Semicolon).location.start_column - tokens[index][0][1]
|
2397
|
+
|
2394
2398
|
tokens[(index + 1)..].each_with_object([]) do |token, locals|
|
2395
2399
|
(lineno, column), type, value, = token
|
2400
|
+
column += parent_column if lineno == 1
|
2401
|
+
lineno += parent_line
|
2396
2402
|
|
2397
2403
|
# Make the state transition for the parser. If there isn't a transition
|
2398
2404
|
# from the current state to a new state for this type, then we're in a
|
@@ -176,7 +176,8 @@ module SyntaxTree
|
|
176
176
|
program =
|
177
177
|
SyntaxTree.parse(SyntaxTree.read(File.expand_path("node.rb", __dir__)))
|
178
178
|
|
179
|
-
|
179
|
+
program_statements = program.statements
|
180
|
+
main_statements = program_statements.body.last.bodystmt.statements.body
|
180
181
|
main_statements.each_with_index do |main_statement, main_statement_index|
|
181
182
|
# Ensure we are only looking at class declarations.
|
182
183
|
next unless main_statement.is_a?(SyntaxTree::ClassDeclaration)
|
data/lib/syntax_tree/version.rb
CHANGED
@@ -189,6 +189,15 @@ module SyntaxTree
|
|
189
189
|
super
|
190
190
|
end
|
191
191
|
|
192
|
+
def visit_block_var(node)
|
193
|
+
node.locals.each do |local|
|
194
|
+
current_scope.add_local_definition(local, :variable)
|
195
|
+
end
|
196
|
+
|
197
|
+
super
|
198
|
+
end
|
199
|
+
alias visit_lambda_var visit_block_var
|
200
|
+
|
192
201
|
# Visit for keeping track of local variable definitions
|
193
202
|
def visit_var_field(node)
|
194
203
|
value = node.value
|
@@ -217,11 +226,72 @@ module SyntaxTree
|
|
217
226
|
super
|
218
227
|
end
|
219
228
|
|
229
|
+
# When using regex named capture groups, vcalls might actually be a variable
|
230
|
+
def visit_vcall(node)
|
231
|
+
value = node.value
|
232
|
+
definition = current_scope.find_local(value.value)
|
233
|
+
current_scope.add_local_usage(value, definition.type) if definition
|
234
|
+
|
235
|
+
super
|
236
|
+
end
|
237
|
+
|
238
|
+
# Visit for capturing local variables defined in regex named capture groups
|
239
|
+
def visit_binary(node)
|
240
|
+
if node.operator == :=~
|
241
|
+
left = node.left
|
242
|
+
|
243
|
+
if left.is_a?(RegexpLiteral) && left.parts.length == 1 &&
|
244
|
+
left.parts.first.is_a?(TStringContent)
|
245
|
+
content = left.parts.first
|
246
|
+
|
247
|
+
value = content.value
|
248
|
+
location = content.location
|
249
|
+
start_line = location.start_line
|
250
|
+
|
251
|
+
Regexp
|
252
|
+
.new(value, Regexp::FIXEDENCODING)
|
253
|
+
.names
|
254
|
+
.each do |name|
|
255
|
+
offset = value.index(/\(\?<#{Regexp.escape(name)}>/)
|
256
|
+
line = start_line + value[0...offset].count("\n")
|
257
|
+
|
258
|
+
# We need to add 3 to account for these three characters
|
259
|
+
# prefixing a named capture (?<
|
260
|
+
column = location.start_column + offset + 3
|
261
|
+
if value[0...offset].include?("\n")
|
262
|
+
column =
|
263
|
+
value[0...offset].length - value[0...offset].rindex("\n") +
|
264
|
+
3 - 1
|
265
|
+
end
|
266
|
+
|
267
|
+
ident_location =
|
268
|
+
Location.new(
|
269
|
+
start_line: line,
|
270
|
+
start_char: location.start_char + offset,
|
271
|
+
start_column: column,
|
272
|
+
end_line: line,
|
273
|
+
end_char: location.start_char + offset + name.length,
|
274
|
+
end_column: column + name.length
|
275
|
+
)
|
276
|
+
|
277
|
+
identifier = Ident.new(value: name, location: ident_location)
|
278
|
+
current_scope.add_local_definition(identifier, :variable)
|
279
|
+
end
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
super
|
284
|
+
end
|
285
|
+
|
220
286
|
private
|
221
287
|
|
222
288
|
def add_argument_definitions(list)
|
223
289
|
list.each do |param|
|
224
|
-
|
290
|
+
case param
|
291
|
+
when ArgStar
|
292
|
+
value = param.value
|
293
|
+
current_scope.add_local_definition(value, :argument) if value
|
294
|
+
when MLHSParen
|
225
295
|
add_argument_definitions(param.contents.parts)
|
226
296
|
else
|
227
297
|
current_scope.add_local_definition(param, :argument)
|
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: 6.0.
|
4
|
+
version: 6.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Newton
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: prettier_print
|