sirop 0.5 → 0.7
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 +9 -0
- data/lib/sirop/finder.rb +1 -2
- data/lib/sirop/sourcifier.rb +26 -25
- data/lib/sirop/version.rb +1 -1
- data/lib/sirop.rb +7 -3
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0aa1bac2ed98532aeed671c846e23c49d64a0df0c838f908d345aff6b3eb20db
|
4
|
+
data.tar.gz: 0efe8bb07a5f691e60978b8a523891808dd849c2b05d62aa28fad1b5b46045ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c92e0f7c2cf5c4452e4af50b5b1e99786eb8d2453668020c5a9fe2d955f242562e96d068b23fee50a304bc02f446e903c43ec8bb720cff0a681a648e6528f7d4
|
7
|
+
data.tar.gz: daf7af4d543398a0e34d4e0521737d179ed120530921c5b560148bbe806e3f38d8b7c12b9d2e3c0665eed26560f46106e80e23751fd0258c354df9d4fa7b1354
|
data/CHANGELOG.md
CHANGED
data/lib/sirop/finder.rb
CHANGED
data/lib/sirop/sourcifier.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
require 'prism'
|
4
4
|
|
5
5
|
module Sirop
|
6
|
-
#
|
6
|
+
#
|
7
7
|
class Sourcifier < Prism::BasicVisitor
|
8
8
|
VISIT_PLANS = {
|
9
9
|
alias_global_variable: [:keyword_loc, :new_name, :old_name],
|
@@ -21,7 +21,7 @@ module Sirop
|
|
21
21
|
class_variable_read: :emit_verbatim,
|
22
22
|
class_variable_target: :emit_verbatim,
|
23
23
|
class_variable_write: [:name_loc, :operator_loc, :value],
|
24
|
-
constant_path: [:parent, :delimiter_loc, :
|
24
|
+
constant_path: [:parent, :delimiter_loc, :name_loc],
|
25
25
|
constant_path_write: [:target, :operator_loc, :value],
|
26
26
|
constant_read: :emit_verbatim,
|
27
27
|
constant_write: [:name_loc, :operator_loc, :value],
|
@@ -49,7 +49,7 @@ module Sirop
|
|
49
49
|
keyword_rest_parameter: [:operator_loc, :name_loc],
|
50
50
|
keyword_parameter: :emit_verbatim,
|
51
51
|
local_variable_and_write: [:name_loc, :operator_loc, :value],
|
52
|
-
local_variable_operator_write: [:name_loc, :
|
52
|
+
local_variable_operator_write: [:name_loc, :binary_operator_loc, :value],
|
53
53
|
local_variable_or_write: [:name_loc, :operator_loc, :value],
|
54
54
|
local_variable_read: :emit_verbatim,
|
55
55
|
local_variable_target: :emit_verbatim,
|
@@ -91,20 +91,21 @@ module Sirop
|
|
91
91
|
|
92
92
|
attr_reader :buffer
|
93
93
|
|
94
|
-
def initialize
|
94
|
+
def initialize(minimize_whitespace: false)
|
95
95
|
@buffer = +''
|
96
|
+
@minimize_whitespace = minimize_whitespace
|
96
97
|
end
|
97
|
-
|
98
|
+
|
98
99
|
def to_source(node)
|
99
100
|
@buffer.clear
|
100
101
|
visit(node)
|
101
102
|
@buffer
|
102
103
|
end
|
103
|
-
|
104
|
+
|
104
105
|
def loc_start(loc)
|
105
106
|
[loc.start_line, loc.start_column]
|
106
107
|
end
|
107
|
-
|
108
|
+
|
108
109
|
def loc_end(loc)
|
109
110
|
[loc.end_line, loc.end_column]
|
110
111
|
end
|
@@ -120,16 +121,16 @@ module Sirop
|
|
120
121
|
line_diff = loc.start_line - @last_loc_end.first
|
121
122
|
if line_diff > 0
|
122
123
|
@buffer << "\n" * line_diff
|
123
|
-
@buffer << ' ' * loc.start_column
|
124
|
+
@buffer << ' ' * loc.start_column if !@minimize_whitespace
|
124
125
|
elsif line_diff == 0
|
125
126
|
ofs = loc.start_column - @last_loc_end.last
|
126
127
|
if ofs > 0
|
127
|
-
@buffer << ' ' * ofs
|
128
|
+
@buffer << (@minimize_whitespace ? ' ' : (' ' * ofs))
|
128
129
|
end
|
129
130
|
end
|
130
131
|
else
|
131
132
|
# empty buffer
|
132
|
-
@buffer << ' ' * loc.start_column
|
133
|
+
@buffer << ' ' * loc.start_column if !@minimize_whitespace
|
133
134
|
end
|
134
135
|
@last_loc = loc
|
135
136
|
@last_loc_start = loc_start(loc)
|
@@ -141,7 +142,7 @@ module Sirop
|
|
141
142
|
|
142
143
|
if @last_loc
|
143
144
|
loc_loc = loc.is_a?(Prism::Node) ? loc.location : loc
|
144
|
-
return if loc_loc.slice == @last_loc.slice && loc_loc.start_line == @last_loc.start_line &&
|
145
|
+
return if loc_loc.slice == @last_loc.slice && loc_loc.start_line == @last_loc.start_line &&
|
145
146
|
loc_loc.start_column == @last_loc.start_column
|
146
147
|
end
|
147
148
|
|
@@ -155,20 +156,20 @@ module Sirop
|
|
155
156
|
str = str.chomp if chomp
|
156
157
|
emit(str)
|
157
158
|
end
|
158
|
-
|
159
|
+
|
159
160
|
def emit_verbatim(node)
|
160
161
|
emit_code(node.location)
|
161
162
|
end
|
162
163
|
|
163
164
|
def emit_nothing(node)
|
164
165
|
# emit nothing
|
165
|
-
end
|
166
|
+
end
|
166
167
|
|
167
168
|
def emit_str(str)
|
168
169
|
emit(str)
|
169
170
|
@last_loc_end[1] += str.size
|
170
171
|
end
|
171
|
-
|
172
|
+
|
172
173
|
def emit_comma
|
173
174
|
emit_str(',')
|
174
175
|
end
|
@@ -193,7 +194,7 @@ module Sirop
|
|
193
194
|
sym = :"visit_#{key}_node"
|
194
195
|
define_method(sym) { |n| visit_plan(plan, n) }
|
195
196
|
end
|
196
|
-
|
197
|
+
|
197
198
|
def visit_plan(plan, node)
|
198
199
|
return send(plan, node) if plan.is_a?(Symbol)
|
199
200
|
|
@@ -270,7 +271,7 @@ module Sirop
|
|
270
271
|
def visit_arguments_node(node, subscript = 0..-1)
|
271
272
|
visit_comma_separated_nodes(node.arguments[subscript])
|
272
273
|
end
|
273
|
-
|
274
|
+
|
274
275
|
def visit_keyword_hash_node(node)
|
275
276
|
visit_comma_separated_nodes(node.elements)
|
276
277
|
end
|
@@ -286,7 +287,7 @@ module Sirop
|
|
286
287
|
emit_code(node.predicate)
|
287
288
|
emit_code(node.then_keyword_loc)
|
288
289
|
emit_code(node.statements, semicolon: true)
|
289
|
-
emit_code(node.
|
290
|
+
emit_code(node.subsequent) if node.subsequent
|
290
291
|
emit_code(node.end_keyword_loc, semicolon: true) if node.if_keyword_loc.slice == 'if'
|
291
292
|
end
|
292
293
|
|
@@ -294,11 +295,11 @@ module Sirop
|
|
294
295
|
emit_code(node.predicate)
|
295
296
|
emit_code(node.then_keyword_loc)
|
296
297
|
emit_code(node.statements)
|
297
|
-
emit_code(node.
|
298
|
+
emit_code(node.subsequent)
|
298
299
|
end
|
299
300
|
|
300
301
|
def visit_if_node_guard(node)
|
301
|
-
emit_code(node.statements)
|
302
|
+
emit_code(node.statements)
|
302
303
|
emit_code(node.if_keyword_loc)
|
303
304
|
emit_code(node.predicate)
|
304
305
|
end
|
@@ -313,12 +314,12 @@ module Sirop
|
|
313
314
|
emit_code(node.then_keyword_loc)
|
314
315
|
@semicolon = true
|
315
316
|
emit_code(node.statements)
|
316
|
-
emit_code(node.
|
317
|
+
emit_code(node.else_clause) if node.else_clause
|
317
318
|
emit_code(node.end_keyword_loc, semicolon: true) if node.keyword_loc.slice == 'unless'
|
318
319
|
end
|
319
320
|
|
320
321
|
def visit_unless_node_guard(node)
|
321
|
-
emit_code(node.statements)
|
322
|
+
emit_code(node.statements)
|
322
323
|
emit_code(node.keyword_loc)
|
323
324
|
emit_code(node.predicate)
|
324
325
|
end
|
@@ -327,7 +328,7 @@ module Sirop
|
|
327
328
|
emit_code(node.case_keyword_loc)
|
328
329
|
emit_code(node.predicate)
|
329
330
|
node.conditions.each { |c| emit_code(c, semicolon: true) }
|
330
|
-
emit_code(node.
|
331
|
+
emit_code(node.else_clause, semicolon: true)
|
331
332
|
emit_code(node.end_keyword_loc, semicolon: true)
|
332
333
|
end
|
333
334
|
|
@@ -385,7 +386,7 @@ module Sirop
|
|
385
386
|
end
|
386
387
|
emit_code(node.opening_loc)
|
387
388
|
emit_code(node.arguments)
|
388
|
-
|
389
|
+
|
389
390
|
if block.is_a?(Prism::BlockArgumentNode)
|
390
391
|
emit_comma if node.arguments && node.arguments.arguments.size > 0
|
391
392
|
emit_code(block)
|
@@ -461,7 +462,7 @@ module Sirop
|
|
461
462
|
visit_comma_separated_nodes(node.elements)
|
462
463
|
emit_code(node.closing_loc)
|
463
464
|
end
|
464
|
-
|
465
|
+
|
465
466
|
def visit_array_node(node)
|
466
467
|
emit_code(node.opening_loc)
|
467
468
|
if node.opening_loc && node.opening_loc.slice =~ /^%/
|
@@ -492,7 +493,7 @@ module Sirop
|
|
492
493
|
emit_code(node.operator_loc)
|
493
494
|
emit_code(node.reference)
|
494
495
|
emit_code(node.statements, semicolon: true)
|
495
|
-
emit_code(node.
|
496
|
+
emit_code(node.subsequent)
|
496
497
|
end
|
497
498
|
|
498
499
|
def visit_begin_node(node)
|
data/lib/sirop/version.rb
CHANGED
data/lib/sirop.rb
CHANGED
@@ -22,15 +22,15 @@ module Sirop
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
def to_source(obj)
|
25
|
+
def to_source(obj, **)
|
26
26
|
obj = to_ast(obj) if !obj.is_a?(Prism::Node)
|
27
|
-
Sourcifier.new.to_source(obj)
|
27
|
+
Sourcifier.new(**).to_source(obj)
|
28
28
|
end
|
29
29
|
|
30
30
|
private
|
31
31
|
|
32
32
|
def proc_ast(proc)
|
33
|
-
fn, lineno = proc.source_location
|
33
|
+
fn, lineno = proc.source_location
|
34
34
|
pr = Prism.parse(IO.read(fn), filepath: fn)
|
35
35
|
program = pr.value
|
36
36
|
|
@@ -39,6 +39,10 @@ module Sirop
|
|
39
39
|
found!(node) if node.location.start_line == lineno
|
40
40
|
super(node)
|
41
41
|
end
|
42
|
+
on(:block) do |node|
|
43
|
+
found!(node) if node.location.start_line == lineno
|
44
|
+
super(node)
|
45
|
+
end
|
42
46
|
on(:call) do |node|
|
43
47
|
case node.name
|
44
48
|
when :proc, :lambda
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sirop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.7'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sharon Rosner
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: prism
|
@@ -15,28 +15,28 @@ dependencies:
|
|
15
15
|
requirements:
|
16
16
|
- - "~>"
|
17
17
|
- !ruby/object:Gem::Version
|
18
|
-
version:
|
18
|
+
version: 1.4.0
|
19
19
|
type: :runtime
|
20
20
|
prerelease: false
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
22
22
|
requirements:
|
23
23
|
- - "~>"
|
24
24
|
- !ruby/object:Gem::Version
|
25
|
-
version:
|
25
|
+
version: 1.4.0
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: minitest
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|
29
29
|
requirements:
|
30
30
|
- - "~>"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 5.
|
32
|
+
version: 5.25.5
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
35
|
version_requirements: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
37
|
- - "~>"
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version: 5.
|
39
|
+
version: 5.25.5
|
40
40
|
email: sharon@noteflakes.com
|
41
41
|
executables: []
|
42
42
|
extensions: []
|
@@ -69,14 +69,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
69
69
|
requirements:
|
70
70
|
- - ">="
|
71
71
|
- !ruby/object:Gem::Version
|
72
|
-
version: '3.
|
72
|
+
version: '3.4'
|
73
73
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
74
|
requirements:
|
75
75
|
- - ">="
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '0'
|
78
78
|
requirements: []
|
79
|
-
rubygems_version: 3.6.
|
79
|
+
rubygems_version: 3.6.8
|
80
80
|
specification_version: 4
|
81
81
|
summary: 'Sirop: Ruby code rewriter'
|
82
82
|
test_files: []
|