parser 2.7.1.3 → 3.0.1.0

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.
Files changed (99) hide show
  1. checksums.yaml +4 -4
  2. data/lib/parser.rb +1 -1
  3. data/lib/parser/all.rb +1 -1
  4. data/lib/parser/ast/processor.rb +5 -7
  5. data/lib/parser/base.rb +7 -5
  6. data/lib/parser/builders/default.rb +225 -29
  7. data/lib/parser/context.rb +5 -0
  8. data/lib/parser/current.rb +11 -11
  9. data/lib/parser/current_arg_stack.rb +5 -2
  10. data/lib/parser/lexer.rb +23780 -0
  11. data/lib/parser/macruby.rb +6149 -0
  12. data/lib/parser/max_numparam_stack.rb +13 -5
  13. data/lib/parser/messages.rb +3 -0
  14. data/lib/parser/meta.rb +8 -7
  15. data/lib/parser/ruby18.rb +5667 -0
  16. data/lib/parser/ruby19.rb +6092 -0
  17. data/lib/parser/ruby20.rb +6527 -0
  18. data/lib/parser/ruby21.rb +6578 -0
  19. data/lib/parser/ruby22.rb +6613 -0
  20. data/lib/parser/ruby23.rb +6624 -0
  21. data/lib/parser/ruby24.rb +6694 -0
  22. data/lib/parser/ruby25.rb +6662 -0
  23. data/lib/parser/ruby26.rb +6676 -0
  24. data/lib/parser/ruby27.rb +7862 -0
  25. data/lib/parser/ruby28.rb +8047 -0
  26. data/lib/parser/ruby30.rb +8060 -0
  27. data/lib/parser/rubymotion.rb +6086 -0
  28. data/lib/parser/runner.rb +4 -4
  29. data/lib/parser/source/buffer.rb +50 -27
  30. data/lib/parser/source/comment.rb +1 -1
  31. data/lib/parser/source/comment/associator.rb +1 -1
  32. data/lib/parser/source/map/{endless_definition.rb → method_definition.rb} +5 -3
  33. data/lib/parser/source/range.rb +3 -3
  34. data/lib/parser/source/tree_rewriter.rb +94 -1
  35. data/lib/parser/source/tree_rewriter/action.rb +39 -0
  36. data/lib/parser/static_environment.rb +4 -0
  37. data/lib/parser/variables_stack.rb +4 -0
  38. data/lib/parser/version.rb +1 -1
  39. data/parser.gemspec +2 -18
  40. metadata +13 -102
  41. data/.gitignore +0 -34
  42. data/.travis.yml +0 -40
  43. data/.yardopts +0 -21
  44. data/CHANGELOG.md +0 -1101
  45. data/CONTRIBUTING.md +0 -17
  46. data/Gemfile +0 -10
  47. data/README.md +0 -308
  48. data/Rakefile +0 -167
  49. data/ci/run_rubocop_specs +0 -14
  50. data/doc/AST_FORMAT.md +0 -2229
  51. data/doc/CUSTOMIZATION.md +0 -37
  52. data/doc/INTERNALS.md +0 -21
  53. data/doc/css/.gitkeep +0 -0
  54. data/doc/css/common.css +0 -68
  55. data/lib/parser/lexer.rl +0 -2543
  56. data/lib/parser/macruby.y +0 -2198
  57. data/lib/parser/ruby18.y +0 -1934
  58. data/lib/parser/ruby19.y +0 -2175
  59. data/lib/parser/ruby20.y +0 -2353
  60. data/lib/parser/ruby21.y +0 -2357
  61. data/lib/parser/ruby22.y +0 -2364
  62. data/lib/parser/ruby23.y +0 -2370
  63. data/lib/parser/ruby24.y +0 -2408
  64. data/lib/parser/ruby25.y +0 -2405
  65. data/lib/parser/ruby26.y +0 -2413
  66. data/lib/parser/ruby27.y +0 -2941
  67. data/lib/parser/ruby28.y +0 -3016
  68. data/lib/parser/rubymotion.y +0 -2182
  69. data/test/bug_163/fixtures/input.rb +0 -5
  70. data/test/bug_163/fixtures/output.rb +0 -5
  71. data/test/bug_163/rewriter.rb +0 -20
  72. data/test/helper.rb +0 -79
  73. data/test/parse_helper.rb +0 -313
  74. data/test/racc_coverage_helper.rb +0 -133
  75. data/test/test_ast_processor.rb +0 -32
  76. data/test/test_base.rb +0 -31
  77. data/test/test_current.rb +0 -31
  78. data/test/test_diagnostic.rb +0 -95
  79. data/test/test_diagnostic_engine.rb +0 -59
  80. data/test/test_encoding.rb +0 -99
  81. data/test/test_lexer.rb +0 -3617
  82. data/test/test_lexer_stack_state.rb +0 -78
  83. data/test/test_meta.rb +0 -12
  84. data/test/test_parse_helper.rb +0 -80
  85. data/test/test_parser.rb +0 -9596
  86. data/test/test_runner_parse.rb +0 -56
  87. data/test/test_runner_rewrite.rb +0 -47
  88. data/test/test_source_buffer.rb +0 -165
  89. data/test/test_source_comment.rb +0 -36
  90. data/test/test_source_comment_associator.rb +0 -399
  91. data/test/test_source_map.rb +0 -14
  92. data/test/test_source_range.rb +0 -192
  93. data/test/test_source_rewriter.rb +0 -541
  94. data/test/test_source_rewriter_action.rb +0 -46
  95. data/test/test_source_tree_rewriter.rb +0 -263
  96. data/test/test_static_environment.rb +0 -45
  97. data/test/using_tree_rewriter/fixtures/input.rb +0 -3
  98. data/test/using_tree_rewriter/fixtures/output.rb +0 -3
  99. data/test/using_tree_rewriter/using_tree_rewriter.rb +0 -9
@@ -1,46 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'helper'
4
-
5
- class TestSourceRewriterAction < Minitest::Test
6
- def setup
7
- @buf = Parser::Source::Buffer.new('(rewriter_action)',
8
- source: 'foo bar baz')
9
- end
10
-
11
- def range(from, len)
12
- Parser::Source::Range.new(@buf, from, from + len)
13
- end
14
-
15
- def action(range, replacement)
16
- Parser::Source::Rewriter::Action.new(range, replacement)
17
- end
18
-
19
- def test_accessors
20
- action = action(range(1, 10), 'foo')
21
-
22
- assert action.frozen?
23
- assert_equal range(1, 10), action.range
24
- assert_equal 'foo', action.replacement
25
- end
26
-
27
- def test_to_s_replace
28
- action = action(range(3, 1), 'foo')
29
- assert_equal "replace 1 character(s) with \"foo\"", action.to_s
30
- end
31
-
32
- def test_to_s_insert
33
- action = action(range(3, 0), 'foo')
34
- assert_equal "insert \"foo\"", action.to_s
35
- end
36
-
37
- def test_to_s_remove
38
- action = action(range(3, 2), '')
39
- assert_equal 'remove 2 character(s)', action.to_s
40
- end
41
-
42
- def test_to_s_nop
43
- action = action(range(3, 0), '')
44
- assert_equal 'do nothing', action.to_s
45
- end
46
- end
@@ -1,263 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'helper'
4
-
5
- class TestSourceTreeRewriter < Minitest::Test
6
- def setup
7
- @buf = Parser::Source::Buffer.new('(rewriter)',
8
- source: 'puts(:hello, :world)')
9
-
10
- @hello = range(5, 6)
11
- @ll = range(7, 2)
12
- @comma_space = range(11,2)
13
- @world = range(13,6)
14
- @whole = range(0, @buf.source.length)
15
- end
16
-
17
- def range(from, len)
18
- Parser::Source::Range.new(@buf, from, from + len)
19
- end
20
-
21
- # Returns either:
22
- # - yield rewriter
23
- # - [diagnostic, ...] (Diagnostics)
24
- # - Parser::ClobberingError
25
- #
26
- def build(actions, **policy)
27
- diagnostics = []
28
- diags = -> { diagnostics.flatten.map(&:strip).join("\n") }
29
- rewriter = Parser::Source::TreeRewriter.new(@buf, **policy)
30
- rewriter.diagnostics.consumer = -> diag { diagnostics << diag.render }
31
- actions.each do |action, range, *args|
32
- rewriter.public_send(action, range, *args)
33
- end
34
- if diagnostics.empty?
35
- yield rewriter
36
- else
37
- diags.call
38
- end
39
- rescue ::Parser::ClobberingError => _e
40
- [::Parser::ClobberingError, diags.call]
41
- end
42
-
43
- # Returns either:
44
- # - String (Normal operation)
45
- # - [diagnostic, ...] (Diagnostics)
46
- # - Parser::ClobberingError
47
- #
48
- def apply(actions, **policy)
49
- build(actions, **policy) { |rewriter| rewriter.process }
50
- end
51
-
52
- # Expects ordered actions to be grouped together
53
- def check_actions(expected, grouped_actions, **policy)
54
- grouped_actions.permutation do |sequence|
55
- # [action, [action, action]] => [action, action, action]
56
- # except we can't use flatten because "action" are arrays themselves
57
- actions = sequence.flat_map { |group| group.first.is_a?(Array) ? group : [group] }
58
- assert_equal(expected, apply(actions, **policy))
59
- end
60
- end
61
-
62
- def assert_actions_result(expected, *actions, **rest)
63
- if expected == :raise
64
- diagnostic = rest.values.first
65
- check_actions([::Parser::ClobberingError, diagnostic], actions)
66
- elsif rest.empty?
67
- check_actions(expected, actions)
68
- else
69
- policy, diagnostic = rest.first
70
- check_actions(expected, actions, policy => :accept)
71
- check_actions(diagnostic, actions, policy => :warn)
72
- diagnostic.gsub!(/warning: /, 'error: ')
73
- check_actions([::Parser::ClobberingError, diagnostic], actions, policy => :raise)
74
- end
75
- end
76
-
77
- ### Simple cases
78
-
79
- def test_remove
80
- assert_actions_result 'puts(, :world)', [:remove, @hello]
81
- end
82
-
83
- def test_insert_before
84
- assert_actions_result 'puts(:hello, 42, :world)', [:insert_before, @world, '42, ']
85
- end
86
-
87
- def test_insert_after
88
- assert_actions_result 'puts(:hello, 42, :world)', [:insert_after, @hello, ', 42']
89
- end
90
-
91
- def test_wrap
92
- assert_actions_result 'puts([:hello], :world)', [:wrap, @hello, '[', ']']
93
- end
94
-
95
- def test_replace
96
- assert_actions_result 'puts(:hi, :world)', [:replace, @hello, ':hi']
97
- end
98
-
99
- #
100
- # All other cases, as per doc
101
- #
102
-
103
- def test_crossing_non_deletions
104
- check = [
105
- [:wrap, '(', ')'],
106
- [:remove],
107
- [:replace, 'xx'],
108
- ]
109
- check.combination(2) do |(action, *args), (action_b, *args_b)|
110
- next if action == :remove && action_b == :remove
111
- assert_actions_result :raise,
112
- [[action, @hello.join(@comma_space), *args],
113
- [action_b, @world.join(@comma_space), *args_b]],
114
- diagnostic: <<-DIAGNOSTIC.chomp
115
- (rewriter):1:12: error: the rewriting action on:
116
- (rewriter):1: puts(:hello, :world)
117
- (rewriter):1: ^~~~~~~~
118
- (rewriter):1:6: error: is crossing that on:
119
- (rewriter):1: puts(:hello, :world)
120
- (rewriter):1: ^~~~~~~~
121
- DIAGNOSTIC
122
- end
123
- end
124
-
125
-
126
- def test_crossing_deletions
127
- assert_actions_result 'puts()',
128
- [[:remove, @hello.join(@comma_space)],
129
- [:remove, @world.join(@comma_space)]],
130
- crossing_deletions: <<-DIAGNOSTIC.chomp
131
- (rewriter):1:12: warning: the deletion of:
132
- (rewriter):1: puts(:hello, :world)
133
- (rewriter):1: ^~~~~~~~
134
- (rewriter):1:6: warning: is crossing:
135
- (rewriter):1: puts(:hello, :world)
136
- (rewriter):1: ^~~~~~~~
137
- DIAGNOSTIC
138
- end
139
-
140
- def test_multiple_actions
141
- assert_actions_result 'puts({:hello => [:everybody]})',
142
- [:replace, @comma_space, ' => '],
143
- [:wrap, @hello.join(@world), '{', '}'],
144
- [:replace, @world, ':everybody'],
145
- [:wrap, @world, '[', ']']
146
- end
147
-
148
- def test_wraps_same_range
149
- assert_actions_result 'puts([(:hello)], :world)',
150
- [[:wrap, @hello, '(', ')'],
151
- [:wrap, @hello, '[', ']']]
152
- end
153
-
154
- def test_inserts_on_empty_ranges
155
- assert_actions_result 'puts({x}:hello[y], :world)',
156
- [:insert_before, @hello.begin, '{'],
157
- [:replace, @hello.begin, 'x'],
158
- [:insert_after, @hello.begin, '}'],
159
- [:insert_before, @hello.end, '['],
160
- [:replace, @hello.end, 'y'],
161
- [:insert_after, @hello.end, ']']
162
- end
163
-
164
- def test_replace_same_range
165
- assert_actions_result 'puts(:hey, :world)',
166
- [[:replace, @hello, ':hi'],
167
- [:replace, @hello, ':hey']],
168
- different_replacements: <<-DIAGNOSTIC.chomp
169
- (rewriter):1:6: warning: different replacements: :hey vs :hi
170
- (rewriter):1: puts(:hello, :world)
171
- (rewriter):1: ^~~~~~
172
- DIAGNOSTIC
173
- end
174
-
175
- def test_swallowed_insertions
176
- assert_actions_result 'puts(:hi)',
177
- [[:wrap, @hello.adjust(begin_pos: 1), '__', '__'],
178
- [:replace, @world.adjust(end_pos: -2), 'xx'],
179
- [:replace, @hello.join(@world), ':hi']],
180
- swallowed_insertions: <<-DIAGNOSTIC.chomp
181
- (rewriter):1:6: warning: this replacement:
182
- (rewriter):1: puts(:hello, :world)
183
- (rewriter):1: ^~~~~~~~~~~~~~
184
- (rewriter):1:7: warning: swallows some inner rewriting actions:
185
- (rewriter):1: puts(:hello, :world)
186
- (rewriter):1: ^~~~~ ~~~~
187
- DIAGNOSTIC
188
- end
189
-
190
- def test_out_of_range_ranges
191
- rewriter = Parser::Source::TreeRewriter.new(@buf)
192
- assert_raises(IndexError) { rewriter.insert_before(range(0, 100), 'hola') }
193
- end
194
-
195
- def test_empty
196
- rewriter = Parser::Source::TreeRewriter.new(@buf)
197
- assert_equal true, rewriter.empty?
198
-
199
- # This is a trivial wrap
200
- rewriter.wrap(range(2,3), '', '')
201
- assert_equal true, rewriter.empty?
202
-
203
- # This is a trivial deletion
204
- rewriter.remove(range(2,0))
205
- assert_equal true, rewriter.empty?
206
-
207
- rewriter.remove(range(2,3))
208
- assert_equal false, rewriter.empty?
209
- end
210
-
211
- # splits array into two groups, yield all such possible pairs of groups
212
- # each_split([1, 2, 3, 4]) yields [1, 2], [3, 4];
213
- # then [1, 3], [2, 4]
214
- # ...
215
- # and finally [3, 4], [1, 2]
216
- def each_split(array)
217
- n = array.size
218
- first_split_size = n.div(2)
219
- splitting = (0...n).to_set
220
- splitting.to_a.combination(first_split_size) do |indices|
221
- yield array.values_at(*indices),
222
- array.values_at(*(splitting - indices))
223
- end
224
- end
225
-
226
- # Checks that `actions+extra` give the same result when
227
- # made in order or from subgroups that are later merged.
228
- # The `extra` actions are always added at the end of the second group.
229
- #
230
- def check_all_merge_possibilities(actions, extra, **policy)
231
- expected = apply(actions + extra, **policy)
232
-
233
- each_split(actions) do |actions_1, actions_2|
234
- build(actions_1, **policy) do |rewriter_1|
235
- build(actions_2 + extra, **policy) do |rewriter_2|
236
- result = rewriter_1.merge(rewriter_2).process
237
- assert_equal(expected, result,
238
- "Group 1: #{actions_1.inspect}\n\n" +
239
- "Group 2: #{(actions_2 + extra).inspect}"
240
- )
241
- end
242
- end
243
- end
244
- end
245
-
246
- def test_merge
247
- check_all_merge_possibilities([
248
- [:wrap, @whole, '<', '>'],
249
- [:replace, @comma_space, ' => '],
250
- [:wrap, @hello, '!', '!'],
251
- # Following two wraps must have same value as they
252
- # will be applied in different orders...
253
- [:wrap, @hello.join(@world), '{', '}'],
254
- [:wrap, @hello.join(@world), '{', '}'],
255
- [:remove, @ll],
256
- [:replace, @world, ':everybody'],
257
- [:wrap, @world, '[', ']']
258
- ],
259
- [ # ... but this one is always going to be applied last (extra)
260
- [:wrap, @hello.join(@world), '@', '@'],
261
- ])
262
- end
263
- end
@@ -1,45 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'helper'
4
-
5
- class TestStaticEnvironment < Minitest::Test
6
- def setup
7
- @env = Parser::StaticEnvironment.new
8
- end
9
-
10
- def test_declare
11
- refute @env.declared?(:foo)
12
-
13
- @env.declare :foo
14
-
15
- assert @env.declared?(:foo)
16
- end
17
-
18
- def test_extend_static
19
- @env.declare :foo
20
- @env.extend_static
21
- @env.declare :bar
22
-
23
- refute @env.declared?(:foo)
24
- assert @env.declared?(:bar)
25
- end
26
-
27
- def test_extend_dynamic
28
- @env.declare :foo
29
- @env.extend_dynamic
30
- @env.declare :bar
31
-
32
- assert @env.declared?(:foo)
33
- assert @env.declared?(:bar)
34
- end
35
-
36
- def test_unextend
37
- @env.declare :foo
38
- @env.extend_dynamic
39
- @env.declare :bar
40
- @env.unextend
41
-
42
- assert @env.declared?(:foo)
43
- refute @env.declared?(:bar)
44
- end
45
- end
@@ -1,3 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- 6 * 7
@@ -1,3 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- ([6] * 7)
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class UsingTreeRewriter < Parser::TreeRewriter
4
- def on_send(node)
5
- wrap(node.loc.expression, '(', ')')
6
- wrap(node.children[0].loc.expression, '[', ']')
7
- super
8
- end
9
- end