syntax_tree 6.0.1 → 6.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/tasks/sorbet.rake CHANGED
@@ -20,6 +20,26 @@ module SyntaxTree
20
20
  generate_parent
21
21
  Reflection.nodes.sort.each { |(_, node)| generate_node(node) }
22
22
 
23
+ body << ClassDeclaration(
24
+ ConstPathRef(VarRef(Const("SyntaxTree")), Const("BasicVisitor")),
25
+ nil,
26
+ BodyStmt(
27
+ Statements(generate_visitor("overridable")),
28
+ nil,
29
+ nil,
30
+ nil,
31
+ nil
32
+ ),
33
+ location
34
+ )
35
+
36
+ body << ClassDeclaration(
37
+ ConstPathRef(VarRef(Const("SyntaxTree")), Const("Visitor")),
38
+ ConstPathRef(VarRef(Const("SyntaxTree")), Const("BasicVisitor")),
39
+ BodyStmt(Statements(generate_visitor("override")), nil, nil, nil, nil),
40
+ location
41
+ )
42
+
23
43
  Formatter.format(nil, Program(Statements(body)))
24
44
  end
25
45
 
@@ -122,8 +142,41 @@ module SyntaxTree
122
142
  @line += 1
123
143
 
124
144
  node_body << generate_def_node("child_nodes", nil)
145
+ @line += 2
146
+
147
+ node_body << sig_block do
148
+ CallNode(
149
+ sig_params do
150
+ BareAssocHash(
151
+ [
152
+ Assoc(
153
+ Label("other:"),
154
+ CallNode(
155
+ VarRef(Const("T")),
156
+ Period("."),
157
+ Ident("untyped"),
158
+ nil
159
+ )
160
+ )
161
+ ]
162
+ )
163
+ end,
164
+ Period("."),
165
+ sig_returns { ConstPathRef(VarRef(Const("T")), Const("Boolean")) },
166
+ nil
167
+ )
168
+ end
125
169
  @line += 1
126
170
 
171
+ node_body << generate_def_node(
172
+ "==",
173
+ Paren(
174
+ LParen("("),
175
+ Params.new(location: location, requireds: [Ident("other")])
176
+ )
177
+ )
178
+ @line += 2
179
+
127
180
  node_body
128
181
  end
129
182
 
@@ -195,6 +248,49 @@ module SyntaxTree
195
248
  )
196
249
  end
197
250
 
251
+ def generate_visitor(override)
252
+ body = []
253
+
254
+ Reflection.nodes.each do |name, node|
255
+ body << sig_block do
256
+ CallNode(
257
+ CallNode(
258
+ Ident(override),
259
+ Period("."),
260
+ sig_params do
261
+ BareAssocHash(
262
+ [
263
+ Assoc(
264
+ Label("node:"),
265
+ sig_type_for(SyntaxTree.const_get(name))
266
+ )
267
+ ]
268
+ )
269
+ end,
270
+ nil
271
+ ),
272
+ Period("."),
273
+ sig_returns do
274
+ CallNode(VarRef(Const("T")), Period("."), Ident("untyped"), nil)
275
+ end,
276
+ nil
277
+ )
278
+ end
279
+
280
+ body << generate_def_node(
281
+ node.visitor_method,
282
+ Paren(
283
+ LParen("("),
284
+ Params.new(requireds: [Ident("node")], location: location)
285
+ )
286
+ )
287
+
288
+ @line += 2
289
+ end
290
+
291
+ body
292
+ end
293
+
198
294
  def sig_block
199
295
  MethodAddBlock(
200
296
  CallNode(nil, nil, Ident("sig"), nil),
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.1
4
+ version: 6.1.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: 2023-02-26 00:00:00.000000000 Z
11
+ date: 2023-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: prettier_print
@@ -110,6 +110,7 @@ files:
110
110
  - ".github/workflows/main.yml"
111
111
  - ".gitignore"
112
112
  - ".rubocop.yml"
113
+ - ".ruby-version"
113
114
  - CHANGELOG.md
114
115
  - CODE_OF_CONDUCT.md
115
116
  - Gemfile