ruby-next-core 0.10.0 → 0.10.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/.rbnext/2.3/ruby-next/language/rewriters/base.rb +4 -0
- data/lib/.rbnext/2.3/ruby-next/language/rewriters/right_hand_assignment.rb +107 -0
- data/lib/ruby-next/language.rb +1 -1
- data/lib/ruby-next/language/rewriters/base.rb +4 -0
- data/lib/ruby-next/language/rewriters/right_hand_assignment.rb +72 -10
- data/lib/ruby-next/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b97da767efae69a9faa9ed2b4c4a3daf9c38a5b70768502b013692b7a3c04a50
|
4
|
+
data.tar.gz: 05ba2f4c4677c40d46a451a68a94e434b54d4e9daa9a2af51cbd508ef0a198ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef678d9b8ed431a8a8f005b00c445da56096c39a3c9ffc1ce88708c4b1280e630cb5c58a63a154381c384b54968ec19b3c88a4a49665b3503bd5df62f454a168
|
7
|
+
data.tar.gz: a25ebf4e0c3456213a1f682d27df031a6add5bc117800026d8b0f9b48cacb49e72a4b97115f9b1b1acf058ca3f6974dfa94402498a58a19ac532916eb9a81199
|
data/CHANGELOG.md
CHANGED
@@ -0,0 +1,107 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RubyNext
|
4
|
+
module Language
|
5
|
+
module Rewriters
|
6
|
+
class RightHandAssignment < Base
|
7
|
+
NAME = "right-hand-assignment"
|
8
|
+
SYNTAX_PROBE = "1 + 2 => a"
|
9
|
+
MIN_SUPPORTED_VERSION = Gem::Version.new("3.0.0")
|
10
|
+
|
11
|
+
def on_rasgn(node)
|
12
|
+
context.track! self
|
13
|
+
|
14
|
+
node = super(node)
|
15
|
+
|
16
|
+
val_node, asgn_node = *node
|
17
|
+
|
18
|
+
remove(val_node.loc.expression.end.join(asgn_node.loc.expression))
|
19
|
+
insert_before(val_node.loc.expression, "#{asgn_node.loc.expression.source} = ")
|
20
|
+
|
21
|
+
asgn_node.updated(
|
22
|
+
nil,
|
23
|
+
asgn_node.children + [val_node]
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
def on_vasgn(node)
|
28
|
+
return super(node) unless rightward?(node)
|
29
|
+
|
30
|
+
context.track! self
|
31
|
+
|
32
|
+
name, val_node = *node
|
33
|
+
|
34
|
+
remove(val_node.loc.expression.end.join(node.loc.name))
|
35
|
+
insert_before(val_node.loc.expression, "#{name} = ")
|
36
|
+
|
37
|
+
super(node)
|
38
|
+
end
|
39
|
+
|
40
|
+
def on_casgn(node)
|
41
|
+
return super(node) unless rightward?(node)
|
42
|
+
|
43
|
+
context.track! self
|
44
|
+
|
45
|
+
scope_node, name, val_node = *node
|
46
|
+
|
47
|
+
if scope_node
|
48
|
+
scope = scope_node.type == :cbase ? scope_node.loc.expression.source : "#{scope_node.loc.expression.source}::"
|
49
|
+
name = "#{scope}#{name}"
|
50
|
+
end
|
51
|
+
|
52
|
+
remove(val_node.loc.expression.end.join(node.loc.name))
|
53
|
+
insert_before(val_node.loc.expression, "#{name} = ")
|
54
|
+
|
55
|
+
super(node)
|
56
|
+
end
|
57
|
+
|
58
|
+
def on_mrasgn(node)
|
59
|
+
context.track! self
|
60
|
+
|
61
|
+
node = super(node)
|
62
|
+
|
63
|
+
lhs, rhs = *node
|
64
|
+
|
65
|
+
replace(lhs.loc.expression.end.join(rhs.loc.expression), ")")
|
66
|
+
insert_before(lhs.loc.expression, "#{rhs.loc.expression.source} = (")
|
67
|
+
|
68
|
+
node.updated(
|
69
|
+
:masgn,
|
70
|
+
[rhs, lhs]
|
71
|
+
)
|
72
|
+
end
|
73
|
+
|
74
|
+
def on_masgn(node)
|
75
|
+
return super(node) unless rightward?(node)
|
76
|
+
|
77
|
+
context.track! self
|
78
|
+
|
79
|
+
rhs, lhs = *node
|
80
|
+
|
81
|
+
replace(lhs.loc.expression.end.join(rhs.loc.expression), ")")
|
82
|
+
insert_before(lhs.loc.expression, "#{rhs.loc.expression.source} = (")
|
83
|
+
|
84
|
+
super(node)
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
|
89
|
+
def rightward?(node)
|
90
|
+
# Location could be empty for node built by rewriters
|
91
|
+
return false unless ((!node.loc.nil?) || nil) && node.loc.operator
|
92
|
+
|
93
|
+
assignee_loc =
|
94
|
+
if node.type == :masgn
|
95
|
+
node.children[0].loc.expression
|
96
|
+
else
|
97
|
+
node.loc.name
|
98
|
+
end
|
99
|
+
|
100
|
+
return false unless assignee_loc
|
101
|
+
|
102
|
+
assignee_loc.begin_pos > node.loc.operator.end_pos
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
data/lib/ruby-next/language.rb
CHANGED
@@ -11,34 +11,96 @@ module RubyNext
|
|
11
11
|
def on_rasgn(node)
|
12
12
|
context.track! self
|
13
13
|
|
14
|
+
node = super(node)
|
15
|
+
|
14
16
|
val_node, asgn_node = *node
|
15
17
|
|
16
18
|
remove(val_node.loc.expression.end.join(asgn_node.loc.expression))
|
17
19
|
insert_before(val_node.loc.expression, "#{asgn_node.loc.expression.source} = ")
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
asgn_node.children + [val_node]
|
23
|
-
)
|
21
|
+
asgn_node.updated(
|
22
|
+
nil,
|
23
|
+
asgn_node.children + [val_node]
|
24
24
|
)
|
25
25
|
end
|
26
26
|
|
27
|
+
def on_vasgn(node)
|
28
|
+
return super(node) unless rightward?(node)
|
29
|
+
|
30
|
+
context.track! self
|
31
|
+
|
32
|
+
name, val_node = *node
|
33
|
+
|
34
|
+
remove(val_node.loc.expression.end.join(node.loc.name))
|
35
|
+
insert_before(val_node.loc.expression, "#{name} = ")
|
36
|
+
|
37
|
+
super(node)
|
38
|
+
end
|
39
|
+
|
40
|
+
def on_casgn(node)
|
41
|
+
return super(node) unless rightward?(node)
|
42
|
+
|
43
|
+
context.track! self
|
44
|
+
|
45
|
+
scope_node, name, val_node = *node
|
46
|
+
|
47
|
+
if scope_node
|
48
|
+
scope = scope_node.type == :cbase ? scope_node.loc.expression.source : "#{scope_node.loc.expression.source}::"
|
49
|
+
name = "#{scope}#{name}"
|
50
|
+
end
|
51
|
+
|
52
|
+
remove(val_node.loc.expression.end.join(node.loc.name))
|
53
|
+
insert_before(val_node.loc.expression, "#{name} = ")
|
54
|
+
|
55
|
+
super(node)
|
56
|
+
end
|
57
|
+
|
27
58
|
def on_mrasgn(node)
|
28
59
|
context.track! self
|
29
60
|
|
61
|
+
node = super(node)
|
62
|
+
|
30
63
|
lhs, rhs = *node
|
31
64
|
|
32
65
|
replace(lhs.loc.expression.end.join(rhs.loc.expression), ")")
|
33
66
|
insert_before(lhs.loc.expression, "#{rhs.loc.expression.source} = (")
|
34
67
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
[rhs, lhs]
|
39
|
-
)
|
68
|
+
node.updated(
|
69
|
+
:masgn,
|
70
|
+
[rhs, lhs]
|
40
71
|
)
|
41
72
|
end
|
73
|
+
|
74
|
+
def on_masgn(node)
|
75
|
+
return super(node) unless rightward?(node)
|
76
|
+
|
77
|
+
context.track! self
|
78
|
+
|
79
|
+
rhs, lhs = *node
|
80
|
+
|
81
|
+
replace(lhs.loc.expression.end.join(rhs.loc.expression), ")")
|
82
|
+
insert_before(lhs.loc.expression, "#{rhs.loc.expression.source} = (")
|
83
|
+
|
84
|
+
super(node)
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
|
89
|
+
def rightward?(node)
|
90
|
+
# Location could be empty for node built by rewriters
|
91
|
+
return false unless node.loc&.operator
|
92
|
+
|
93
|
+
assignee_loc =
|
94
|
+
if node.type == :masgn
|
95
|
+
node.children[0].loc.expression
|
96
|
+
else
|
97
|
+
node.loc.name
|
98
|
+
end
|
99
|
+
|
100
|
+
return false unless assignee_loc
|
101
|
+
|
102
|
+
assignee_loc.begin_pos > node.loc.operator.end_pos
|
103
|
+
end
|
42
104
|
end
|
43
105
|
end
|
44
106
|
end
|
data/lib/ruby-next/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-next-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.10.
|
4
|
+
version: 0.10.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vladimir Dementyev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-09-
|
11
|
+
date: 2020-09-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-next-parser
|
@@ -61,6 +61,7 @@ files:
|
|
61
61
|
- lib/.rbnext/2.3/ruby-next/language/rewriters/base.rb
|
62
62
|
- lib/.rbnext/2.3/ruby-next/language/rewriters/endless_range.rb
|
63
63
|
- lib/.rbnext/2.3/ruby-next/language/rewriters/pattern_matching.rb
|
64
|
+
- lib/.rbnext/2.3/ruby-next/language/rewriters/right_hand_assignment.rb
|
64
65
|
- lib/.rbnext/2.3/ruby-next/utils.rb
|
65
66
|
- lib/ruby-next.rb
|
66
67
|
- lib/ruby-next/cli.rb
|