unparser 0.4.7 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (143) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -2
  3. data/bin/unparser +1 -1
  4. data/lib/unparser.rb +134 -62
  5. data/lib/unparser/ast.rb +0 -1
  6. data/lib/unparser/ast/local_variable_scope.rb +6 -76
  7. data/lib/unparser/buffer.rb +19 -16
  8. data/lib/unparser/cli.rb +84 -77
  9. data/lib/unparser/{cli/color.rb → color.rb} +0 -13
  10. data/lib/unparser/comments.rb +0 -26
  11. data/lib/unparser/constants.rb +4 -53
  12. data/lib/unparser/diff.rb +98 -0
  13. data/lib/unparser/dsl.rb +0 -32
  14. data/lib/unparser/emitter.rb +24 -425
  15. data/lib/unparser/emitter/alias.rb +2 -8
  16. data/lib/unparser/emitter/args.rb +45 -0
  17. data/lib/unparser/emitter/argument.rb +8 -166
  18. data/lib/unparser/emitter/array.rb +27 -0
  19. data/lib/unparser/emitter/array_pattern.rb +29 -0
  20. data/lib/unparser/emitter/assignment.rb +36 -127
  21. data/lib/unparser/emitter/begin.rb +9 -84
  22. data/lib/unparser/emitter/binary.rb +7 -20
  23. data/lib/unparser/emitter/block.rb +57 -41
  24. data/lib/unparser/emitter/case.rb +6 -48
  25. data/lib/unparser/emitter/case_guard.rb +27 -0
  26. data/lib/unparser/emitter/case_match.rb +40 -0
  27. data/lib/unparser/emitter/cbase.rb +1 -3
  28. data/lib/unparser/emitter/class.rb +6 -26
  29. data/lib/unparser/emitter/const_pattern.rb +24 -0
  30. data/lib/unparser/emitter/def.rb +7 -51
  31. data/lib/unparser/emitter/defined.rb +2 -12
  32. data/lib/unparser/emitter/dstr.rb +22 -0
  33. data/lib/unparser/emitter/dsym.rb +41 -0
  34. data/lib/unparser/emitter/flipflop.rb +11 -10
  35. data/lib/unparser/emitter/float.rb +29 -0
  36. data/lib/unparser/emitter/flow_modifier.rb +8 -55
  37. data/lib/unparser/emitter/for.rb +5 -19
  38. data/lib/unparser/emitter/hash.rb +74 -0
  39. data/lib/unparser/emitter/hash_pattern.rb +67 -0
  40. data/lib/unparser/emitter/hookexe.rb +5 -11
  41. data/lib/unparser/emitter/if.rb +9 -73
  42. data/lib/unparser/emitter/in_match.rb +21 -0
  43. data/lib/unparser/emitter/in_pattern.rb +34 -0
  44. data/lib/unparser/emitter/index.rb +21 -88
  45. data/lib/unparser/emitter/kwbegin.rb +31 -0
  46. data/lib/unparser/emitter/lambda.rb +0 -8
  47. data/lib/unparser/emitter/masgn.rb +20 -0
  48. data/lib/unparser/emitter/match.rb +3 -17
  49. data/lib/unparser/emitter/match_alt.rb +23 -0
  50. data/lib/unparser/emitter/match_as.rb +21 -0
  51. data/lib/unparser/emitter/match_rest.rb +26 -0
  52. data/lib/unparser/emitter/match_var.rb +19 -0
  53. data/lib/unparser/emitter/mlhs.rb +40 -0
  54. data/lib/unparser/emitter/module.rb +3 -9
  55. data/lib/unparser/emitter/op_assign.rb +12 -27
  56. data/lib/unparser/emitter/pin.rb +19 -0
  57. data/lib/unparser/emitter/primitive.rb +93 -0
  58. data/lib/unparser/emitter/range.rb +35 -0
  59. data/lib/unparser/emitter/regexp.rb +35 -0
  60. data/lib/unparser/emitter/repetition.rb +17 -57
  61. data/lib/unparser/emitter/rescue.rb +1 -97
  62. data/lib/unparser/emitter/root.rb +17 -1
  63. data/lib/unparser/emitter/send.rb +10 -219
  64. data/lib/unparser/emitter/simple.rb +33 -0
  65. data/lib/unparser/emitter/splat.rb +2 -18
  66. data/lib/unparser/emitter/super.rb +1 -29
  67. data/lib/unparser/emitter/undef.rb +1 -9
  68. data/lib/unparser/emitter/variable.rb +1 -31
  69. data/lib/unparser/emitter/xstr.rb +72 -0
  70. data/lib/unparser/emitter/yield.rb +1 -9
  71. data/lib/unparser/generation.rb +250 -0
  72. data/lib/unparser/node_details.rb +21 -0
  73. data/lib/unparser/node_details/send.rb +62 -0
  74. data/lib/unparser/node_helpers.rb +45 -6
  75. data/lib/unparser/validation.rb +172 -0
  76. data/lib/unparser/writer.rb +15 -0
  77. data/lib/unparser/writer/binary.rb +99 -0
  78. data/lib/unparser/writer/dynamic_string.rb +233 -0
  79. data/lib/unparser/writer/resbody.rb +40 -0
  80. data/lib/unparser/writer/rescue.rb +39 -0
  81. data/lib/unparser/writer/send.rb +124 -0
  82. data/lib/unparser/{emitter → writer}/send/attribute_assignment.rb +11 -26
  83. data/lib/unparser/writer/send/binary.rb +27 -0
  84. data/lib/unparser/writer/send/conditional.rb +25 -0
  85. data/lib/unparser/writer/send/regular.rb +33 -0
  86. data/lib/unparser/{emitter → writer}/send/unary.rb +10 -17
  87. metadata +127 -104
  88. data/.circleci/config.yml +0 -49
  89. data/.gitignore +0 -37
  90. data/.rspec +0 -4
  91. data/.rubocop.yml +0 -9
  92. data/Changelog.md +0 -156
  93. data/Gemfile +0 -9
  94. data/Gemfile.lock +0 -181
  95. data/LICENSE +0 -20
  96. data/Rakefile +0 -22
  97. data/config/devtools.yml +0 -2
  98. data/config/flay.yml +0 -3
  99. data/config/flog.yml +0 -2
  100. data/config/mutant.yml +0 -6
  101. data/config/reek.yml +0 -98
  102. data/config/rubocop.yml +0 -122
  103. data/config/yardstick.yml +0 -2
  104. data/lib/unparser/cli/differ.rb +0 -152
  105. data/lib/unparser/cli/source.rb +0 -267
  106. data/lib/unparser/emitter/empty.rb +0 -23
  107. data/lib/unparser/emitter/ensure.rb +0 -37
  108. data/lib/unparser/emitter/literal.rb +0 -10
  109. data/lib/unparser/emitter/literal/array.rb +0 -29
  110. data/lib/unparser/emitter/literal/dynamic.rb +0 -53
  111. data/lib/unparser/emitter/literal/dynamic_body.rb +0 -132
  112. data/lib/unparser/emitter/literal/execute_string.rb +0 -38
  113. data/lib/unparser/emitter/literal/hash.rb +0 -156
  114. data/lib/unparser/emitter/literal/primitive.rb +0 -145
  115. data/lib/unparser/emitter/literal/range.rb +0 -36
  116. data/lib/unparser/emitter/literal/regexp.rb +0 -114
  117. data/lib/unparser/emitter/literal/singleton.rb +0 -26
  118. data/lib/unparser/emitter/meta.rb +0 -16
  119. data/lib/unparser/emitter/redo.rb +0 -25
  120. data/lib/unparser/emitter/resbody.rb +0 -76
  121. data/lib/unparser/emitter/retry.rb +0 -25
  122. data/lib/unparser/emitter/send/binary.rb +0 -57
  123. data/lib/unparser/emitter/send/conditional.rb +0 -40
  124. data/lib/unparser/emitter/send/regular.rb +0 -40
  125. data/lib/unparser/preprocessor.rb +0 -159
  126. data/spec/integration/unparser/corpus_spec.rb +0 -111
  127. data/spec/integrations.yml +0 -92
  128. data/spec/spec_helper.rb +0 -20
  129. data/spec/unit/unparser/buffer/append_spec.rb +0 -24
  130. data/spec/unit/unparser/buffer/append_without_prefix_spec.rb +0 -23
  131. data/spec/unit/unparser/buffer/capture_content_spec.rb +0 -17
  132. data/spec/unit/unparser/buffer/content_spec.rb +0 -38
  133. data/spec/unit/unparser/buffer/fresh_line_spec.rb +0 -20
  134. data/spec/unit/unparser/buffer/indent_spec.rb +0 -20
  135. data/spec/unit/unparser/buffer/nl_spec.rb +0 -16
  136. data/spec/unit/unparser/buffer/unindent_spec.rb +0 -20
  137. data/spec/unit/unparser/comments/consume_spec.rb +0 -22
  138. data/spec/unit/unparser/comments/take_all_spec.rb +0 -19
  139. data/spec/unit/unparser/comments/take_before_spec.rb +0 -46
  140. data/spec/unit/unparser/comments/take_eol_comments_spec.rb +0 -32
  141. data/spec/unit/unparser/emitter/class_methods/handle_spec.rb +0 -17
  142. data/spec/unit/unparser_spec.rb +0 -1849
  143. data/unparser.gemspec +0 -32
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Unparser
4
- class Emitter
5
-
6
- # Emitter for artifical empty node
7
- class Empty < self
8
-
9
- handle :empty
10
-
11
- private
12
-
13
- # Perform dispatch
14
- #
15
- # @return [undefined]
16
- #
17
- # @api private
18
- #
19
- def dispatch; end
20
-
21
- end
22
- end
23
- end # Unparser
@@ -1,37 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Unparser
4
- class Emitter
5
-
6
- # Emitter for ensure nodes
7
- class Ensure < self
8
-
9
- handle :ensure
10
-
11
- children :body, :ensure_body
12
-
13
- private
14
-
15
- # Perform dispatch
16
- #
17
- # @return [undefined]
18
- #
19
- # @api private
20
- #
21
- def dispatch
22
- if body
23
- visit_indented(body)
24
- else
25
- nl
26
- end
27
- write(K_ENSURE)
28
- if ensure_body
29
- visit_indented(ensure_body)
30
- else
31
- nl
32
- end
33
- end
34
-
35
- end # Ensure
36
- end # Emitter
37
- end # Unparser
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Unparser
4
- class Emitter
5
- # Namespace class for literal emiters
6
- class Literal < self
7
- include Terminated
8
- end # Literal
9
- end # Emitter
10
- end # Unparser
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Unparser
4
- class Emitter
5
- class Literal
6
-
7
- # Array literal emitter
8
- class Array < self
9
- handle :array
10
-
11
- private
12
-
13
- # Perform dispatch
14
- #
15
- # @return [undefined]
16
- #
17
- # @api private
18
- #
19
- def dispatch
20
- parentheses(*BRACKETS_SQUARE) do
21
- delimited(children)
22
- end
23
- end
24
-
25
- end # Array
26
-
27
- end # Literal
28
- end # Emitter
29
- end # Unparser
@@ -1,53 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Unparser
4
- class Emitter
5
- class Literal
6
-
7
- # Base class for dynamic literal emitters
8
- class Dynamic < self
9
-
10
- private
11
-
12
- # Perform dispatch
13
- #
14
- # @return [undefined]
15
- #
16
- # @api private
17
- #
18
- def dispatch
19
- util = self.class
20
- visit_parentheses(dynamic_body, util::OPEN, util::CLOSE)
21
- end
22
-
23
- # Return dynamic body
24
- #
25
- # @return [Parser::AST::Node]
26
- #
27
- # @api private
28
- #
29
- def dynamic_body
30
- Parser::AST::Node.new(:dyn_str_body, children)
31
- end
32
-
33
- # Dynamic string literal emitter
34
- class String < self
35
-
36
- OPEN = CLOSE = '"'.freeze
37
- handle :dstr
38
-
39
- end # String
40
-
41
- # Dynamic symbol literal emitter
42
- class Symbol < self
43
-
44
- OPEN = ':"'.freeze
45
- CLOSE = '"'.freeze
46
-
47
- handle :dsym
48
-
49
- end # Symbol
50
- end # Dynamic
51
- end # Literal
52
- end # Emitter
53
- end # Unparser
@@ -1,132 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Unparser
4
- class Emitter
5
- class Literal
6
-
7
- # Emitter for dynamic bodies
8
- class DynamicBody < self
9
-
10
- OPEN = '#{'.freeze
11
- CLOSE = '}'.freeze
12
-
13
- # Emitter for interpolated nodes
14
- class Interpolation < self
15
-
16
- handle :interpolated
17
-
18
- children :subject
19
-
20
- private
21
-
22
- # Perform dispatch
23
- #
24
- # @return [undefined]
25
- #
26
- # @api private
27
- #
28
- def dispatch
29
- write(OPEN)
30
- visit_plain(subject)
31
- write(CLOSE)
32
- end
33
-
34
- end
35
-
36
- private
37
-
38
- # Perform dispatch
39
- #
40
- # @return [undefined]
41
- #
42
- # @api private
43
- #
44
- def dispatch
45
- children.each(&method(:emit_segment))
46
- end
47
-
48
- # Emit segment
49
- #
50
- # @param [Parser::AST::Node] node
51
- #
52
- # @return [undefined]
53
- #
54
- # @api private
55
- #
56
- def emit_segment(node)
57
- emit_interpolated_segment(node)
58
- end
59
-
60
- pairs = Parser::Lexer::ESCAPES.invert.map do |key, value|
61
- [key, "\\#{value}"] unless key.eql?(WS)
62
- end.compact
63
-
64
- pairs << ['#{', '\#{']
65
-
66
- ESCAPES = ::Hash[pairs]
67
-
68
- REPLACEMENTS = ::Regexp.union(ESCAPES.keys)
69
-
70
- # Emit str segment
71
- #
72
- # @param [Parser::AST::Node] node
73
- #
74
- # @return [undefined]
75
- #
76
- # @api private
77
- #
78
- def emit_str_segment(node)
79
- util = self.class
80
- string = node.children.first
81
- segment = string
82
- .gsub(REPLACEMENTS, ESCAPES)
83
- .gsub(util::DELIMITER, util::REPLACEMENT)
84
- write(segment)
85
- end
86
-
87
- # Emit interpolated segment
88
- #
89
- # @param [Parser::AST::Node] node
90
- #
91
- # @return [undefined]
92
- #
93
- # @api private
94
- #
95
- def emit_interpolated_segment(node)
96
- visit_parentheses(node, OPEN, CLOSE)
97
- end
98
-
99
- # Dynamic string body
100
- class String < self
101
-
102
- handle :dyn_str_body
103
-
104
- DELIMITER = '"'.freeze
105
- REPLACEMENT = '\"'.freeze
106
-
107
- end # String
108
-
109
- # Dynamic regexp body
110
- class Regexp < self
111
-
112
- handle :dyn_regexp_body
113
-
114
- DELIMITER = '/'.freeze
115
- REPLACEMENT = '\/'.freeze
116
-
117
- end # Regexp
118
-
119
- # Dynamic regexp body
120
- class ExecuteString < self
121
-
122
- handle :dyn_xstr_body
123
-
124
- DELIMITER = '`'.freeze
125
- REPLACEMENT = '\`'.freeze
126
-
127
- end # ExecuteString
128
-
129
- end # DynamicBody
130
- end # Literal
131
- end # Emitter
132
- end # Unparser
@@ -1,38 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Unparser
4
- class Emitter
5
- class Literal
6
- # Emitter for execute strings (xstr) nodes
7
- class ExecuteString < self
8
-
9
- OPEN = CLOSE = '`'.freeze
10
-
11
- handle :xstr
12
-
13
- private
14
-
15
- # Perform dispatch
16
- #
17
- # @return [undefined]
18
- #
19
- # @api private
20
- #
21
- def dispatch
22
- visit_parentheses(dynamic_body, OPEN, CLOSE)
23
- end
24
-
25
- # Return dynamic body
26
- #
27
- # @return [Parser::AST::Node]
28
- #
29
- # @api private
30
- #
31
- def dynamic_body
32
- Parser::AST::Node.new(:dyn_xstr_body, children)
33
- end
34
-
35
- end # ExecuteString
36
- end # Literal
37
- end # Emitter
38
- end # Unparser
@@ -1,156 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Unparser
4
- class Emitter
5
- class Literal
6
-
7
- # Abstract namespace class for hash pair emitters
8
- class HashPair < self
9
-
10
- children :key, :value
11
-
12
- private
13
-
14
- # Emit value
15
- #
16
- # @return [undefined]
17
- #
18
- # @api private
19
- #
20
- def emit_value
21
- value_type = value.type
22
- conditional_parentheses(value_type.equal?(:if)) do
23
- visit(value)
24
- end
25
- end
26
-
27
- # Pair emitter that emits hash-rocket separated key values
28
- class Rocket < self
29
- HASHROCKET = ' => '.freeze
30
-
31
- handle :pair_rocket, :pair
32
-
33
- private
34
-
35
- # Perform dispatch
36
- #
37
- # @return [undefined]
38
- #
39
- # @api private
40
- #
41
- def dispatch
42
- visit(key)
43
- write(HASHROCKET)
44
- emit_value
45
- end
46
-
47
- end # Rocket
48
-
49
- # Pair emitter that emits colon separated key values
50
- class Colon < self
51
- COLON = ': '.freeze
52
-
53
- handle :pair_colon
54
-
55
- private
56
-
57
- # Perform dispatch
58
- #
59
- # @return [undefined]
60
- #
61
- # @api private
62
- #
63
- def dispatch
64
- write(key.children.first.to_s, COLON)
65
- emit_value
66
- end
67
-
68
- end # Colon
69
-
70
- end # HashPair
71
-
72
- # Emitter for hash bodies
73
- class HashBody < self
74
-
75
- BAREWORD = /\A[A-Za-z_][A-Za-z_0-9]*[?!]?\z/.freeze
76
-
77
- handle :hash_body
78
-
79
- private
80
-
81
- # Perform dispatch
82
- #
83
- # @return [undefined]
84
- #
85
- # @api private
86
- #
87
- def dispatch
88
- delimited(effective_body)
89
- end
90
-
91
- # Return effective body
92
- #
93
- # @return [Enumerable<Parser::AST::Node>]
94
- #
95
- # @api private
96
- #
97
- def effective_body
98
- children.map do |pair|
99
- if pair.type.equal?(:kwsplat)
100
- pair
101
- else
102
- key, _value = *pair
103
- if key.type.equal?(:sym) && key.children.first.to_s =~ BAREWORD
104
- n(:pair_colon, pair.children)
105
- else
106
- n(:pair_rocket, pair.children)
107
- end
108
- end
109
- end
110
- end
111
-
112
- end # HashBody
113
-
114
- # Emitter for Hash literals
115
- class Hash < self
116
-
117
- DELIMITER = ', '.freeze
118
- OPEN = '{'.freeze
119
- CLOSE = '}'.freeze
120
-
121
- handle :hash
122
-
123
- private
124
-
125
- # Perform dispatch
126
- #
127
- # @return [undefined]
128
- #
129
- # @api private
130
- #
131
- def dispatch
132
- if children.empty?
133
- write(OPEN, CLOSE)
134
- else
135
- emit_hash_body
136
- end
137
- end
138
-
139
- # Emit hash body
140
- #
141
- # @return [undefined]
142
- #
143
- # @api private
144
- #
145
- def emit_hash_body
146
- parentheses(OPEN, CLOSE) do
147
- write(WS)
148
- run(HashBody)
149
- write(WS)
150
- end
151
- end
152
-
153
- end # Hash
154
- end # Literal
155
- end # Emitter
156
- end # Unparser