parser 2.2.2.6 → 2.2.3.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.
@@ -82,6 +82,16 @@ module Parser
82
82
  @parser_class = Parser::Ruby22
83
83
  end
84
84
 
85
+ opts.on '--mac', 'Parse as MacRuby 0.12 would' do
86
+ require 'parser/macruby'
87
+ @parser_class = Parser::MacRuby
88
+ end
89
+
90
+ opts.on '--ios', 'Parse as mid-2015 RubyMotion would' do
91
+ require 'parser/rubymotion'
92
+ @parser_class = Parser::RubyMotion
93
+ end
94
+
85
95
  opts.on '-w', '--warnings', 'Enable warnings' do |w|
86
96
  @warnings = w
87
97
  end
@@ -40,6 +40,8 @@ module Parser
40
40
  )
41
41
  /x
42
42
 
43
+ NEW_LINE = "\n".freeze
44
+
43
45
  ##
44
46
  # Try to recognize encoding of `string` as Ruby would, i.e. by looking for
45
47
  # magic encoding comment or UTF-8 BOM. `string` can be in any encoding.
@@ -173,7 +175,7 @@ module Parser
173
175
  raise ArgumentError, 'Source::Buffer is immutable'
174
176
  end
175
177
 
176
- @source = input.gsub("\r\n", "\n").freeze
178
+ @source = input.gsub("\r\n", NEW_LINE).freeze
177
179
  end
178
180
 
179
181
  ##
@@ -198,7 +200,7 @@ module Parser
198
200
  def source_line(lineno)
199
201
  unless @lines
200
202
  @lines = @source.lines.to_a
201
- @lines.each { |line| line.chomp!("\n") }
203
+ @lines.each { |line| line.chomp!(NEW_LINE) }
202
204
 
203
205
  # If a file ends with a newline, the EOF token will appear
204
206
  # to be one line further than the end of file.
@@ -215,7 +217,7 @@ module Parser
215
217
  @line_begins, index = [ [ 0, 0 ] ], 1
216
218
 
217
219
  @source.each_char do |char|
218
- if char == "\n"
220
+ if char == NEW_LINE
219
221
  @line_begins.unshift [ @line_begins.length, index ]
220
222
  end
221
223
 
@@ -0,0 +1,17 @@
1
+ module Parser
2
+ module Source
3
+
4
+ class Map::ObjcKwarg < Map
5
+ attr_reader :keyword
6
+ attr_reader :operator
7
+ attr_reader :argument
8
+
9
+ def initialize(keyword_l, operator_l, argument_l, expression_l)
10
+ @keyword, @operator, @argument = keyword_l, operator_l, argument_l
11
+
12
+ super(expression_l)
13
+ end
14
+ end
15
+
16
+ end
17
+ end
@@ -1,3 +1,3 @@
1
1
  module Parser
2
- VERSION = '2.2.2.6'
2
+ VERSION = '2.2.3.0'
3
3
  end
@@ -5,7 +5,7 @@ require File.expand_path('../lib/parser/version', __FILE__)
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'parser'
7
7
  spec.version = Parser::VERSION
8
- spec.authors = ['Peter Zotov']
8
+ spec.authors = ['whitequark']
9
9
  spec.email = ['whitequark@whitequark.org']
10
10
  spec.description = 'A Ruby parser written in pure Ruby.'
11
11
  spec.summary = spec.description
@@ -20,6 +20,8 @@ Gem::Specification.new do |spec|
20
20
  lib/parser/ruby20.rb
21
21
  lib/parser/ruby21.rb
22
22
  lib/parser/ruby22.rb
23
+ lib/parser/macruby.rb
24
+ lib/parser/rubymotion.rb
23
25
  )
24
26
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
25
27
  spec.test_files = spec.files.grep(%r{^test/})
@@ -8,8 +8,10 @@ module ParseHelper
8
8
  else
9
9
  require 'parser/all'
10
10
  require 'parser/ruby22'
11
+ require 'parser/macruby'
12
+ require 'parser/rubymotion'
11
13
 
12
- ALL_VERSIONS = %w(1.8 1.9 2.0 2.1 2.2)
14
+ ALL_VERSIONS = %w(1.8 1.9 2.0 2.1 2.2 mac ios)
13
15
  end
14
16
 
15
17
  def setup
@@ -25,6 +27,8 @@ module ParseHelper
25
27
  when '2.0' then parser = Parser::Ruby20.new
26
28
  when '2.1' then parser = Parser::Ruby21.new
27
29
  when '2.2' then parser = Parser::Ruby22.new
30
+ when 'mac' then parser = Parser::MacRuby.new
31
+ when 'ios' then parser = Parser::RubyMotion.new
28
32
  else raise "Unrecognized Ruby version #{version}"
29
33
  end
30
34
 
@@ -121,13 +121,13 @@ class TestParser < Minitest::Test
121
121
  s(:rational, Rational(42)),
122
122
  %q{42r},
123
123
  %q{~~~ expression},
124
- ALL_VERSIONS - %w(1.8 1.9 2.0))
124
+ ALL_VERSIONS - %w(1.8 1.9 mac ios 2.0))
125
125
 
126
126
  assert_parses(
127
127
  s(:rational, Rational(421, 10)),
128
128
  %q{42.1r},
129
129
  %q{~~~~~ expression},
130
- ALL_VERSIONS - %w(1.8 1.9 2.0))
130
+ ALL_VERSIONS - %w(1.8 1.9 mac ios 2.0))
131
131
  end
132
132
 
133
133
  def test_complex
@@ -135,25 +135,25 @@ class TestParser < Minitest::Test
135
135
  s(:complex, Complex(0, 42)),
136
136
  %q{42i},
137
137
  %q{~~~ expression},
138
- ALL_VERSIONS - %w(1.8 1.9 2.0))
138
+ ALL_VERSIONS - %w(1.8 1.9 mac ios 2.0))
139
139
 
140
140
  assert_parses(
141
141
  s(:complex, Complex(0, Rational(42))),
142
142
  %q{42ri},
143
143
  %q{~~~~ expression},
144
- ALL_VERSIONS - %w(1.8 1.9 2.0))
144
+ ALL_VERSIONS - %w(1.8 1.9 mac ios 2.0))
145
145
 
146
146
  assert_parses(
147
147
  s(:complex, Complex(0, 42.1)),
148
148
  %q{42.1i},
149
149
  %q{~~~~~ expression},
150
- ALL_VERSIONS - %w(1.8 1.9 2.0))
150
+ ALL_VERSIONS - %w(1.8 1.9 mac ios 2.0))
151
151
 
152
152
  assert_parses(
153
153
  s(:complex, Complex(0, Rational(421, 10))),
154
154
  %q{42.1ri},
155
155
  %q{~~~~~~ expression},
156
- ALL_VERSIONS - %w(1.8 1.9 2.0))
156
+ ALL_VERSIONS - %w(1.8 1.9 mac ios 2.0))
157
157
  end
158
158
 
159
159
  # Strings
@@ -491,7 +491,7 @@ class TestParser < Minitest::Test
491
491
  | ^ end
492
492
  | ~~~ expression (sym)
493
493
  |~~~~~~~~~~~ expression},
494
- ALL_VERSIONS - %w(1.8 1.9))
494
+ ALL_VERSIONS - %w(1.8 1.9 mac ios))
495
495
  end
496
496
 
497
497
  def test_array_symbols_interp
@@ -508,7 +508,7 @@ class TestParser < Minitest::Test
508
508
  | ~~~~~~ expression (dsym.begin)
509
509
  | ~~~ expression (dsym.begin.lvar)
510
510
  |~~~~~~~~~~~~~~ expression},
511
- ALL_VERSIONS - %w(1.8 1.9))
511
+ ALL_VERSIONS - %w(1.8 1.9 mac ios))
512
512
 
513
513
  assert_parses(
514
514
  s(:array,
@@ -517,7 +517,7 @@ class TestParser < Minitest::Test
517
517
  s(:begin, s(:lvar, :bar)))),
518
518
  %q{%I[foo#{bar}]},
519
519
  %q{},
520
- ALL_VERSIONS - %w(1.8 1.9))
520
+ ALL_VERSIONS - %w(1.8 1.9 mac ios))
521
521
  end
522
522
 
523
523
  def test_array_symbols_empty
@@ -527,13 +527,13 @@ class TestParser < Minitest::Test
527
527
  %q{^^^ begin
528
528
  | ^ end
529
529
  |~~~~ expression},
530
- ALL_VERSIONS - %w(1.8 1.9))
530
+ ALL_VERSIONS - %w(1.8 1.9 mac ios))
531
531
 
532
532
  assert_parses(
533
533
  s(:array),
534
534
  %q{%I()},
535
535
  %q{},
536
- ALL_VERSIONS - %w(1.8 1.9))
536
+ ALL_VERSIONS - %w(1.8 1.9 mac ios))
537
537
  end
538
538
 
539
539
  # Hashes
@@ -589,7 +589,7 @@ class TestParser < Minitest::Test
589
589
  | ~~~~~ expression (pair.sym)
590
590
  | ~~~~~~~~ expression (pair)
591
591
  |~~~~~~~~~~~~ expression},
592
- ALL_VERSIONS - %w(1.8 1.9 2.0 2.1))
592
+ ALL_VERSIONS - %w(1.8 1.9 mac ios 2.0 2.1))
593
593
 
594
594
  assert_parses(
595
595
  s(:hash,
@@ -597,7 +597,7 @@ class TestParser < Minitest::Test
597
597
  s(:pair, s(:sym, :bar), s(:hash))),
598
598
  %q[{ 'foo': 2, 'bar': {}}],
599
599
  %q{},
600
- ALL_VERSIONS - %w(1.8 1.9 2.0 2.1))
600
+ ALL_VERSIONS - %w(1.8 1.9 mac ios 2.0 2.1))
601
601
 
602
602
  assert_parses(
603
603
  s(:send, nil, :f,
@@ -606,7 +606,7 @@ class TestParser < Minitest::Test
606
606
  s(:int, 1))),
607
607
  %q{f(a ? "a":1)},
608
608
  %q{},
609
- ALL_VERSIONS - %w(1.8 1.9 2.0 2.1))
609
+ ALL_VERSIONS - %w(1.8 1.9 mac ios 2.0 2.1))
610
610
  end
611
611
 
612
612
  def test_hash_kwsplat
@@ -617,7 +617,7 @@ class TestParser < Minitest::Test
617
617
  %q[{ foo: 2, **bar }],
618
618
  %q{ ^^ operator (kwsplat)
619
619
  | ~~~~~ expression (kwsplat)},
620
- ALL_VERSIONS - %w(1.8 1.9))
620
+ ALL_VERSIONS - %w(1.8 1.9 mac ios))
621
621
  end
622
622
 
623
623
  def test_hash_no_hashrocket
@@ -837,7 +837,7 @@ class TestParser < Minitest::Test
837
837
  s(:send, nil, :m, s(:lvar, :foo)))),
838
838
  %q{foo = bar = m foo},
839
839
  %q{},
840
- ALL_VERSIONS - %w(1.8))
840
+ ALL_VERSIONS - %w(1.8 mac ios))
841
841
  end
842
842
 
843
843
  def test_asgn_keyword_invalid
@@ -1233,7 +1233,7 @@ class TestParser < Minitest::Test
1233
1233
  s(:int, 1)),
1234
1234
  %q{::A += 1},
1235
1235
  %q{},
1236
- ALL_VERSIONS - %w(1.8 1.9))
1236
+ ALL_VERSIONS - %w(1.8 1.9 mac ios))
1237
1237
 
1238
1238
  assert_parses(
1239
1239
  s(:op_asgn,
@@ -1241,7 +1241,7 @@ class TestParser < Minitest::Test
1241
1241
  s(:int, 1)),
1242
1242
  %q{B::A += 1},
1243
1243
  %q{},
1244
- ALL_VERSIONS - %w(1.8 1.9))
1244
+ ALL_VERSIONS - %w(1.8 1.9 mac ios))
1245
1245
 
1246
1246
  assert_parses(
1247
1247
  s(:def, :x, s(:args),
@@ -1250,7 +1250,7 @@ class TestParser < Minitest::Test
1250
1250
  s(:int, 1))),
1251
1251
  %q{def x; self::A ||= 1; end},
1252
1252
  %q{},
1253
- ALL_VERSIONS - %w(1.8 1.9))
1253
+ ALL_VERSIONS - %w(1.8 1.9 mac ios))
1254
1254
 
1255
1255
  assert_parses(
1256
1256
  s(:def, :x, s(:args),
@@ -1259,7 +1259,7 @@ class TestParser < Minitest::Test
1259
1259
  s(:int, 1))),
1260
1260
  %q{def x; ::A ||= 1; end},
1261
1261
  %q{},
1262
- ALL_VERSIONS - %w(1.8 1.9))
1262
+ ALL_VERSIONS - %w(1.8 1.9 mac ios))
1263
1263
  end
1264
1264
 
1265
1265
  def test_const_op_asgn_invalid
@@ -1267,25 +1267,25 @@ class TestParser < Minitest::Test
1267
1267
  [:error, :dynamic_const],
1268
1268
  %q{Foo::Bar += 1},
1269
1269
  %q{ ~~~ location},
1270
- %w(1.8 1.9))
1270
+ %w(1.8 1.9 mac ios))
1271
1271
 
1272
1272
  assert_diagnoses(
1273
1273
  [:error, :dynamic_const],
1274
1274
  %q{::Bar += 1},
1275
1275
  %q{ ~~~ location},
1276
- %w(1.8 1.9))
1276
+ %w(1.8 1.9 mac ios))
1277
1277
 
1278
1278
  assert_diagnoses(
1279
1279
  [:error, :dynamic_const],
1280
1280
  %q{def foo; Foo::Bar += 1; end},
1281
1281
  %q{ ~~~ location},
1282
- %w(1.8 1.9))
1282
+ %w(1.8 1.9 mac ios))
1283
1283
 
1284
1284
  assert_diagnoses(
1285
1285
  [:error, :dynamic_const],
1286
1286
  %q{def foo; ::Bar += 1; end},
1287
1287
  %q{ ~~~ location},
1288
- %w(1.8 1.9))
1288
+ %w(1.8 1.9 mac ios))
1289
1289
  end
1290
1290
 
1291
1291
  # Method binary operator-assignment
@@ -1339,7 +1339,7 @@ class TestParser < Minitest::Test
1339
1339
  s(:send, nil, :m, s(:lvar, :foo))),
1340
1340
  %q{foo::A += m foo},
1341
1341
  %q{},
1342
- ALL_VERSIONS - %w(1.8))
1342
+ ALL_VERSIONS - %w(1.8 ios))
1343
1343
  end
1344
1344
 
1345
1345
  def test_op_asgn_index
@@ -1535,7 +1535,7 @@ class TestParser < Minitest::Test
1535
1535
  nil),
1536
1536
  %q{class Foo < a:b; end},
1537
1537
  %q{},
1538
- ALL_VERSIONS - %w(1.8 1.9))
1538
+ ALL_VERSIONS - %w(1.8 1.9 mac ios))
1539
1539
  end
1540
1540
 
1541
1541
  def test_class_invalid
@@ -1771,7 +1771,7 @@ class TestParser < Minitest::Test
1771
1771
  %q{def f(foo:); end},
1772
1772
  %q{ ~~~ name (args.kwarg)
1773
1773
  | ~~~~ expression (args.kwarg)},
1774
- ALL_VERSIONS - %w(1.8 1.9 2.0))
1774
+ ALL_VERSIONS - %w(1.8 1.9 mac ios 2.0))
1775
1775
  end
1776
1776
 
1777
1777
  def test_kwoptarg
@@ -1782,7 +1782,7 @@ class TestParser < Minitest::Test
1782
1782
  %q{def f(foo: 1); end},
1783
1783
  %q{ ~~~ name (args.kwoptarg)
1784
1784
  | ~~~~~~ expression (args.kwoptarg)},
1785
- ALL_VERSIONS - %w(1.8 1.9))
1785
+ ALL_VERSIONS - %w(1.8 1.9 mac ios))
1786
1786
  end
1787
1787
 
1788
1788
  def test_kwrestarg_named
@@ -1793,7 +1793,7 @@ class TestParser < Minitest::Test
1793
1793
  %q{def f(**foo); end},
1794
1794
  %q{ ~~~ name (args.kwrestarg)
1795
1795
  | ~~~~~ expression (args.kwrestarg)},
1796
- ALL_VERSIONS - %w(1.8 1.9))
1796
+ ALL_VERSIONS - %w(1.8 1.9 mac ios))
1797
1797
  end
1798
1798
 
1799
1799
  def test_kwrestarg_unnamed
@@ -1803,7 +1803,7 @@ class TestParser < Minitest::Test
1803
1803
  nil),
1804
1804
  %q{def f(**); end},
1805
1805
  %q{ ~~ expression (args.kwrestarg)},
1806
- ALL_VERSIONS - %w(1.8 1.9))
1806
+ ALL_VERSIONS - %w(1.8 1.9 mac ios))
1807
1807
  end
1808
1808
 
1809
1809
  def test_blockarg
@@ -1816,6 +1816,30 @@ class TestParser < Minitest::Test
1816
1816
  | ~~~~~~ expression (args.blockarg)})
1817
1817
  end
1818
1818
 
1819
+ def test_objc_arg
1820
+ assert_parses(
1821
+ s(:def, :f,
1822
+ s(:args, s(:arg, :a), s(:objc_kwarg, :b, :c)),
1823
+ nil),
1824
+ %q{def f(a, b: c); end},
1825
+ %q{ ~ keyword (args.objc_kwarg)
1826
+ | ~ operator (args.objc_kwarg)
1827
+ | ~ argument (args.objc_kwarg)
1828
+ | ~~~~ expression (args.objc_kwarg)},
1829
+ %w(mac))
1830
+
1831
+ assert_parses(
1832
+ s(:def, :f,
1833
+ s(:args, s(:arg, :a), s(:objc_kwarg, :b, :c)),
1834
+ nil),
1835
+ %q{def f(a, b => c); end},
1836
+ %q{ ~ keyword (args.objc_kwarg)
1837
+ | ~~ operator (args.objc_kwarg)
1838
+ | ~ argument (args.objc_kwarg)
1839
+ | ~~~~~~ expression (args.objc_kwarg)},
1840
+ %w(mac))
1841
+ end
1842
+
1819
1843
  def test_arg_scope
1820
1844
  # [ruby-core:61299] [Bug #9593]
1821
1845
  assert_parses(
@@ -1824,7 +1848,7 @@ class TestParser < Minitest::Test
1824
1848
  s(:lvar, :var)),
1825
1849
  %q{def f(var = defined?(var)) var end},
1826
1850
  %q{},
1827
- ALL_VERSIONS - %w(1.8 1.9 2.0))
1851
+ ALL_VERSIONS - %w(1.8 1.9 mac ios 2.0))
1828
1852
 
1829
1853
  assert_parses(
1830
1854
  s(:def, :f,
@@ -1832,7 +1856,7 @@ class TestParser < Minitest::Test
1832
1856
  s(:lvar, :var)),
1833
1857
  %q{def f(var: defined?(var)) var end},
1834
1858
  %q{},
1835
- ALL_VERSIONS - %w(1.8 1.9 2.0))
1859
+ ALL_VERSIONS - %w(1.8 1.9 mac ios 2.0))
1836
1860
  end
1837
1861
 
1838
1862
  def assert_parses_args(ast, code, versions=ALL_VERSIONS)
@@ -1978,7 +2002,7 @@ class TestParser < Minitest::Test
1978
2002
  s(:kwrestarg, :baz),
1979
2003
  s(:blockarg, :b)),
1980
2004
  %q{(foo: 1, bar: 2, **baz, &b)},
1981
- ALL_VERSIONS - %w(1.8 1.9))
2005
+ ALL_VERSIONS - %w(1.8 1.9 mac ios))
1982
2006
 
1983
2007
  # f_kwarg opt_f_block_arg
1984
2008
  assert_parses_args(
@@ -1986,7 +2010,7 @@ class TestParser < Minitest::Test
1986
2010
  s(:kwoptarg, :foo, s(:int, 1)),
1987
2011
  s(:blockarg, :b)),
1988
2012
  %q{(foo: 1, &b)},
1989
- ALL_VERSIONS - %w(1.8 1.9))
2013
+ ALL_VERSIONS - %w(1.8 1.9 mac ios))
1990
2014
 
1991
2015
  # f_kwrest opt_f_block_arg
1992
2016
  assert_parses_args(
@@ -1994,14 +2018,14 @@ class TestParser < Minitest::Test
1994
2018
  s(:kwrestarg, :baz),
1995
2019
  s(:blockarg, :b)),
1996
2020
  %q{**baz, &b},
1997
- ALL_VERSIONS - %w(1.8 1.9))
2021
+ ALL_VERSIONS - %w(1.8 1.9 mac ios))
1998
2022
 
1999
2023
  assert_parses_args(
2000
2024
  s(:args,
2001
2025
  s(:restarg),
2002
2026
  s(:kwrestarg)),
2003
2027
  %q{*, **},
2004
- ALL_VERSIONS - %w(1.8 1.9))
2028
+ ALL_VERSIONS - %w(1.8 1.9 mac ios))
2005
2029
  end
2006
2030
 
2007
2031
  def test_kwarg_no_paren
@@ -2009,13 +2033,13 @@ class TestParser < Minitest::Test
2009
2033
  s(:args,
2010
2034
  s(:kwarg, :foo)),
2011
2035
  %Q{foo:\n},
2012
- ALL_VERSIONS - %w(1.8 1.9 2.0))
2036
+ ALL_VERSIONS - %w(1.8 1.9 mac ios 2.0))
2013
2037
 
2014
2038
  assert_parses_args(
2015
2039
  s(:args,
2016
2040
  s(:kwoptarg, :foo, s(:int, -1))),
2017
2041
  %Q{foo: -1\n},
2018
- ALL_VERSIONS - %w(1.8 1.9 2.0))
2042
+ ALL_VERSIONS - %w(1.8 1.9 mac ios 2.0))
2019
2043
  end
2020
2044
 
2021
2045
  def assert_parses_margs(ast, code, versions=ALL_VERSIONS - %w(1.8))
@@ -2078,6 +2102,20 @@ class TestParser < Minitest::Test
2078
2102
  %q{(*, p)})
2079
2103
  end
2080
2104
 
2105
+ def test_marg_objc_restarg
2106
+ assert_parses(
2107
+ s(:def, :f,
2108
+ s(:args,
2109
+ s(:arg, :a),
2110
+ s(:mlhs,
2111
+ s(:objc_restarg, s(:objc_kwarg, :b, :c)))),
2112
+ nil),
2113
+ %Q{def f(a, (*b: c)); end},
2114
+ %q{ ~ operator (args.mlhs.objc_restarg)
2115
+ | ~~~~~ expression (args.mlhs.objc_restarg)},
2116
+ %w(mac))
2117
+ end
2118
+
2081
2119
  def assert_parses_blockargs(ast, code, versions=ALL_VERSIONS)
2082
2120
  assert_parses(
2083
2121
  s(:block,
@@ -2108,7 +2146,7 @@ class TestParser < Minitest::Test
2108
2146
  assert_parses_blockargs(
2109
2147
  s(:args, s(:shadowarg, :a)),
2110
2148
  %Q{|;\na\n|},
2111
- ALL_VERSIONS - %w(1.8 1.9))
2149
+ ALL_VERSIONS - %w(1.8 1.9 mac ios))
2112
2150
 
2113
2151
  # tOROP
2114
2152
  assert_parses_blockargs(
@@ -2346,7 +2384,7 @@ class TestParser < Minitest::Test
2346
2384
  s(:kwrestarg, :baz),
2347
2385
  s(:blockarg, :b)),
2348
2386
  %q{|foo: 1, bar: 2, **baz, &b|},
2349
- ALL_VERSIONS - %w(1.8 1.9))
2387
+ ALL_VERSIONS - %w(1.8 1.9 mac ios))
2350
2388
 
2351
2389
  # f_block_kwarg opt_f_block_arg
2352
2390
  assert_parses_blockargs(
@@ -2354,7 +2392,7 @@ class TestParser < Minitest::Test
2354
2392
  s(:kwoptarg, :foo, s(:int, 1)),
2355
2393
  s(:blockarg, :b)),
2356
2394
  %q{|foo: 1, &b|},
2357
- ALL_VERSIONS - %w(1.8 1.9))
2395
+ ALL_VERSIONS - %w(1.8 1.9 mac ios))
2358
2396
 
2359
2397
  # f_kwrest opt_f_block_arg
2360
2398
  assert_parses_blockargs(
@@ -2362,7 +2400,7 @@ class TestParser < Minitest::Test
2362
2400
  s(:kwrestarg, :baz),
2363
2401
  s(:blockarg, :b)),
2364
2402
  %q{|**baz, &b|},
2365
- ALL_VERSIONS - %w(1.8 1.9))
2403
+ ALL_VERSIONS - %w(1.8 1.9 mac ios))
2366
2404
  end
2367
2405
 
2368
2406
  def test_block_kwarg
@@ -2370,7 +2408,7 @@ class TestParser < Minitest::Test
2370
2408
  s(:args,
2371
2409
  s(:kwarg, :foo)),
2372
2410
  %q{|foo:|},
2373
- ALL_VERSIONS - %w(1.8 1.9 2.0))
2411
+ ALL_VERSIONS - %w(1.8 1.9 mac ios 2.0))
2374
2412
  end
2375
2413
 
2376
2414
  def test_arg_invalid
@@ -2447,21 +2485,21 @@ class TestParser < Minitest::Test
2447
2485
  %q{def foo(aa, aa: 1); end},
2448
2486
  %q{ ^^ location
2449
2487
  | ~~ highlights (0)},
2450
- ALL_VERSIONS - %w(1.8 1.9))
2488
+ ALL_VERSIONS - %w(1.8 1.9 mac ios))
2451
2489
 
2452
2490
  assert_diagnoses(
2453
2491
  [:error, :duplicate_argument],
2454
2492
  %q{def foo(aa, **aa); end},
2455
2493
  %q{ ^^ location
2456
2494
  | ~~ highlights (0)},
2457
- ALL_VERSIONS - %w(1.8 1.9))
2495
+ ALL_VERSIONS - %w(1.8 1.9 mac ios))
2458
2496
 
2459
2497
  assert_diagnoses(
2460
2498
  [:error, :duplicate_argument],
2461
2499
  %q{def foo(aa, aa:); end},
2462
2500
  %q{ ^^ location
2463
2501
  | ~~ highlights (0)},
2464
- ALL_VERSIONS - %w(1.8 1.9 2.0))
2502
+ ALL_VERSIONS - %w(1.8 1.9 mac ios 2.0))
2465
2503
  end
2466
2504
 
2467
2505
  def test_arg_duplicate_ignored
@@ -2483,7 +2521,7 @@ class TestParser < Minitest::Test
2483
2521
  [:error, :duplicate_argument],
2484
2522
  %q{def foo(_a, _a); end},
2485
2523
  %q{},
2486
- %w(1.8 1.9))
2524
+ %w(1.8 1.9 mac ios))
2487
2525
 
2488
2526
  assert_parses(
2489
2527
  s(:def, :foo,
@@ -2491,7 +2529,7 @@ class TestParser < Minitest::Test
2491
2529
  nil),
2492
2530
  %q{def foo(_a, _a); end},
2493
2531
  %q{},
2494
- ALL_VERSIONS - %w(1.8 1.9))
2532
+ ALL_VERSIONS - %w(1.8 1.9 mac ios))
2495
2533
  end
2496
2534
 
2497
2535
  def test_arg_duplicate_proc
@@ -2515,13 +2553,13 @@ class TestParser < Minitest::Test
2515
2553
  [:error, :argument_const],
2516
2554
  %q{def foo(Abc: 1); end},
2517
2555
  %q{ ~~~~ location},
2518
- ALL_VERSIONS - %w(1.8 1.9))
2556
+ ALL_VERSIONS - %w(1.8 1.9 mac ios))
2519
2557
 
2520
2558
  assert_diagnoses(
2521
2559
  [:error, :argument_const],
2522
2560
  %q{def foo(Abc:); end},
2523
2561
  %q{ ~~~~ location},
2524
- ALL_VERSIONS - %w(1.8 1.9 2.0))
2562
+ ALL_VERSIONS - %w(1.8 1.9 mac ios 2.0))
2525
2563
  end
2526
2564
 
2527
2565
  def test_arg_label
@@ -2604,6 +2642,17 @@ class TestParser < Minitest::Test
2604
2642
  | ~~ highlights (0)})
2605
2643
  end
2606
2644
 
2645
+ def test_send_objc_vararg
2646
+ assert_parses(
2647
+ s(:send, nil, :fun,
2648
+ s(:int, 1),
2649
+ s(:hash,
2650
+ s(:pair, s(:sym, :bar), s(:objc_varargs, s(:int, 2), s(:int, 3), s(:nil))))),
2651
+ %q{fun(1, bar: 2, 3, nil)},
2652
+ %q{ ~~~~~~~~~ expression (hash.pair.objc_varargs)},
2653
+ %w(mac))
2654
+ end
2655
+
2607
2656
  # To receiver
2608
2657
 
2609
2658
  def test_send_plain
@@ -2687,7 +2736,7 @@ class TestParser < Minitest::Test
2687
2736
  [:warning, :ambiguous_prefix, { :prefix => '**' }],
2688
2737
  %q{m **foo},
2689
2738
  %q{ ^^ location},
2690
- ALL_VERSIONS - %w(1.8 1.9))
2739
+ ALL_VERSIONS - %w(1.8 1.9 mac ios))
2691
2740
  end
2692
2741
 
2693
2742
  def test_send_block_chain_cmd
@@ -2749,7 +2798,7 @@ class TestParser < Minitest::Test
2749
2798
  s(:args), nil),
2750
2799
  %q{meth 1 do end.fun bar do end},
2751
2800
  %q{},
2752
- ALL_VERSIONS - %w(1.8 1.9))
2801
+ ALL_VERSIONS - %w(1.8 1.9 mac ios))
2753
2802
 
2754
2803
  assert_parses(
2755
2804
  s(:block,
@@ -2761,7 +2810,7 @@ class TestParser < Minitest::Test
2761
2810
  s(:args), nil),
2762
2811
  %q{meth 1 do end.fun(bar) {}},
2763
2812
  %q{},
2764
- ALL_VERSIONS - %w(1.8 1.9))
2813
+ ALL_VERSIONS - %w(1.8 1.9 mac ios))
2765
2814
 
2766
2815
  assert_parses(
2767
2816
  s(:block,
@@ -2773,7 +2822,7 @@ class TestParser < Minitest::Test
2773
2822
  s(:args), nil),
2774
2823
  %q{meth 1 do end.fun {}},
2775
2824
  %q{},
2776
- ALL_VERSIONS - %w(1.8 1.9))
2825
+ ALL_VERSIONS - %w(1.8 1.9 mac ios))
2777
2826
  end
2778
2827
 
2779
2828
  def test_send_paren_block_cmd
@@ -3110,7 +3159,7 @@ class TestParser < Minitest::Test
3110
3159
  nil),
3111
3160
  %q{-> (a) { }},
3112
3161
  %q{},
3113
- ALL_VERSIONS - %w(1.8 1.9))
3162
+ ALL_VERSIONS - %w(1.8 1.9 mac ios))
3114
3163
  end
3115
3164
 
3116
3165
  def test_send_lambda_args_shadow
@@ -3126,6 +3175,26 @@ class TestParser < Minitest::Test
3126
3175
  ALL_VERSIONS - %w(1.8))
3127
3176
  end
3128
3177
 
3178
+ def test_send_lambda_args_noparen
3179
+ assert_parses(
3180
+ s(:block, s(:send, nil, :lambda),
3181
+ s(:args,
3182
+ s(:kwoptarg, :a, s(:int, 1))),
3183
+ nil),
3184
+ %q{-> a: 1 { }},
3185
+ %q{},
3186
+ ALL_VERSIONS - %w(1.8 1.9 mac ios))
3187
+
3188
+ assert_parses(
3189
+ s(:block, s(:send, nil, :lambda),
3190
+ s(:args,
3191
+ s(:kwarg, :a)),
3192
+ nil),
3193
+ %q{-> a: { }},
3194
+ %q{},
3195
+ ALL_VERSIONS - %w(1.8 1.9 mac ios 2.0))
3196
+ end
3197
+
3129
3198
  def test_send_call
3130
3199
  assert_parses(
3131
3200
  s(:send, s(:lvar, :foo), :call,
@@ -3422,6 +3491,14 @@ class TestParser < Minitest::Test
3422
3491
  %q{fun (1)})
3423
3492
  end
3424
3493
 
3494
+ def test_space_args_arg_newline
3495
+ assert_parses(
3496
+ s(:send, nil, :fun, s(:begin, s(:int, 1))),
3497
+ %Q{fun (1\n)},
3498
+ %q{},
3499
+ ALL_VERSIONS - %w(mac))
3500
+ end
3501
+
3425
3502
  def test_space_args_arg_block
3426
3503
  assert_parses(
3427
3504
  s(:block,
@@ -3702,7 +3779,7 @@ class TestParser < Minitest::Test
3702
3779
  s(:args), nil),
3703
3780
  %q{fun () {}},
3704
3781
  %q{ ~~ expression (send.begin)},
3705
- ALL_VERSIONS - %w(1.8 1.9))
3782
+ ALL_VERSIONS - %w(1.8 1.9 mac ios))
3706
3783
  end
3707
3784
 
3708
3785
  #
@@ -4255,7 +4332,7 @@ class TestParser < Minitest::Test
4255
4332
  %q{break fun foo do end},
4256
4333
  %q{ ~~~~~~~~~~~~~~ expression (block)
4257
4334
  |~~~~~~~~~~~~~~~~~~~~ expression},
4258
- ALL_VERSIONS - %w(1.8))
4335
+ ALL_VERSIONS - %w(1.8 ios))
4259
4336
  end
4260
4337
 
4261
4338
  def test_return
@@ -4302,7 +4379,7 @@ class TestParser < Minitest::Test
4302
4379
  %q{return fun foo do end},
4303
4380
  %q{ ~~~~~~~~~~~~~~ expression (block)
4304
4381
  |~~~~~~~~~~~~~~~~~~~~~ expression},
4305
- ALL_VERSIONS - %w(1.8))
4382
+ ALL_VERSIONS - %w(1.8 ios))
4306
4383
  end
4307
4384
 
4308
4385
  def test_next
@@ -4349,7 +4426,7 @@ class TestParser < Minitest::Test
4349
4426
  %q{next fun foo do end},
4350
4427
  %q{ ~~~~~~~~~~~~~~ expression (block)
4351
4428
  |~~~~~~~~~~~~~~~~~~~ expression},
4352
- ALL_VERSIONS - %w(1.8))
4429
+ ALL_VERSIONS - %w(1.8 ios))
4353
4430
  end
4354
4431
 
4355
4432
  def test_redo
@@ -4580,7 +4657,7 @@ class TestParser < Minitest::Test
4580
4657
  %q{def f; BEGIN{}; end},
4581
4658
  %q{ ~~~~~ location},
4582
4659
  # Yes. *Exclude 1.9*. Sigh.
4583
- ALL_VERSIONS - %w(1.9))
4660
+ ALL_VERSIONS - %w(1.9 mac ios))
4584
4661
  end
4585
4662
 
4586
4663
  def test_postexe
@@ -4634,7 +4711,7 @@ class TestParser < Minitest::Test
4634
4711
  s(:int, 1)))),
4635
4712
  %q{p begin 1.times do 1 end end},
4636
4713
  %{},
4637
- ALL_VERSIONS - %w(1.8 1.9))
4714
+ ALL_VERSIONS - %w(1.8 1.9 mac ios))
4638
4715
  end
4639
4716
 
4640
4717
  def test_bug_cmdarg
@@ -4864,7 +4941,7 @@ class TestParser < Minitest::Test
4864
4941
  s(:args), nil))),
4865
4942
  %q{tap (proc do end)},
4866
4943
  %q{},
4867
- ALL_VERSIONS - %w(1.8))
4944
+ ALL_VERSIONS - %w(1.8 mac ios))
4868
4945
  end
4869
4946
 
4870
4947
  def test_bug_interp_single
@@ -4917,7 +4994,7 @@ class TestParser < Minitest::Test
4917
4994
  s(:def, :a, s(:args, s(:kwarg, :b)), s(:return)),
4918
4995
  %Q{def a b:\nreturn\nend},
4919
4996
  %q{},
4920
- ALL_VERSIONS - %w(1.8 1.9 2.0))
4997
+ ALL_VERSIONS - %w(1.8 1.9 mac ios 2.0))
4921
4998
 
4922
4999
  assert_parses(
4923
5000
  s(:lvasgn, :o,
@@ -4925,7 +5002,7 @@ class TestParser < Minitest::Test
4925
5002
  s(:pair, s(:sym, :a), s(:int, 1)))),
4926
5003
  %Q{o = {\na:\n1\n}},
4927
5004
  %q{},
4928
- ALL_VERSIONS - %w(1.8 1.9 2.0))
5005
+ ALL_VERSIONS - %w(1.8 1.9 mac ios 2.0))
4929
5006
  end
4930
5007
 
4931
5008
  def test_ruby_bug_10279
@@ -4935,7 +5012,36 @@ class TestParser < Minitest::Test
4935
5012
  s(:if, s(:true), s(:int, 42), nil))),
4936
5013
  %q{{a: if true then 42 end}},
4937
5014
  %q{},
4938
- ALL_VERSIONS - %w(1.8 1.9 2.0))
5015
+ ALL_VERSIONS - %w(1.8 1.9 mac ios 2.0))
5016
+ end
5017
+
5018
+ def test_ruby_bug_11107
5019
+ assert_parses(
5020
+ s(:send, nil, :p,
5021
+ s(:block,
5022
+ s(:send, nil, :lambda),
5023
+ s(:args),
5024
+ s(:block, s(:send, nil, :a), s(:args), nil))),
5025
+ %q{p ->() do a() do end end},
5026
+ %q{},
5027
+ ALL_VERSIONS - %w(1.8 1.9 mac ios 2.0)) # no 1.9 backport
5028
+ end
5029
+
5030
+ def test_ruby_bug_11380
5031
+ assert_parses(
5032
+ s(:block,
5033
+ s(:send, nil, :p,
5034
+ s(:block,
5035
+ s(:send, nil, :lambda),
5036
+ s(:args),
5037
+ s(:sym, :hello)),
5038
+ s(:hash,
5039
+ s(:pair, s(:sym, :a), s(:int, 1)))),
5040
+ s(:args),
5041
+ nil),
5042
+ %q{p -> { :hello }, a: 1 do end},
5043
+ %q{},
5044
+ ALL_VERSIONS - %w(1.8 1.9 mac ios 2.0)) # no 1.9 backport
4939
5045
  end
4940
5046
 
4941
5047
  def test_parser_bug_198