parser 2.6.5.0 → 2.7.2.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 (102) hide show
  1. checksums.yaml +4 -4
  2. data/lib/parser.rb +4 -1
  3. data/lib/parser/all.rb +1 -0
  4. data/lib/parser/ast/processor.rb +21 -0
  5. data/lib/parser/base.rb +25 -5
  6. data/lib/parser/builders/default.rb +394 -24
  7. data/lib/parser/context.rb +5 -0
  8. data/lib/parser/current.rb +16 -7
  9. data/lib/parser/current_arg_stack.rb +43 -0
  10. data/lib/parser/diagnostic.rb +1 -1
  11. data/lib/parser/diagnostic/engine.rb +1 -2
  12. data/lib/parser/lexer.rb +23770 -0
  13. data/lib/parser/lexer/dedenter.rb +52 -49
  14. data/lib/parser/macruby.rb +6149 -0
  15. data/lib/parser/{lexer/max_numparam_stack.rb → max_numparam_stack.rb} +10 -4
  16. data/lib/parser/messages.rb +52 -29
  17. data/lib/parser/meta.rb +10 -5
  18. data/lib/parser/ruby18.rb +5663 -0
  19. data/lib/parser/ruby19.rb +6092 -0
  20. data/lib/parser/ruby20.rb +6527 -0
  21. data/lib/parser/ruby21.rb +6578 -0
  22. data/lib/parser/ruby22.rb +6613 -0
  23. data/lib/parser/ruby23.rb +6624 -0
  24. data/lib/parser/ruby24.rb +6694 -0
  25. data/lib/parser/ruby25.rb +6662 -0
  26. data/lib/parser/ruby26.rb +6676 -0
  27. data/lib/parser/ruby27.rb +7803 -0
  28. data/lib/parser/ruby28.rb +8047 -0
  29. data/lib/parser/ruby30.rb +8052 -0
  30. data/lib/parser/rubymotion.rb +6086 -0
  31. data/lib/parser/runner.rb +26 -2
  32. data/lib/parser/runner/ruby_rewrite.rb +2 -2
  33. data/lib/parser/source/buffer.rb +3 -1
  34. data/lib/parser/source/comment.rb +1 -1
  35. data/lib/parser/source/comment/associator.rb +14 -4
  36. data/lib/parser/source/map/method_definition.rb +25 -0
  37. data/lib/parser/source/range.rb +19 -3
  38. data/lib/parser/source/tree_rewriter.rb +115 -12
  39. data/lib/parser/source/tree_rewriter/action.rb +137 -28
  40. data/lib/parser/static_environment.rb +10 -0
  41. data/lib/parser/tree_rewriter.rb +1 -2
  42. data/lib/parser/variables_stack.rb +32 -0
  43. data/lib/parser/version.rb +1 -1
  44. data/parser.gemspec +10 -18
  45. metadata +22 -99
  46. data/.gitignore +0 -33
  47. data/.travis.yml +0 -45
  48. data/.yardopts +0 -21
  49. data/CHANGELOG.md +0 -997
  50. data/CONTRIBUTING.md +0 -17
  51. data/Gemfile +0 -10
  52. data/LICENSE.txt +0 -25
  53. data/README.md +0 -301
  54. data/Rakefile +0 -166
  55. data/ci/run_rubocop_specs +0 -14
  56. data/doc/AST_FORMAT.md +0 -1816
  57. data/doc/CUSTOMIZATION.md +0 -37
  58. data/doc/INTERNALS.md +0 -21
  59. data/doc/css/.gitkeep +0 -0
  60. data/doc/css/common.css +0 -68
  61. data/lib/parser/lexer.rl +0 -2533
  62. data/lib/parser/macruby.y +0 -2198
  63. data/lib/parser/ruby18.y +0 -1934
  64. data/lib/parser/ruby19.y +0 -2175
  65. data/lib/parser/ruby20.y +0 -2353
  66. data/lib/parser/ruby21.y +0 -2357
  67. data/lib/parser/ruby22.y +0 -2364
  68. data/lib/parser/ruby23.y +0 -2370
  69. data/lib/parser/ruby24.y +0 -2408
  70. data/lib/parser/ruby25.y +0 -2405
  71. data/lib/parser/ruby26.y +0 -2413
  72. data/lib/parser/ruby27.y +0 -2470
  73. data/lib/parser/rubymotion.y +0 -2182
  74. data/test/bug_163/fixtures/input.rb +0 -5
  75. data/test/bug_163/fixtures/output.rb +0 -5
  76. data/test/bug_163/rewriter.rb +0 -20
  77. data/test/helper.rb +0 -59
  78. data/test/parse_helper.rb +0 -316
  79. data/test/racc_coverage_helper.rb +0 -133
  80. data/test/test_base.rb +0 -31
  81. data/test/test_current.rb +0 -29
  82. data/test/test_diagnostic.rb +0 -96
  83. data/test/test_diagnostic_engine.rb +0 -62
  84. data/test/test_encoding.rb +0 -99
  85. data/test/test_lexer.rb +0 -3667
  86. data/test/test_lexer_stack_state.rb +0 -78
  87. data/test/test_parse_helper.rb +0 -80
  88. data/test/test_parser.rb +0 -7644
  89. data/test/test_runner_parse.rb +0 -35
  90. data/test/test_runner_rewrite.rb +0 -47
  91. data/test/test_source_buffer.rb +0 -162
  92. data/test/test_source_comment.rb +0 -36
  93. data/test/test_source_comment_associator.rb +0 -367
  94. data/test/test_source_map.rb +0 -15
  95. data/test/test_source_range.rb +0 -172
  96. data/test/test_source_rewriter.rb +0 -541
  97. data/test/test_source_rewriter_action.rb +0 -46
  98. data/test/test_source_tree_rewriter.rb +0 -173
  99. data/test/test_static_environment.rb +0 -45
  100. data/test/using_tree_rewriter/fixtures/input.rb +0 -3
  101. data/test/using_tree_rewriter/fixtures/output.rb +0 -3
  102. 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
- @buf.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,173 +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
- @buf.source = 'puts(:hello, :world)'
9
-
10
- @hello = range(5, 6)
11
- @comma_space = range(11,2)
12
- @world = range(13,6)
13
- end
14
-
15
- def range(from, len)
16
- Parser::Source::Range.new(@buf, from, from + len)
17
- end
18
-
19
- # Returns either:
20
- # - String (Normal operation)
21
- # - [diagnostic, ...] (Diagnostics)
22
- # - Parser::ClobberingError
23
- #
24
- def apply(actions, **policy)
25
- diagnostics = []
26
- diags = -> { diagnostics.flatten.map(&:strip).join("\n") }
27
- rewriter = Parser::Source::TreeRewriter.new(@buf, **policy)
28
- rewriter.diagnostics.consumer = -> diag { diagnostics << diag.render }
29
- actions.each do |action, range, *args|
30
- rewriter.public_send(action, range, *args)
31
- end
32
- if diagnostics.empty?
33
- rewriter.process
34
- else
35
- diags.call
36
- end
37
- rescue ::Parser::ClobberingError => e
38
- [::Parser::ClobberingError, diags.call]
39
- end
40
-
41
- # Expects ordered actions to be grouped together
42
- def check_actions(expected, grouped_actions, **policy)
43
- grouped_actions.permutation do |sequence|
44
- # [action, [action, action]] => [action, action, action]
45
- # except we can't use flatten because "action" are arrays themselves
46
- actions = sequence.flat_map { |group| group.first.is_a?(Array) ? group : [group] }
47
- assert_equal(expected, apply(actions, **policy))
48
- end
49
- end
50
-
51
- def assert_actions_result(expected, *actions, **rest)
52
- if expected == :raise
53
- diagnostic = rest.values.first
54
- check_actions([::Parser::ClobberingError, diagnostic], actions)
55
- elsif rest.empty?
56
- check_actions(expected, actions)
57
- else
58
- policy, diagnostic = rest.first
59
- check_actions(expected, actions, policy => :accept)
60
- check_actions(diagnostic, actions, policy => :warn)
61
- diagnostic.gsub!(/warning: /, 'error: ')
62
- check_actions([::Parser::ClobberingError, diagnostic], actions, policy => :raise)
63
- end
64
- end
65
-
66
- ### Simple cases
67
-
68
- def test_remove
69
- assert_actions_result 'puts(, :world)', [:remove, @hello]
70
- end
71
-
72
- def test_insert_before
73
- assert_actions_result 'puts(:hello, 42, :world)', [:insert_before, @world, '42, ']
74
- end
75
-
76
- def test_insert_after
77
- assert_actions_result 'puts(:hello, 42, :world)', [:insert_after, @hello, ', 42']
78
- end
79
-
80
- def test_wrap
81
- assert_actions_result 'puts([:hello], :world)', [:wrap, @hello, '[', ']']
82
- end
83
-
84
- def test_replace
85
- assert_actions_result 'puts(:hi, :world)', [:replace, @hello, ':hi']
86
- end
87
-
88
- #
89
- # All other cases, as per doc
90
- #
91
-
92
- def test_crossing_non_deletions
93
- check = [
94
- [:wrap, '(', ')'],
95
- [:remove],
96
- [:replace, 'xx'],
97
- ]
98
- check.combination(2) do |(action, *args), (action_b, *args_b)|
99
- next if action == :remove && action_b == :remove
100
- assert_actions_result :raise,
101
- [[action, @hello.join(@comma_space), *args],
102
- [action_b, @world.join(@comma_space), *args_b]],
103
- diagnostic: <<-DIAGNOSTIC.chomp
104
- (rewriter):1:12: error: the rewriting action on:
105
- (rewriter):1: puts(:hello, :world)
106
- (rewriter):1: ^~~~~~~~
107
- (rewriter):1:6: error: is crossing that on:
108
- (rewriter):1: puts(:hello, :world)
109
- (rewriter):1: ^~~~~~~~
110
- DIAGNOSTIC
111
- end
112
- end
113
-
114
-
115
- def test_crossing_deletions
116
- assert_actions_result 'puts()',
117
- [[:remove, @hello.join(@comma_space)],
118
- [:remove, @world.join(@comma_space)]],
119
- crossing_deletions: <<-DIAGNOSTIC.chomp
120
- (rewriter):1:12: warning: the deletion of:
121
- (rewriter):1: puts(:hello, :world)
122
- (rewriter):1: ^~~~~~~~
123
- (rewriter):1:6: warning: is crossing:
124
- (rewriter):1: puts(:hello, :world)
125
- (rewriter):1: ^~~~~~~~
126
- DIAGNOSTIC
127
- end
128
-
129
- def test_multiple_actions
130
- assert_actions_result 'puts({:hello => [:everybody]})',
131
- [:replace, @comma_space, ' => '],
132
- [:wrap, @hello.join(@world), '{', '}'],
133
- [:replace, @world, ':everybody'],
134
- [:wrap, @world, '[', ']']
135
- end
136
-
137
- def test_wraps_same_range
138
- assert_actions_result 'puts([(:hello)], :world)',
139
- [[:wrap, @hello, '(', ')'],
140
- [:wrap, @hello, '[', ']']]
141
- end
142
-
143
- def test_replace_same_range
144
- assert_actions_result 'puts(:hey, :world)',
145
- [[:replace, @hello, ':hi'],
146
- [:replace, @hello, ':hey']],
147
- different_replacements: <<-DIAGNOSTIC.chomp
148
- (rewriter):1:6: warning: different replacements: :hey vs :hi
149
- (rewriter):1: puts(:hello, :world)
150
- (rewriter):1: ^~~~~~
151
- DIAGNOSTIC
152
- end
153
-
154
- def test_swallowed_insertions
155
- assert_actions_result 'puts(:hi)',
156
- [[:wrap, @hello.adjust(begin_pos: 1), '__', '__'],
157
- [:replace, @world.adjust(end_pos: -2), 'xx'],
158
- [:replace, @hello.join(@world), ':hi']],
159
- swallowed_insertions: <<-DIAGNOSTIC.chomp
160
- (rewriter):1:6: warning: this replacement:
161
- (rewriter):1: puts(:hello, :world)
162
- (rewriter):1: ^~~~~~~~~~~~~~
163
- (rewriter):1:7: warning: swallows some inner rewriting actions:
164
- (rewriter):1: puts(:hello, :world)
165
- (rewriter):1: ^~~~~ ~~~~
166
- DIAGNOSTIC
167
- end
168
-
169
- def test_out_of_range_ranges
170
- rewriter = Parser::Source::TreeRewriter.new(@buf)
171
- assert_raises(IndexError) { rewriter.insert_before(range(0, 100), 'hola') }
172
- end
173
- 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