rephrase 0.2 → 0.3
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 +7 -3
- data/lib/rephrase/version.rb +1 -1
- data/lib/rephrase.rb +45 -39
- metadata +31 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fff798527479ef2c51091ce5358d97f744439765c654efe86bf076ea3b71f66a
|
4
|
+
data.tar.gz: d5b22bfc4f8155b67aa384eef563d099e2b7c9baef0b59515d0fb4f68230e771
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4d6310d5dd1f17bc8a234689e647dbf63dd6eac0139ddb7b8bfc4587f23919fa54ff717f51b5bf600d230180205c0aa173a56d9cbb595ea6c25742af42501d4
|
7
|
+
data.tar.gz: e0626f72497824c948f447dc8b7f32fdec3ac2f065ef7f5ab83b22ef48d24b823e33f88811aa9eb9a8ecea6b00cd6ee29985996baef95e58a2e17fc64287638f
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,12 @@
|
|
1
|
+
## 0.3 2011-11-17
|
2
|
+
|
3
|
+
- Improve documentation.
|
4
|
+
|
1
5
|
## 0.2 2011-11-16
|
2
6
|
|
3
|
-
- Rename `#to_ruby` to `#to_source
|
4
|
-
- Add documentation
|
7
|
+
- Rename `#to_ruby` to `#to_source`.
|
8
|
+
- Add documentation.
|
5
9
|
|
6
10
|
## 0.1 2021-11-16
|
7
11
|
|
8
|
-
- First working version
|
12
|
+
- First working version.
|
data/lib/rephrase/version.rb
CHANGED
data/lib/rephrase.rb
CHANGED
@@ -6,21 +6,27 @@
|
|
6
6
|
class Rephrase
|
7
7
|
# Class for faking a node
|
8
8
|
class FakeNode
|
9
|
-
# Constructs a FakeNode with type `:LIST_EMBEDDED
|
9
|
+
# Constructs a FakeNode with type `:LIST_EMBEDDED`.
|
10
10
|
# @param children [Array] child nodes
|
11
11
|
def self.list(children)
|
12
12
|
new(:LIST_EMBEDDED, children)
|
13
13
|
end
|
14
14
|
|
15
|
-
# Constructs a FakeNode with type `:ITER_SCOPE
|
15
|
+
# Constructs a FakeNode with type `:ITER_SCOPE`.
|
16
16
|
# @param children [Array] child nodes
|
17
17
|
def self.iter_scope(children)
|
18
18
|
new(:ITER_SCOPE, children)
|
19
19
|
end
|
20
20
|
|
21
|
-
|
21
|
+
# Node type
|
22
|
+
# @return [Symbol]
|
23
|
+
attr_reader :type
|
24
|
+
|
25
|
+
# Node children
|
26
|
+
# @return [Array]
|
27
|
+
attr_reader :children
|
22
28
|
|
23
|
-
# Initializes a FakeNode
|
29
|
+
# Initializes a FakeNode.
|
24
30
|
# @param type [Symbol] node type
|
25
31
|
# @param children [Array] child nodes
|
26
32
|
def initialize(type, children)
|
@@ -29,7 +35,7 @@ class Rephrase
|
|
29
35
|
end
|
30
36
|
end
|
31
37
|
|
32
|
-
# Converts a
|
38
|
+
# Converts a block or method to its source code.
|
33
39
|
# @param code [Proc, BoundMethod, UnboundMethod] proc or method
|
34
40
|
# @return [String] converted source code
|
35
41
|
def self.to_source(code)
|
@@ -37,7 +43,7 @@ class Rephrase
|
|
37
43
|
new.convert({}, ast)
|
38
44
|
end
|
39
45
|
|
40
|
-
# Pretty-prints an AST
|
46
|
+
# Pretty-prints an AST.
|
41
47
|
# @param node [RubyVM::AbstractSyntaxTree::Node] AST node
|
42
48
|
def self.pp_ast(node, level = 0)
|
43
49
|
case node
|
@@ -54,7 +60,7 @@ class Rephrase
|
|
54
60
|
end
|
55
61
|
end
|
56
62
|
|
57
|
-
# Converts an AST node to a string containing its source code
|
63
|
+
# Converts an AST node to a string containing its source code.
|
58
64
|
# @param ctx [Hash] context object
|
59
65
|
# @param node [RubyVM::AbstractSyntaxTree::Node] AST node
|
60
66
|
# @return [String] source code
|
@@ -71,7 +77,7 @@ class Rephrase
|
|
71
77
|
ctx[:buffer]
|
72
78
|
end
|
73
79
|
|
74
|
-
# Converts a
|
80
|
+
# Converts a `:SCOPE` AST node.
|
75
81
|
# @param ctx [Hash] context object
|
76
82
|
# @param node [RubyVM::AbstractSyntaxTree::Node] AST node
|
77
83
|
def on_scope(ctx, node)
|
@@ -82,7 +88,7 @@ class Rephrase
|
|
82
88
|
emit(ctx, "proc do", [body], "end")
|
83
89
|
end
|
84
90
|
|
85
|
-
# Converts a
|
91
|
+
# Converts a `:BLOCK` AST node.
|
86
92
|
# @param ctx [Hash] context object
|
87
93
|
# @param node [RubyVM::AbstractSyntaxTree::Node] AST node
|
88
94
|
def on_block(ctx, node)
|
@@ -93,7 +99,7 @@ class Rephrase
|
|
93
99
|
end
|
94
100
|
end
|
95
101
|
|
96
|
-
# Converts a
|
102
|
+
# Converts a `:ITER` AST node.
|
97
103
|
# @param ctx [Hash] context object
|
98
104
|
# @param node [RubyVM::AbstractSyntaxTree::Node] AST node
|
99
105
|
def on_iter(ctx, node)
|
@@ -102,7 +108,7 @@ class Rephrase
|
|
102
108
|
emit(ctx, FakeNode.iter_scope(scope.children))
|
103
109
|
end
|
104
110
|
|
105
|
-
# Converts a
|
111
|
+
# Converts a `:ITER_SCOPE` AST (fake) node.
|
106
112
|
# @param ctx [Hash] context object
|
107
113
|
# @param node [Rephrase::FakeNode] AST node
|
108
114
|
def on_iter_scope(ctx, node)
|
@@ -114,14 +120,14 @@ class Rephrase
|
|
114
120
|
emit(ctx, "\nend")
|
115
121
|
end
|
116
122
|
|
117
|
-
# Converts a
|
123
|
+
# Converts a `:CONST` AST node.
|
118
124
|
# @param ctx [Hash] context object
|
119
125
|
# @param node [RubyVM::AbstractSyntaxTree::Node] AST node
|
120
126
|
def on_const(ctx, node)
|
121
127
|
emit(ctx, node.children.first.to_s)
|
122
128
|
end
|
123
129
|
|
124
|
-
# Converts a
|
130
|
+
# Converts a `:COLON2` AST node.
|
125
131
|
# @param ctx [Hash] context object
|
126
132
|
# @param node [RubyVM::AbstractSyntaxTree::Node] AST node
|
127
133
|
def on_colon2(ctx, node)
|
@@ -129,7 +135,7 @@ class Rephrase
|
|
129
135
|
emit(ctx, left, "::", right.to_s)
|
130
136
|
end
|
131
137
|
|
132
|
-
# Converts a
|
138
|
+
# Converts a `:CALL` AST node.
|
133
139
|
# @param ctx [Hash] context object
|
134
140
|
# @param node [RubyVM::AbstractSyntaxTree::Node] AST node
|
135
141
|
def on_call(ctx, node)
|
@@ -147,7 +153,7 @@ class Rephrase
|
|
147
153
|
end
|
148
154
|
end
|
149
155
|
|
150
|
-
# Converts a
|
156
|
+
# Converts a `:FCALL` AST node.
|
151
157
|
# @param ctx [Hash] context object
|
152
158
|
# @param node [RubyVM::AbstractSyntaxTree::Node] AST node
|
153
159
|
def on_fcall(ctx, node)
|
@@ -156,14 +162,14 @@ class Rephrase
|
|
156
162
|
emit(ctx, "#{method}(", args, ")")
|
157
163
|
end
|
158
164
|
|
159
|
-
# Converts a
|
165
|
+
# Converts a `:VCALL` AST node.
|
160
166
|
# @param ctx [Hash] context object
|
161
167
|
# @param node [RubyVM::AbstractSyntaxTree::Node] AST node
|
162
168
|
def on_vcall(ctx, node)
|
163
169
|
emit(ctx, node.children.first.to_s, "()")
|
164
170
|
end
|
165
171
|
|
166
|
-
# Converts a
|
172
|
+
# Converts a `:OPCALL` AST node.
|
167
173
|
# @param ctx [Hash] context object
|
168
174
|
# @param node [RubyVM::AbstractSyntaxTree::Node] AST node
|
169
175
|
def on_opcall(ctx, node)
|
@@ -175,7 +181,7 @@ class Rephrase
|
|
175
181
|
end
|
176
182
|
end
|
177
183
|
|
178
|
-
# Converts a
|
184
|
+
# Converts a `:DASGN_CURR` AST node.
|
179
185
|
# @param ctx [Hash] context object
|
180
186
|
# @param node [RubyVM::AbstractSyntaxTree::Node] AST node
|
181
187
|
def on_dasgn_curr(ctx, node)
|
@@ -183,7 +189,7 @@ class Rephrase
|
|
183
189
|
emit(ctx, left.to_s, " = ", right)
|
184
190
|
end
|
185
191
|
|
186
|
-
# Converts a
|
192
|
+
# Converts a `:IASGN` AST node.
|
187
193
|
# @param ctx [Hash] context object
|
188
194
|
# @param node [RubyVM::AbstractSyntaxTree::Node] AST node
|
189
195
|
def on_iasgn(ctx, node)
|
@@ -191,7 +197,7 @@ class Rephrase
|
|
191
197
|
emit(ctx, left.to_s, " = ", right)
|
192
198
|
end
|
193
199
|
|
194
|
-
# Converts a
|
200
|
+
# Converts a `:IF AST` node.
|
195
201
|
# @param ctx [Hash] context object
|
196
202
|
# @param node [RubyVM::AbstractSyntaxTree::Node] AST node
|
197
203
|
def on_if(ctx, node)
|
@@ -203,7 +209,7 @@ class Rephrase
|
|
203
209
|
end
|
204
210
|
end
|
205
211
|
|
206
|
-
# Converts a
|
212
|
+
# Converts a `:UNLESS` AST node.
|
207
213
|
# @param ctx [Hash] context object
|
208
214
|
# @param node [RubyVM::AbstractSyntaxTree::Node] AST node
|
209
215
|
def on_unless(ctx, node)
|
@@ -215,7 +221,7 @@ class Rephrase
|
|
215
221
|
end
|
216
222
|
end
|
217
223
|
|
218
|
-
# Converts a
|
224
|
+
# Converts a `:WHILE` AST node.
|
219
225
|
# @param ctx [Hash] context object
|
220
226
|
# @param node [RubyVM::AbstractSyntaxTree::Node] AST node
|
221
227
|
def on_while(ctx, node)
|
@@ -223,56 +229,56 @@ class Rephrase
|
|
223
229
|
emit(ctx, "while ", cond, "\n", body, "\nend")
|
224
230
|
end
|
225
231
|
|
226
|
-
# Converts a
|
232
|
+
# Converts a `:LIT` AST node.
|
227
233
|
# @param ctx [Hash] context object
|
228
234
|
# @param node [RubyVM::AbstractSyntaxTree::Node] AST node
|
229
235
|
def on_lit(ctx, node)
|
230
236
|
emit(ctx, node.children.first.inspect)
|
231
237
|
end
|
232
238
|
|
233
|
-
# Converts a
|
239
|
+
# Converts a `:NIL` AST node.
|
234
240
|
# @param ctx [Hash] context object
|
235
241
|
# @param node [RubyVM::AbstractSyntaxTree::Node] AST node
|
236
242
|
def on_nil(ctx, node)
|
237
243
|
emit(ctx, "nil")
|
238
244
|
end
|
239
245
|
|
240
|
-
# Converts a
|
246
|
+
# Converts a `:TRUE` AST node.
|
241
247
|
# @param ctx [Hash] context object
|
242
248
|
# @param node [RubyVM::AbstractSyntaxTree::Node] AST node
|
243
249
|
def on_true(ctx, node)
|
244
250
|
emit(ctx, "true")
|
245
251
|
end
|
246
252
|
|
247
|
-
# Converts a
|
253
|
+
# Converts a `:FALSE` AST node.
|
248
254
|
# @param ctx [Hash] context object
|
249
255
|
# @param node [RubyVM::AbstractSyntaxTree::Node] AST node
|
250
256
|
def on_false(ctx, node)
|
251
257
|
emit(ctx, "false")
|
252
258
|
end
|
253
259
|
|
254
|
-
# Converts a
|
260
|
+
# Converts a `:DVAR` AST node.
|
255
261
|
# @param ctx [Hash] context object
|
256
262
|
# @param node [RubyVM::AbstractSyntaxTree::Node] AST node
|
257
263
|
def on_dvar(ctx, node)
|
258
264
|
emit(ctx, node.children.first.to_s)
|
259
265
|
end
|
260
266
|
|
261
|
-
# Converts a
|
267
|
+
# Converts a `:IVAR` AST node.
|
262
268
|
# @param ctx [Hash] context object
|
263
269
|
# @param node [RubyVM::AbstractSyntaxTree::Node] AST node
|
264
270
|
def on_ivar(ctx, node)
|
265
271
|
emit(ctx, node.children.first.to_s)
|
266
272
|
end
|
267
273
|
|
268
|
-
# Converts a
|
274
|
+
# Converts a `:STR` AST node.
|
269
275
|
# @param ctx [Hash] context object
|
270
276
|
# @param node [RubyVM::AbstractSyntaxTree::Node] AST node
|
271
277
|
def on_str(ctx, node)
|
272
278
|
emit(ctx, node.children.first.inspect)
|
273
279
|
end
|
274
280
|
|
275
|
-
# Converts a
|
281
|
+
# Converts a `:DSTR` AST node.
|
276
282
|
# @param ctx [Hash] context object
|
277
283
|
# @param node [RubyVM::AbstractSyntaxTree::Node] AST node
|
278
284
|
def on_dstr(ctx, node)
|
@@ -293,14 +299,14 @@ class Rephrase
|
|
293
299
|
emit(ctx, "\"")
|
294
300
|
end
|
295
301
|
|
296
|
-
# Converts a
|
302
|
+
# Converts a `:EVSTR` AST node.
|
297
303
|
# @param ctx [Hash] context object
|
298
304
|
# @param node [RubyVM::AbstractSyntaxTree::Node] AST node
|
299
305
|
def on_evstr(ctx, node)
|
300
306
|
emit(ctx, "\#{", node.children.first, "}")
|
301
307
|
end
|
302
308
|
|
303
|
-
# Converts a
|
309
|
+
# Converts a `:AND` AST node.
|
304
310
|
# @param ctx [Hash] context object
|
305
311
|
# @param node [RubyVM::AbstractSyntaxTree::Node] AST node
|
306
312
|
def on_and(ctx, node)
|
@@ -308,7 +314,7 @@ class Rephrase
|
|
308
314
|
emit(ctx, left, " && ", right)
|
309
315
|
end
|
310
316
|
|
311
|
-
# Converts a
|
317
|
+
# Converts a `:OR` AST node.
|
312
318
|
# @param ctx [Hash] context object
|
313
319
|
# @param node [RubyVM::AbstractSyntaxTree::Node] AST node
|
314
320
|
def on_or(ctx, node)
|
@@ -316,7 +322,7 @@ class Rephrase
|
|
316
322
|
emit(ctx, left, " || ", right)
|
317
323
|
end
|
318
324
|
|
319
|
-
# Converts a
|
325
|
+
# Converts a `:LIST` AST node.
|
320
326
|
# @param ctx [Hash] context object
|
321
327
|
# @param node [RubyVM::AbstractSyntaxTree::Node] AST node
|
322
328
|
def on_list(ctx, node)
|
@@ -330,7 +336,7 @@ class Rephrase
|
|
330
336
|
emit(ctx, "]")
|
331
337
|
end
|
332
338
|
|
333
|
-
# Converts a
|
339
|
+
# Converts a `:LIST_EMBEDDED` AST (fake) node.
|
334
340
|
# @param ctx [Hash] context object
|
335
341
|
# @param node [Rephrase::FakeNode] AST node
|
336
342
|
def on_list_embedded(ctx, node)
|
@@ -342,7 +348,7 @@ class Rephrase
|
|
342
348
|
end
|
343
349
|
end
|
344
350
|
|
345
|
-
# Converts a
|
351
|
+
# Converts a `:HASH` AST node.
|
346
352
|
# @param ctx [Hash] context object
|
347
353
|
# @param node [RubyVM::AbstractSyntaxTree::Node] AST node
|
348
354
|
def on_hash(ctx, node)
|
@@ -360,7 +366,7 @@ class Rephrase
|
|
360
366
|
emit(ctx, "}")
|
361
367
|
end
|
362
368
|
|
363
|
-
# Converts a
|
369
|
+
# Converts a `:ATTRASGN` AST node.
|
364
370
|
# @param ctx [Hash] context object
|
365
371
|
# @param node [RubyVM::AbstractSyntaxTree::Node] AST node
|
366
372
|
def on_attrasgn(ctx, node)
|
@@ -377,7 +383,7 @@ class Rephrase
|
|
377
383
|
end
|
378
384
|
end
|
379
385
|
|
380
|
-
# Converts a
|
386
|
+
# Converts a `:RESCUE` AST node.
|
381
387
|
# @param ctx [Hash] context object
|
382
388
|
# @param node [RubyVM::AbstractSyntaxTree::Node] AST node
|
383
389
|
def on_rescue(ctx, node)
|
@@ -386,7 +392,7 @@ class Rephrase
|
|
386
392
|
emit(ctx, " rescue ", rescue_body.children[1])
|
387
393
|
end
|
388
394
|
|
389
|
-
# Emits code into the context buffer
|
395
|
+
# Emits code into the context buffer.
|
390
396
|
# @param ctx [Hash] context object
|
391
397
|
# @param entries [Array<String, Symbol>] code entries
|
392
398
|
def emit(ctx, *entries)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rephrase
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.3'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sharon Rosner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-11-
|
11
|
+
date: 2021-11-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -38,6 +38,34 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '12.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: yard
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: kramdown
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
41
69
|
description:
|
42
70
|
email: ciconia@gmail.com
|
43
71
|
executables: []
|
@@ -54,6 +82,7 @@ licenses:
|
|
54
82
|
- MIT
|
55
83
|
metadata:
|
56
84
|
source_code_uri: https://github.com/digital-fabric/rephrase
|
85
|
+
documentation_uri: https://www.rubydoc.info/gems/rephrase/0.3
|
57
86
|
post_install_message:
|
58
87
|
rdoc_options:
|
59
88
|
- "--title"
|