unparser 0.0.8 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.devtools +17 -18
- data/Rakefile +9 -0
- data/{.circle.yml → circle.yml} +1 -1
- data/config/flay.yml +1 -1
- data/config/flog.yml +1 -1
- data/lib/unparser.rb +3 -0
- data/lib/unparser/constants.rb +26 -29
- data/lib/unparser/emitter/begin.rb +19 -133
- data/lib/unparser/emitter/ensure.rb +27 -0
- data/lib/unparser/emitter/flipflop.rb +3 -2
- data/lib/unparser/emitter/literal/primitive.rb +60 -1
- data/lib/unparser/emitter/resbody.rb +51 -0
- data/lib/unparser/emitter/rescue.rb +64 -0
- data/lib/unparser/emitter/send.rb +19 -17
- data/lib/unparser/emitter/send/binary.rb +2 -38
- data/lib/unparser/emitter/send/unary.rb +3 -3
- data/spec/integration/unparser/spike_spec.rb +9 -12
- data/spec/unit/unparser/class_methods/unparse_spec.rb +1 -1
- data/spec/unit/unparser/emitter/class_methods/visit_spec.rb +1 -1
- data/spec/unit/unparser/emitter/source_map/class_methods/emit_spec.rb +3 -3
- data/unparser.gemspec +4 -4
- metadata +12 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ccb8ec5ec53b06f423ec478b69175df8b6d23e7
|
4
|
+
data.tar.gz: 5c21e85a61a86b8a74b8e2f4765474d68e90cd57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d460332fd79deb26a5f077e513774e4b7609f11ed313e4c09a70ba724789ff857de7a40d4d40afc8e571d9f8e7ca02c073ccc62b3c0a71b8d952ef5baf9f5cda
|
7
|
+
data.tar.gz: 050e67bb496b66d06ee75e266dd22b6539562589d63cebd6dce5ff57dcf88a688fa2250f5b9b4d99a9d71557d550f2c554067a88928e7d05556fe6437849091b
|
data/Gemfile.devtools
CHANGED
@@ -2,46 +2,45 @@
|
|
2
2
|
|
3
3
|
group :development do
|
4
4
|
gem 'rake', '~> 10.1.0'
|
5
|
-
gem 'rspec', '~> 2.
|
6
|
-
gem 'yard', '~> 0.8.6.
|
5
|
+
gem 'rspec', '~> 2.14.1'
|
6
|
+
gem 'yard', '~> 0.8.6.2'
|
7
7
|
end
|
8
8
|
|
9
9
|
group :yard do
|
10
|
-
gem 'kramdown', '~> 1.0
|
10
|
+
gem 'kramdown', '~> 1.1.0'
|
11
11
|
end
|
12
12
|
|
13
13
|
group :guard do
|
14
14
|
gem 'guard', '~> 1.8.1'
|
15
15
|
gem 'guard-bundler', '~> 1.0.0'
|
16
16
|
gem 'guard-rspec', '~> 3.0.2'
|
17
|
+
gem 'guard-rubocop', '~> 0.2.0'
|
18
|
+
gem 'guard-mutant', '~> 0.0.1'
|
17
19
|
|
18
20
|
# file system change event handling
|
19
21
|
gem 'listen', '~> 1.2.2'
|
20
|
-
gem 'rb-fchange', '~> 0.0.6', :
|
21
|
-
gem 'rb-fsevent', '~> 0.9.3', :
|
22
|
-
gem 'rb-inotify', '~> 0.9.0', :
|
22
|
+
gem 'rb-fchange', '~> 0.0.6', require: false
|
23
|
+
gem 'rb-fsevent', '~> 0.9.3', require: false
|
24
|
+
gem 'rb-inotify', '~> 0.9.0', require: false
|
23
25
|
|
24
26
|
# notification handling
|
25
|
-
gem 'libnotify', '~> 0.8.0', :
|
26
|
-
gem 'rb-notifu', '~> 0.0.4', :
|
27
|
-
gem 'terminal-notifier-guard', '~> 1.5.3', :
|
27
|
+
gem 'libnotify', '~> 0.8.0', require: false
|
28
|
+
gem 'rb-notifu', '~> 0.0.4', require: false
|
29
|
+
gem 'terminal-notifier-guard', '~> 1.5.3', require: false
|
28
30
|
end
|
29
31
|
|
30
32
|
group :metrics do
|
31
|
-
gem 'backports', '~> 3.3', '>= 3.3.2'
|
32
33
|
gem 'coveralls', '~> 0.6.7'
|
33
|
-
gem 'flay', '~> 2.3.
|
34
|
-
gem 'flog', '~> 4.1.
|
35
|
-
gem 'reek', '~> 1.3.1',
|
34
|
+
gem 'flay', '~> 2.3.1'
|
35
|
+
gem 'flog', '~> 4.1.1'
|
36
|
+
gem 'reek', '~> 1.3.1', git: 'https://github.com/troessner/reek.git'
|
37
|
+
gem 'rubocop', '~> 0.10.0', git: 'https://github.com/bbatsov/rubocop.git'
|
36
38
|
gem 'simplecov', '~> 0.7.1'
|
37
39
|
gem 'yardstick', '~> 0.9.6'
|
38
40
|
|
39
|
-
platforms :ruby_19 do
|
40
|
-
gem 'yard-spellcheck', '~> 0.1.5'
|
41
|
-
end
|
42
|
-
|
43
41
|
platforms :ruby_19, :ruby_20 do
|
44
|
-
gem 'mutant',
|
42
|
+
gem 'mutant', '~> 0.3.0.beta17'
|
43
|
+
gem 'yard-spellcheck', '~> 0.1.5'
|
45
44
|
end
|
46
45
|
|
47
46
|
platforms :rbx do
|
data/Rakefile
CHANGED
@@ -1,2 +1,11 @@
|
|
1
1
|
require 'devtools'
|
2
2
|
Devtools.init_rake_tasks
|
3
|
+
|
4
|
+
Rake.application.load_imports
|
5
|
+
task('metrics:mutant').clear
|
6
|
+
|
7
|
+
namespace :metrics do
|
8
|
+
task :mutant => :coverage do
|
9
|
+
$stderr.puts 'Mutant is disabled till flexible rspec strategy is implemented'
|
10
|
+
end
|
11
|
+
end
|
data/{.circle.yml → circle.yml}
RENAMED
data/config/flay.yml
CHANGED
data/config/flog.yml
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
---
|
2
|
-
threshold:
|
2
|
+
threshold: 12.2
|
data/lib/unparser.rb
CHANGED
@@ -89,5 +89,8 @@ require 'unparser/emitter/root'
|
|
89
89
|
require 'unparser/emitter/match'
|
90
90
|
require 'unparser/emitter/empty'
|
91
91
|
require 'unparser/emitter/flipflop'
|
92
|
+
require 'unparser/emitter/rescue'
|
93
|
+
require 'unparser/emitter/resbody'
|
94
|
+
require 'unparser/emitter/ensure'
|
92
95
|
# make it easy for zombie
|
93
96
|
require 'unparser/finalize'
|
data/lib/unparser/constants.rb
CHANGED
@@ -1,39 +1,36 @@
|
|
1
1
|
module Unparser
|
2
|
+
# All unparser constants maybe included in other libraries.
|
2
3
|
module Constants
|
3
4
|
|
4
5
|
UNARY_OPERATORS = %w(
|
5
|
-
!
|
6
|
-
|
7
|
-
-@
|
8
|
-
+@
|
9
|
-
).map(&:to_sym).to_set.freeze
|
10
|
-
|
6
|
+
! ~ -@ +@
|
7
|
+
).map(&:to_sym).to_set
|
11
8
|
|
12
9
|
BINARY_OPERATORS = %w(
|
13
10
|
+ - * / & | && || << >> ==
|
14
11
|
=== != <= < <=> > >= =~ !~ ^
|
15
12
|
**
|
16
|
-
).map(&:to_sym).to_set
|
13
|
+
).map(&:to_sym).to_set
|
17
14
|
|
18
|
-
WS = ' '
|
19
|
-
NL = "\n"
|
20
|
-
T_DOT = '.'
|
21
|
-
T_LT = '<'
|
22
|
-
T_DLT = '<<'
|
23
|
-
T_AMP = '&'
|
24
|
-
T_ASN = '='
|
25
|
-
T_SPLAT = '*'
|
26
|
-
T_DSPLAT = '**'
|
27
|
-
T_ASR = '=>'
|
28
|
-
T_PIPE = '|'
|
29
|
-
T_DCL = '::'
|
30
|
-
T_NEG = '!'
|
31
|
-
T_OR = '||'
|
32
|
-
T_AND = '&&'
|
33
|
-
T_COLON = ':'
|
15
|
+
WS = ' '
|
16
|
+
NL = "\n"
|
17
|
+
T_DOT = '.'
|
18
|
+
T_LT = '<'
|
19
|
+
T_DLT = '<<'
|
20
|
+
T_AMP = '&'
|
21
|
+
T_ASN = '='
|
22
|
+
T_SPLAT = '*'
|
23
|
+
T_DSPLAT = '**'
|
24
|
+
T_ASR = '=>'
|
25
|
+
T_PIPE = '|'
|
26
|
+
T_DCL = '::'
|
27
|
+
T_NEG = '!'
|
28
|
+
T_OR = '||'
|
29
|
+
T_AND = '&&'
|
30
|
+
T_COLON = ':'
|
34
31
|
|
35
|
-
M_PO = '('
|
36
|
-
M_PC = ')'
|
32
|
+
M_PO = '('
|
33
|
+
M_PC = ')'
|
37
34
|
|
38
35
|
K_DO = 'do'
|
39
36
|
K_DEF = 'def'
|
@@ -78,12 +75,12 @@ module Unparser
|
|
78
75
|
K_FILE = '__FILE__'
|
79
76
|
K_THEN = 'then'
|
80
77
|
|
81
|
-
|
82
|
-
|
78
|
+
KEYWORDS = constants.each_with_object([]) do |name, keywords|
|
79
|
+
value = const_get(name).freeze
|
83
80
|
if name.to_s.start_with?('K_')
|
84
|
-
|
81
|
+
keywords << value.to_sym
|
85
82
|
end
|
86
|
-
end.
|
83
|
+
end.to_set.freeze
|
87
84
|
|
88
85
|
end # Constants
|
89
86
|
end # Unparser
|
@@ -1,138 +1,6 @@
|
|
1
1
|
module Unparser
|
2
2
|
class Emitter
|
3
3
|
|
4
|
-
# Emitter for rescue nodes
|
5
|
-
class Rescue < self
|
6
|
-
|
7
|
-
handle :rescue
|
8
|
-
|
9
|
-
children :body
|
10
|
-
|
11
|
-
private
|
12
|
-
|
13
|
-
# Perform dispatch
|
14
|
-
#
|
15
|
-
# @return [undefined]
|
16
|
-
#
|
17
|
-
# @api private
|
18
|
-
#
|
19
|
-
def dispatch
|
20
|
-
visit_indented(body)
|
21
|
-
rescue_bodies.each do |child|
|
22
|
-
visit(child)
|
23
|
-
end
|
24
|
-
emit_else
|
25
|
-
end
|
26
|
-
|
27
|
-
# Return rescue bodies
|
28
|
-
#
|
29
|
-
# @return [Enumerable<Parser::AST::Node>]
|
30
|
-
#
|
31
|
-
# @api private
|
32
|
-
#
|
33
|
-
def rescue_bodies
|
34
|
-
children[1..-2]
|
35
|
-
end
|
36
|
-
|
37
|
-
# Emit else
|
38
|
-
#
|
39
|
-
# @return [undefined]
|
40
|
-
#
|
41
|
-
# @api private
|
42
|
-
#
|
43
|
-
def emit_else
|
44
|
-
return unless else_branch
|
45
|
-
write(K_ELSE)
|
46
|
-
visit_indented(else_branch)
|
47
|
-
end
|
48
|
-
|
49
|
-
# Return else body
|
50
|
-
#
|
51
|
-
# @return [Parser::AST::Node]
|
52
|
-
# if else body is present
|
53
|
-
#
|
54
|
-
# @return [nil]
|
55
|
-
# otherwise
|
56
|
-
#
|
57
|
-
# @api private
|
58
|
-
#
|
59
|
-
def else_branch
|
60
|
-
children.last
|
61
|
-
end
|
62
|
-
|
63
|
-
end # Rescue
|
64
|
-
|
65
|
-
# Emitter for ensure nodes
|
66
|
-
class Ensure < self
|
67
|
-
|
68
|
-
handle :ensure
|
69
|
-
|
70
|
-
children :body, :ensure_body
|
71
|
-
|
72
|
-
private
|
73
|
-
|
74
|
-
# Perform dispatch
|
75
|
-
#
|
76
|
-
# @return [undefined]
|
77
|
-
#
|
78
|
-
# @api private
|
79
|
-
#
|
80
|
-
def dispatch
|
81
|
-
visit_indented(body)
|
82
|
-
write(K_ENSURE)
|
83
|
-
visit_indented(ensure_body)
|
84
|
-
end
|
85
|
-
|
86
|
-
end # Ensure
|
87
|
-
|
88
|
-
# Emitter for rescue body nodes
|
89
|
-
class Resbody < self
|
90
|
-
|
91
|
-
handle :resbody
|
92
|
-
|
93
|
-
children :exception, :assignment, :body
|
94
|
-
|
95
|
-
private
|
96
|
-
|
97
|
-
# Perform dispatch
|
98
|
-
#
|
99
|
-
# @return [undefined]
|
100
|
-
#
|
101
|
-
# @api private
|
102
|
-
#
|
103
|
-
def dispatch
|
104
|
-
write(K_RESCUE)
|
105
|
-
emit_exception
|
106
|
-
emit_assignment
|
107
|
-
emit_body
|
108
|
-
end
|
109
|
-
|
110
|
-
# Emit exception
|
111
|
-
#
|
112
|
-
# @return [undefined]
|
113
|
-
#
|
114
|
-
# @api private
|
115
|
-
#
|
116
|
-
def emit_exception
|
117
|
-
return unless exception
|
118
|
-
ws
|
119
|
-
delimited(exception.children)
|
120
|
-
end
|
121
|
-
|
122
|
-
# Emit assignment
|
123
|
-
#
|
124
|
-
# @return [undefined]
|
125
|
-
#
|
126
|
-
# @api private
|
127
|
-
#
|
128
|
-
def emit_assignment
|
129
|
-
return unless assignment
|
130
|
-
write(WS, T_ASR, WS)
|
131
|
-
visit(assignment)
|
132
|
-
end
|
133
|
-
|
134
|
-
end # Resbody
|
135
|
-
|
136
4
|
# Emitter for begin nodes
|
137
5
|
class Begin < self
|
138
6
|
|
@@ -169,7 +37,25 @@ module Unparser
|
|
169
37
|
# @api private
|
170
38
|
#
|
171
39
|
def dispatch
|
172
|
-
|
40
|
+
if parentheses?
|
41
|
+
parentheses { emit_inner }
|
42
|
+
else
|
43
|
+
emit_inner
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Test if begin node needs to be enclosed within parentheses
|
48
|
+
#
|
49
|
+
# @return [true]
|
50
|
+
# if parentheses are needed
|
51
|
+
#
|
52
|
+
# @return [false]
|
53
|
+
# otherwise
|
54
|
+
#
|
55
|
+
# @api private
|
56
|
+
#
|
57
|
+
def parentheses?
|
58
|
+
children.length == 1 && children.first.type == :send && BINARY_OPERATORS.include?(children.first.children[1])
|
173
59
|
end
|
174
60
|
|
175
61
|
end # Implicit
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Unparser
|
2
|
+
class Emitter
|
3
|
+
|
4
|
+
# Emitter for ensure nodes
|
5
|
+
class Ensure < self
|
6
|
+
|
7
|
+
handle :ensure
|
8
|
+
|
9
|
+
children :body, :ensure_body
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
# Perform dispatch
|
14
|
+
#
|
15
|
+
# @return [undefined]
|
16
|
+
#
|
17
|
+
# @api private
|
18
|
+
#
|
19
|
+
def dispatch
|
20
|
+
visit_indented(body)
|
21
|
+
write(K_ENSURE)
|
22
|
+
visit_indented(ensure_body)
|
23
|
+
end
|
24
|
+
|
25
|
+
end # Ensure
|
26
|
+
end # Emitter
|
27
|
+
end # Unparser
|
@@ -1,5 +1,6 @@
|
|
1
1
|
module Unparser
|
2
2
|
class Emitter
|
3
|
+
# Emitter for flip flops
|
3
4
|
class FlipFlop < self
|
4
5
|
|
5
6
|
MAP = IceNine.deep_freeze(
|
@@ -20,9 +21,9 @@ module Unparser
|
|
20
21
|
# @api private
|
21
22
|
#
|
22
23
|
def dispatch
|
23
|
-
|
24
|
+
visit(left)
|
24
25
|
write(MAP.fetch(node.type))
|
25
|
-
|
26
|
+
visit(right)
|
26
27
|
end
|
27
28
|
end # FlipFLop
|
28
29
|
end # Emitter
|
@@ -12,7 +12,7 @@ module Unparser
|
|
12
12
|
# Emitter for primitives based on Object#inspect
|
13
13
|
class Inspect < self
|
14
14
|
|
15
|
-
handle :
|
15
|
+
handle :float, :sym, :int
|
16
16
|
|
17
17
|
private
|
18
18
|
|
@@ -27,6 +27,65 @@ module Unparser
|
|
27
27
|
end
|
28
28
|
|
29
29
|
end # Inspect
|
30
|
+
|
31
|
+
# Literal emitter with macro regeneration base class
|
32
|
+
class MacroSafe < self
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
# Perform dispatch
|
37
|
+
#
|
38
|
+
# @return [undefined]
|
39
|
+
#
|
40
|
+
# @api private
|
41
|
+
#
|
42
|
+
def dispatch
|
43
|
+
if(source == macro)
|
44
|
+
write(macro)
|
45
|
+
return
|
46
|
+
end
|
47
|
+
write(value.inspect)
|
48
|
+
end
|
49
|
+
|
50
|
+
# Return source, if present
|
51
|
+
#
|
52
|
+
# @return [String]
|
53
|
+
# if present
|
54
|
+
#
|
55
|
+
# @return [nil]
|
56
|
+
# otherwise
|
57
|
+
#
|
58
|
+
# @api private
|
59
|
+
#
|
60
|
+
def source
|
61
|
+
location = node.location || return
|
62
|
+
expression = location.expression || return
|
63
|
+
expression.source
|
64
|
+
end
|
65
|
+
|
66
|
+
# Return marco
|
67
|
+
#
|
68
|
+
# @return [String]
|
69
|
+
#
|
70
|
+
# @api private
|
71
|
+
#
|
72
|
+
def macro
|
73
|
+
self.class::MACRO
|
74
|
+
end
|
75
|
+
|
76
|
+
# String macro safe emitter
|
77
|
+
class String < self
|
78
|
+
MACRO = '__FILE__'.freeze
|
79
|
+
handle :str
|
80
|
+
end # String
|
81
|
+
|
82
|
+
# Integer macro safe emitter
|
83
|
+
class Integer < self
|
84
|
+
MACRO = '__LINE__'.freeze
|
85
|
+
handle :int
|
86
|
+
end # Integer
|
87
|
+
|
88
|
+
end # MacroSave
|
30
89
|
end # Primitive
|
31
90
|
end # Literal
|
32
91
|
end # Emitter
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Unparser
|
2
|
+
class Emitter
|
3
|
+
# Emitter for rescue body nodes
|
4
|
+
class Resbody < self
|
5
|
+
|
6
|
+
handle :resbody
|
7
|
+
|
8
|
+
children :exception, :assignment, :body
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
# Perform dispatch
|
13
|
+
#
|
14
|
+
# @return [undefined]
|
15
|
+
#
|
16
|
+
# @api private
|
17
|
+
#
|
18
|
+
def dispatch
|
19
|
+
write(K_RESCUE)
|
20
|
+
emit_exception
|
21
|
+
emit_assignment
|
22
|
+
emit_body
|
23
|
+
end
|
24
|
+
|
25
|
+
# Emit exception
|
26
|
+
#
|
27
|
+
# @return [undefined]
|
28
|
+
#
|
29
|
+
# @api private
|
30
|
+
#
|
31
|
+
def emit_exception
|
32
|
+
return unless exception
|
33
|
+
ws
|
34
|
+
delimited(exception.children)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Emit assignment
|
38
|
+
#
|
39
|
+
# @return [undefined]
|
40
|
+
#
|
41
|
+
# @api private
|
42
|
+
#
|
43
|
+
def emit_assignment
|
44
|
+
return unless assignment
|
45
|
+
write(WS, T_ASR, WS)
|
46
|
+
visit(assignment)
|
47
|
+
end
|
48
|
+
|
49
|
+
end # Resbody
|
50
|
+
end # Emitter
|
51
|
+
end # Unparser
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module Unparser
|
2
|
+
class Emitter
|
3
|
+
# Emitter for rescue nodes
|
4
|
+
class Rescue < self
|
5
|
+
|
6
|
+
handle :rescue
|
7
|
+
|
8
|
+
children :body
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
# Perform dispatch
|
13
|
+
#
|
14
|
+
# @return [undefined]
|
15
|
+
#
|
16
|
+
# @api private
|
17
|
+
#
|
18
|
+
def dispatch
|
19
|
+
visit_indented(body)
|
20
|
+
rescue_bodies.each do |child|
|
21
|
+
visit(child)
|
22
|
+
end
|
23
|
+
emit_else
|
24
|
+
end
|
25
|
+
|
26
|
+
# Return rescue bodies
|
27
|
+
#
|
28
|
+
# @return [Enumerable<Parser::AST::Node>]
|
29
|
+
#
|
30
|
+
# @api private
|
31
|
+
#
|
32
|
+
def rescue_bodies
|
33
|
+
children[1..-2]
|
34
|
+
end
|
35
|
+
|
36
|
+
# Emit else
|
37
|
+
#
|
38
|
+
# @return [undefined]
|
39
|
+
#
|
40
|
+
# @api private
|
41
|
+
#
|
42
|
+
def emit_else
|
43
|
+
return unless else_branch
|
44
|
+
write(K_ELSE)
|
45
|
+
visit_indented(else_branch)
|
46
|
+
end
|
47
|
+
|
48
|
+
# Return else body
|
49
|
+
#
|
50
|
+
# @return [Parser::AST::Node]
|
51
|
+
# if else body is present
|
52
|
+
#
|
53
|
+
# @return [nil]
|
54
|
+
# otherwise
|
55
|
+
#
|
56
|
+
# @api private
|
57
|
+
#
|
58
|
+
def else_branch
|
59
|
+
children.last
|
60
|
+
end
|
61
|
+
|
62
|
+
end # Rescue
|
63
|
+
end # Emitter
|
64
|
+
end # Unparser
|
@@ -8,12 +8,14 @@ module Unparser
|
|
8
8
|
INDEX_PARENS = IceNine.deep_freeze(%w([ ]))
|
9
9
|
NORMAL_PARENS = IceNine.deep_freeze(%w[( )])
|
10
10
|
|
11
|
-
INDEX_REFERENCE = '[]'
|
12
|
-
INDEX_ASSIGN = '[]='
|
11
|
+
INDEX_REFERENCE = :'[]'
|
12
|
+
INDEX_ASSIGN = :'[]='
|
13
13
|
ASSIGN_SUFFIX = '='.freeze
|
14
14
|
|
15
15
|
AMBIGOUS = [:irange, :erange].to_set.freeze
|
16
16
|
|
17
|
+
children :receiver, :selector
|
18
|
+
|
17
19
|
private
|
18
20
|
|
19
21
|
# Perform dispatch
|
@@ -33,6 +35,17 @@ module Unparser
|
|
33
35
|
end
|
34
36
|
end
|
35
37
|
|
38
|
+
# Return string selector
|
39
|
+
#
|
40
|
+
# @return [String]
|
41
|
+
#
|
42
|
+
# @api private
|
43
|
+
#
|
44
|
+
def string_selector
|
45
|
+
selector.to_s
|
46
|
+
end
|
47
|
+
memoize :string_selector
|
48
|
+
|
36
49
|
# Emit unambiguous receiver
|
37
50
|
#
|
38
51
|
# @return [undefined]
|
@@ -150,7 +163,7 @@ module Unparser
|
|
150
163
|
# @api private
|
151
164
|
#
|
152
165
|
def unary?
|
153
|
-
UNARY_OPERATORS.include?(
|
166
|
+
UNARY_OPERATORS.include?(selector)
|
154
167
|
end
|
155
168
|
|
156
169
|
# Test for binary operator implemented as method
|
@@ -164,7 +177,7 @@ module Unparser
|
|
164
177
|
# @api private
|
165
178
|
#
|
166
179
|
def binary?
|
167
|
-
BINARY_OPERATORS.include?(
|
180
|
+
BINARY_OPERATORS.include?(selector) && arguments.length == 1 && arguments.first.type != :splat
|
168
181
|
end
|
169
182
|
|
170
183
|
# Emit selector
|
@@ -174,7 +187,7 @@ module Unparser
|
|
174
187
|
# @api private
|
175
188
|
#
|
176
189
|
def emit_selector
|
177
|
-
name =
|
190
|
+
name = string_selector
|
178
191
|
if mlhs?
|
179
192
|
name = name[0..-2]
|
180
193
|
end
|
@@ -206,19 +219,8 @@ module Unparser
|
|
206
219
|
# @api private
|
207
220
|
#
|
208
221
|
def assignment?
|
209
|
-
|
210
|
-
end
|
211
|
-
|
212
|
-
# Return selector
|
213
|
-
#
|
214
|
-
# @return [String]
|
215
|
-
#
|
216
|
-
# @api private
|
217
|
-
#
|
218
|
-
def selector
|
219
|
-
children[1].to_s
|
222
|
+
string_selector[-1] == ASSIGN_SUFFIX
|
220
223
|
end
|
221
|
-
memoize :selector
|
222
224
|
|
223
225
|
# Test for empty arguments
|
224
226
|
#
|
@@ -26,7 +26,6 @@ module Unparser
|
|
26
26
|
#
|
27
27
|
def emit_receiver
|
28
28
|
emit_unambiguous_receiver
|
29
|
-
write(T_DOT) if parentheses?
|
30
29
|
end
|
31
30
|
|
32
31
|
# Emit operator
|
@@ -36,8 +35,7 @@ module Unparser
|
|
36
35
|
# @api private
|
37
36
|
#
|
38
37
|
def emit_operator
|
39
|
-
|
40
|
-
parentheses(parens, parens) { write(selector) }
|
38
|
+
write(WS, string_selector, WS)
|
41
39
|
end
|
42
40
|
|
43
41
|
# Return right node
|
@@ -50,35 +48,6 @@ module Unparser
|
|
50
48
|
children[2]
|
51
49
|
end
|
52
50
|
|
53
|
-
# Test for splat argument
|
54
|
-
#
|
55
|
-
# @return [true]
|
56
|
-
# if first argument is a splat
|
57
|
-
#
|
58
|
-
# @return [false]
|
59
|
-
# otherwise
|
60
|
-
#
|
61
|
-
# @api private
|
62
|
-
#
|
63
|
-
def splat?
|
64
|
-
right_node.type == :splat
|
65
|
-
end
|
66
|
-
|
67
|
-
# Test if parentheses are needed
|
68
|
-
#
|
69
|
-
# @return [true]
|
70
|
-
# if parenthes are needed
|
71
|
-
#
|
72
|
-
# @return [false]
|
73
|
-
# otherwise
|
74
|
-
#
|
75
|
-
# @api private
|
76
|
-
#
|
77
|
-
def parentheses?
|
78
|
-
splat? || children.length >= 4
|
79
|
-
end
|
80
|
-
memoize :parentheses?
|
81
|
-
|
82
51
|
# Emit right
|
83
52
|
#
|
84
53
|
# @return [undefined]
|
@@ -86,12 +55,7 @@ module Unparser
|
|
86
55
|
# @api private
|
87
56
|
#
|
88
57
|
def emit_right
|
89
|
-
|
90
|
-
if parentheses?
|
91
|
-
parentheses { delimited(children[2..-1]) }
|
92
|
-
return
|
93
|
-
end
|
94
|
-
visit(node)
|
58
|
+
visit(right_node)
|
95
59
|
end
|
96
60
|
|
97
61
|
end # Binary
|
@@ -7,8 +7,8 @@ module Unparser
|
|
7
7
|
private
|
8
8
|
|
9
9
|
MAP = IceNine.deep_freeze(
|
10
|
-
'-@' => '-',
|
11
|
-
'+@' => '+'
|
10
|
+
:'-@' => '-',
|
11
|
+
:'+@' => '+'
|
12
12
|
)
|
13
13
|
|
14
14
|
# Perform dispatch
|
@@ -19,7 +19,7 @@ module Unparser
|
|
19
19
|
#
|
20
20
|
def dispatch
|
21
21
|
name = selector
|
22
|
-
write(MAP.fetch(name, name))
|
22
|
+
write(MAP.fetch(name, name).to_s)
|
23
23
|
emit_unambiguous_receiver
|
24
24
|
end
|
25
25
|
|
@@ -196,8 +196,8 @@ describe Unparser, 'spike' do
|
|
196
196
|
|
197
197
|
context 'magic keywords' do
|
198
198
|
assert_generates '__ENCODING__', 'Encoding::UTF_8', RUBIES - %w(1.8)
|
199
|
-
|
200
|
-
|
199
|
+
assert_source '__FILE__'
|
200
|
+
assert_source '__LINE__'
|
201
201
|
end
|
202
202
|
|
203
203
|
context 'assignment' do
|
@@ -730,13 +730,11 @@ describe Unparser, 'spike' do
|
|
730
730
|
context 'class' do
|
731
731
|
assert_source <<-RUBY
|
732
732
|
class TestClass
|
733
|
-
|
734
733
|
end
|
735
734
|
RUBY
|
736
735
|
|
737
736
|
assert_source <<-RUBY
|
738
737
|
class << some_object
|
739
|
-
|
740
738
|
end
|
741
739
|
RUBY
|
742
740
|
|
@@ -748,25 +746,21 @@ describe Unparser, 'spike' do
|
|
748
746
|
|
749
747
|
assert_source <<-RUBY
|
750
748
|
class SomeNameSpace::TestClass
|
751
|
-
|
752
749
|
end
|
753
750
|
RUBY
|
754
751
|
|
755
752
|
assert_source <<-RUBY
|
756
753
|
class Some::Name::Space::TestClass
|
757
|
-
|
758
754
|
end
|
759
755
|
RUBY
|
760
756
|
|
761
757
|
assert_source <<-RUBY
|
762
758
|
class TestClass < Object
|
763
|
-
|
764
759
|
end
|
765
760
|
RUBY
|
766
761
|
|
767
762
|
assert_source <<-RUBY
|
768
763
|
class TestClass < SomeNameSpace::Object
|
769
|
-
|
770
764
|
end
|
771
765
|
RUBY
|
772
766
|
|
@@ -780,7 +774,6 @@ describe Unparser, 'spike' do
|
|
780
774
|
|
781
775
|
assert_source <<-RUBY
|
782
776
|
class ::TestClass
|
783
|
-
|
784
777
|
end
|
785
778
|
RUBY
|
786
779
|
end
|
@@ -789,19 +782,16 @@ describe Unparser, 'spike' do
|
|
789
782
|
|
790
783
|
assert_source <<-RUBY
|
791
784
|
module TestModule
|
792
|
-
|
793
785
|
end
|
794
786
|
RUBY
|
795
787
|
|
796
788
|
assert_source <<-RUBY
|
797
789
|
module SomeNameSpace::TestModule
|
798
|
-
|
799
790
|
end
|
800
791
|
RUBY
|
801
792
|
|
802
793
|
assert_source <<-RUBY
|
803
794
|
module Some::Name::Space::TestModule
|
804
|
-
|
805
795
|
end
|
806
796
|
RUBY
|
807
797
|
|
@@ -880,6 +870,12 @@ describe Unparser, 'spike' do
|
|
880
870
|
end
|
881
871
|
end
|
882
872
|
|
873
|
+
context 'nested binary operators' do
|
874
|
+
assert_source '(a + b) / (c - d)'
|
875
|
+
assert_source '(a + b) / (c.-(e, f))'
|
876
|
+
assert_source '(a + b) / (c.-(*f))'
|
877
|
+
end
|
878
|
+
|
883
879
|
context 'binary operator' do
|
884
880
|
assert_source '((a) || (break(foo)))'
|
885
881
|
assert_source '((break(foo)) || (a))'
|
@@ -1058,4 +1054,5 @@ describe Unparser, 'spike' do
|
|
1058
1054
|
end
|
1059
1055
|
RUBY
|
1060
1056
|
end
|
1057
|
+
|
1061
1058
|
end
|
@@ -4,7 +4,7 @@ describe Unparser::Emitter, '.visit' do
|
|
4
4
|
subject { object.visit(node, buffer) }
|
5
5
|
let(:object) { described_class }
|
6
6
|
|
7
|
-
let(:node) {
|
7
|
+
let(:node) { double('Node', :type => type, :source_map => nil) }
|
8
8
|
let(:buffer) { Unparser::Buffer.new }
|
9
9
|
|
10
10
|
before do
|
@@ -6,10 +6,10 @@ describe Unparser::Emitter::SourceMap, '.emit' do
|
|
6
6
|
let(:buffer) { Unparser::Buffer.new }
|
7
7
|
|
8
8
|
let(:node) do
|
9
|
-
|
9
|
+
double('Node',
|
10
10
|
:type => :foo,
|
11
|
-
:location =>
|
12
|
-
:expression =>
|
11
|
+
:location => double('SourceMap',
|
12
|
+
:expression => double('SourceRange', :source => 'foo')
|
13
13
|
)
|
14
14
|
)
|
15
15
|
end
|
data/unparser.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = 'unparser'
|
5
|
-
s.version = '0.0.
|
5
|
+
s.version = '0.0.10'
|
6
6
|
|
7
7
|
s.authors = ['Markus Schirp']
|
8
8
|
s.email = 'mbj@schir-dso.com'
|
@@ -17,9 +17,9 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.extra_rdoc_files = %w(README.md)
|
18
18
|
s.executables = [ 'test-unparser' ]
|
19
19
|
|
20
|
-
s.add_dependency('parser', '~> 2.0.0.
|
21
|
-
s.add_dependency('concord', '~> 0.1.
|
22
|
-
s.add_dependency('adamantium', '~> 0.0.
|
20
|
+
s.add_dependency('parser', '~> 2.0.0.pre3')
|
21
|
+
s.add_dependency('concord', '~> 0.1.1')
|
22
|
+
s.add_dependency('adamantium', '~> 0.0.10')
|
23
23
|
s.add_dependency('equalizer', '~> 0.0.5')
|
24
24
|
s.add_dependency('abstract_type', '~> 0.0.5')
|
25
25
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unparser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Markus Schirp
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-07-
|
11
|
+
date: 2013-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|
@@ -16,42 +16,42 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 2.0.0.
|
19
|
+
version: 2.0.0.pre3
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 2.0.0.
|
26
|
+
version: 2.0.0.pre3
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: concord
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.1.
|
33
|
+
version: 0.1.1
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.1.
|
40
|
+
version: 0.1.1
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: adamantium
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ~>
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.0.
|
47
|
+
version: 0.0.10
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.0.
|
54
|
+
version: 0.0.10
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: equalizer
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -88,7 +88,6 @@ extensions: []
|
|
88
88
|
extra_rdoc_files:
|
89
89
|
- README.md
|
90
90
|
files:
|
91
|
-
- .circle.yml
|
92
91
|
- .gitignore
|
93
92
|
- .rspec
|
94
93
|
- .travis.yml
|
@@ -101,6 +100,7 @@ files:
|
|
101
100
|
- Rakefile
|
102
101
|
- TODO
|
103
102
|
- bin/test-unparser
|
103
|
+
- circle.yml
|
104
104
|
- config/devtools.yml
|
105
105
|
- config/flay.yml
|
106
106
|
- config/flog.yml
|
@@ -124,6 +124,7 @@ files:
|
|
124
124
|
- lib/unparser/emitter/def.rb
|
125
125
|
- lib/unparser/emitter/defined.rb
|
126
126
|
- lib/unparser/emitter/empty.rb
|
127
|
+
- lib/unparser/emitter/ensure.rb
|
127
128
|
- lib/unparser/emitter/flipflop.rb
|
128
129
|
- lib/unparser/emitter/for.rb
|
129
130
|
- lib/unparser/emitter/hookexe.rb
|
@@ -144,6 +145,8 @@ files:
|
|
144
145
|
- lib/unparser/emitter/op_assign.rb
|
145
146
|
- lib/unparser/emitter/redo.rb
|
146
147
|
- lib/unparser/emitter/repetition.rb
|
148
|
+
- lib/unparser/emitter/resbody.rb
|
149
|
+
- lib/unparser/emitter/rescue.rb
|
147
150
|
- lib/unparser/emitter/retry.rb
|
148
151
|
- lib/unparser/emitter/return.rb
|
149
152
|
- lib/unparser/emitter/root.rb
|