parser 2.5.0.5 → 2.5.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1104,7 +1104,7 @@ rule
1104
1104
  }
1105
1105
  bodystmt kEND
1106
1106
  {
1107
- if @context.indirectly_in_def?
1107
+ unless @context.class_definition_allowed?
1108
1108
  diagnostic :error, :class_in_def, nil, val[0]
1109
1109
  end
1110
1110
 
@@ -1139,7 +1139,7 @@ rule
1139
1139
  }
1140
1140
  bodystmt kEND
1141
1141
  {
1142
- if @context.indirectly_in_def?
1142
+ unless @context.module_definition_allowed?
1143
1143
  diagnostic :error, :module_in_def, nil, val[0]
1144
1144
  end
1145
1145
 
@@ -101,6 +101,11 @@ module Parser
101
101
  @parser_class = Parser::Ruby25
102
102
  end
103
103
 
104
+ opts.on '--26', 'Parse as Ruby 2.6 would' do
105
+ require 'parser/ruby26'
106
+ @parser_class = Parser::Ruby26
107
+ end
108
+
104
109
  opts.on '--mac', 'Parse as MacRuby 0.12 would' do
105
110
  require 'parser/macruby'
106
111
  @parser_class = Parser::MacRuby
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Parser
4
- VERSION = '2.5.0.5'
4
+ VERSION = '2.5.1.0'
5
5
  end
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
24
24
  lib/parser/ruby23.rb
25
25
  lib/parser/ruby24.rb
26
26
  lib/parser/ruby25.rb
27
+ lib/parser/ruby26.rb
27
28
  lib/parser/macruby.rb
28
29
  lib/parser/rubymotion.rb
29
30
  )
@@ -8,8 +8,19 @@ require 'simplecov'
8
8
  if ENV.include?('COVERAGE') && SimpleCov.usable?
9
9
  require_relative 'racc_coverage_helper'
10
10
 
11
- RaccCoverage.start(%w(ruby18.y ruby19.y ruby20.y ruby21.y ruby22.y ruby23.y ruby24.y ruby25.y),
12
- File.expand_path('../../lib/parser', __FILE__))
11
+ RaccCoverage.start(
12
+ %w(
13
+ ruby18.y
14
+ ruby19.y
15
+ ruby20.y
16
+ ruby21.y
17
+ ruby22.y
18
+ ruby23.y
19
+ ruby24.y
20
+ ruby25.y
21
+ ruby26.y
22
+ ),
23
+ File.expand_path('../../lib/parser', __FILE__))
13
24
 
14
25
  # Report results faster.
15
26
  at_exit { RaccCoverage.stop }
@@ -7,7 +7,7 @@ module ParseHelper
7
7
  require 'parser/macruby'
8
8
  require 'parser/rubymotion'
9
9
 
10
- ALL_VERSIONS = %w(1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 mac ios)
10
+ ALL_VERSIONS = %w(1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 mac ios)
11
11
 
12
12
  def setup
13
13
  @diagnostics = []
@@ -25,6 +25,7 @@ module ParseHelper
25
25
  when '2.3' then parser = Parser::Ruby23.new
26
26
  when '2.4' then parser = Parser::Ruby24.new
27
27
  when '2.5' then parser = Parser::Ruby25.new
28
+ when '2.6' then parser = Parser::Ruby26.new
28
29
  when 'mac' then parser = Parser::MacRuby.new
29
30
  when 'ios' then parser = Parser::RubyMotion.new
30
31
  else raise "Unrecognized Ruby version #{version}"
@@ -18,6 +18,8 @@ class TestCurrent < Minitest::Test
18
18
  assert_equal Parser::Ruby24, Parser::CurrentRuby
19
19
  when /^2\.5\.\d+/
20
20
  assert_equal Parser::Ruby25, Parser::CurrentRuby
21
+ when /^2\.6\.\d+/
22
+ assert_equal Parser::Ruby26, Parser::CurrentRuby
21
23
  else
22
24
  flunk "Update test_current for #{RUBY_VERSION}"
23
25
  end
@@ -1944,7 +1944,7 @@ class TestLexer < Minitest::Test
1944
1944
  :tIDENTIFIER, "a", [0, 1],
1945
1945
  :tSTAR2, "*", [2, 3])
1946
1946
 
1947
- assert_equal :expr_beg, @lex.state
1947
+ assert_equal :expr_value, @lex.state
1948
1948
  end
1949
1949
 
1950
1950
  def test_star2
@@ -1952,7 +1952,7 @@ class TestLexer < Minitest::Test
1952
1952
  :tIDENTIFIER, "a", [0, 1],
1953
1953
  :tPOW, "**", [2, 4])
1954
1954
 
1955
- assert_equal :expr_beg, @lex.state
1955
+ assert_equal :expr_value, @lex.state
1956
1956
  end
1957
1957
 
1958
1958
  def test_star2_equals
@@ -3498,4 +3498,40 @@ class TestLexer < Minitest::Test
3498
3498
  :tIDENTIFIER, 'cond', [11, 15])
3499
3499
  end
3500
3500
 
3501
+ def test_parser_bug_486
3502
+ setup_lexer(19)
3503
+ assert_scanned(':!@',
3504
+ :tSYMBOL, '!', [0, 3])
3505
+
3506
+ setup_lexer(19)
3507
+ assert_scanned(':~@',
3508
+ :tSYMBOL, '~', [0, 3])
3509
+ end
3510
+
3511
+ def test_slash_only_in_heredocs
3512
+ setup_lexer(23)
3513
+ refute_scanned(%Q{<<~E\n\\\nE})
3514
+
3515
+ setup_lexer(23)
3516
+ refute_scanned(%Q{<<-E\n\\\nE})
3517
+ end
3518
+
3519
+ def test_escapes_in_squiggly_heredoc
3520
+ setup_lexer(23)
3521
+
3522
+ assert_scanned(%Q{<<~E\n\a\b\e\f\r\t\\\v\nE},
3523
+ :tSTRING_BEG, '<<"', [0, 4],
3524
+ :tSTRING_CONTENT, "\a\b\e\f\r\t\v\n", [5, 14],
3525
+ :tSTRING_END, 'E', [14, 15],
3526
+ :tNL, nil, [4, 5])
3527
+
3528
+ setup_lexer(23)
3529
+
3530
+ assert_scanned(%Q{<<-E\n\a\b\e\f\r\t\\\v\nE},
3531
+ :tSTRING_BEG, '<<"', [0, 4],
3532
+ :tSTRING_CONTENT, "\a\b\e\f\r\t\v\n", [5, 14],
3533
+ :tSTRING_END, 'E', [14, 15],
3534
+ :tNL, nil, [4, 5])
3535
+ end
3536
+
3501
3537
  end
@@ -27,6 +27,7 @@ class TestParser < Minitest::Test
27
27
  SINCE_2_3 = SINCE_2_2 - %w(2.2)
28
28
  SINCE_2_4 = SINCE_2_3 - %w(2.3)
29
29
  SINCE_2_5 = SINCE_2_4 - %w(2.4)
30
+ SINCE_2_6 = SINCE_2_5 - %w(2.5)
30
31
 
31
32
  # Guidelines for test naming:
32
33
  # * Test structure follows structure of AST_FORMAT.md.
@@ -3915,7 +3916,8 @@ class TestParser < Minitest::Test
3915
3916
  s(:args),
3916
3917
  s(:int, 1)),
3917
3918
  %q{f 1, {1 => 2} {1}},
3918
- %q{})
3919
+ %q{},
3920
+ ALL_VERSIONS - SINCE_2_5)
3919
3921
  end
3920
3922
 
3921
3923
  def test_space_args_arg_call
@@ -4940,7 +4942,8 @@ class TestParser < Minitest::Test
4940
4942
  s(:begin,
4941
4943
  s(:int, 2))),
4942
4944
  %q{begin; else; 2; end},
4943
- %q{ ~~~~ begin (begin)})
4945
+ %q{ ~~~~ begin (begin)},
4946
+ ALL_VERSIONS - SINCE_2_6)
4944
4947
 
4945
4948
  assert_parses(
4946
4949
  s(:kwbegin,
@@ -4948,7 +4951,8 @@ class TestParser < Minitest::Test
4948
4951
  s(:begin,
4949
4952
  s(:int, 2))),
4950
4953
  %q{begin; 1; else; 2; end},
4951
- %q{ ~~~~ begin (begin)})
4954
+ %q{ ~~~~ begin (begin)},
4955
+ ALL_VERSIONS - SINCE_2_6)
4952
4956
 
4953
4957
  assert_parses(
4954
4958
  s(:kwbegin,
@@ -4957,12 +4961,20 @@ class TestParser < Minitest::Test
4957
4961
  s(:begin,
4958
4962
  s(:int, 3))),
4959
4963
  %q{begin; 1; 2; else; 3; end},
4960
- %q{ ~~~~ begin (begin)})
4964
+ %q{ ~~~~ begin (begin)},
4965
+ ALL_VERSIONS - SINCE_2_6)
4961
4966
 
4962
4967
  assert_diagnoses(
4963
4968
  [:warning, :useless_else],
4964
4969
  %q{begin; 1; else; 2; end},
4965
- %q{ ~~~~ location})
4970
+ %q{ ~~~~ location},
4971
+ ALL_VERSIONS - SINCE_2_6)
4972
+
4973
+ assert_diagnoses(
4974
+ [:error, :useless_else],
4975
+ %q{begin; 1; else; 2; end},
4976
+ %q{ ~~~~ location},
4977
+ SINCE_2_6)
4966
4978
  end
4967
4979
 
4968
4980
  def test_ensure
@@ -6416,9 +6428,9 @@ class TestParser < Minitest::Test
6416
6428
 
6417
6429
  def test_context_cmd_brace_block
6418
6430
  [
6419
- 'tap 1, { 1 => 2 } {',
6420
- 'foo.tap 1, { 1 => 2 } {',
6421
- 'foo::tap 1, { 1 => 2 } {'
6431
+ 'tap foo {',
6432
+ 'foo.tap foo {',
6433
+ 'foo::tap foo {'
6422
6434
  ].each do |code|
6423
6435
  assert_context([:block], code, ALL_VERSIONS)
6424
6436
  end
@@ -6736,7 +6748,7 @@ class TestParser < Minitest::Test
6736
6748
  [:error, :unexpected_token, { :token => 'tLCURLY' }],
6737
6749
  %q{m [] {}},
6738
6750
  %q{ ^ location},
6739
- SINCE_2_4)
6751
+ SINCE_2_5)
6740
6752
 
6741
6753
  assert_parses(
6742
6754
  s(:block,
@@ -6745,7 +6757,7 @@ class TestParser < Minitest::Test
6745
6757
  s(:args), nil),
6746
6758
  %q{meth[] {}},
6747
6759
  %q{},
6748
- SINCE_2_4
6760
+ SINCE_2_5
6749
6761
  )
6750
6762
 
6751
6763
  assert_diagnoses_many(
@@ -6842,4 +6854,115 @@ class TestParser < Minitest::Test
6842
6854
  %q{},
6843
6855
  ALL_VERSIONS)
6844
6856
  end
6857
+
6858
+ def test_bug_480
6859
+ assert_parses(
6860
+ s(:send, nil, :m,
6861
+ s(:dstr,
6862
+ s(:begin),
6863
+ s(:begin,
6864
+ s(:begin)))),
6865
+ %q{m "#{}#{()}"},
6866
+ %q{},
6867
+ ALL_VERSIONS)
6868
+ end
6869
+
6870
+ def test_bug_481
6871
+ assert_parses(
6872
+ s(:begin,
6873
+ s(:send, nil, :m,
6874
+ s(:def, :x,
6875
+ s(:args), nil)),
6876
+ s(:block,
6877
+ s(:send,
6878
+ s(:int, 1), :tap),
6879
+ s(:args), nil)),
6880
+ %q{m def x(); end; 1.tap do end},
6881
+ %q{},
6882
+ ALL_VERSIONS)
6883
+ end
6884
+
6885
+ def test_parser_bug_490
6886
+ assert_parses(
6887
+ s(:def, :m,
6888
+ s(:args),
6889
+ s(:sclass,
6890
+ s(:self),
6891
+ s(:class,
6892
+ s(:const, nil, :C), nil, nil))),
6893
+ %q{def m; class << self; class C; end; end; end},
6894
+ %q{},
6895
+ ALL_VERSIONS)
6896
+
6897
+ assert_parses(
6898
+ s(:def, :m,
6899
+ s(:args),
6900
+ s(:sclass,
6901
+ s(:self),
6902
+ s(:module,
6903
+ s(:const, nil, :M), nil))),
6904
+ %q{def m; class << self; module M; end; end; end},
6905
+ %q{},
6906
+ ALL_VERSIONS)
6907
+
6908
+ assert_parses(
6909
+ s(:def, :m,
6910
+ s(:args),
6911
+ s(:sclass,
6912
+ s(:self),
6913
+ s(:casgn, nil, :A,
6914
+ s(:nil)))),
6915
+ %q{def m; class << self; A = nil; end; end},
6916
+ %q{},
6917
+ ALL_VERSIONS)
6918
+ end
6919
+
6920
+ def test_slash_newline_in_heredocs
6921
+ assert_parses(
6922
+ s(:dstr,
6923
+ s(:str, "1 2\n"),
6924
+ s(:str, "3\n")),
6925
+ %Q{<<~E\n 1 \\\n 2\n 3\nE\n},
6926
+ %q{},
6927
+ SINCE_2_3)
6928
+
6929
+ assert_parses(
6930
+ s(:dstr,
6931
+ s(:str, " 1 2\n"),
6932
+ s(:str, " 3\n")),
6933
+ %Q{<<-E\n 1 \\\n 2\n 3\nE\n},
6934
+ %q{},
6935
+ ALL_VERSIONS)
6936
+ end
6937
+
6938
+ def test_ambiuous_quoted_label_in_ternary_operator
6939
+ assert_parses(
6940
+ s(:if,
6941
+ s(:send, nil, :a),
6942
+ s(:send,
6943
+ s(:send, nil, :b), :&,
6944
+ s(:str, '')),
6945
+ s(:nil)),
6946
+ %q{a ? b & '': nil},
6947
+ %q{},
6948
+ ALL_VERSIONS)
6949
+
6950
+ assert_diagnoses(
6951
+ [:error, :unexpected_token, { :token => 'tLABEL_END' }],
6952
+ %q{a ? b | '': nil},
6953
+ %q{ ^~ location},
6954
+ SINCE_2_2)
6955
+
6956
+ assert_diagnoses(
6957
+ [:error, :unexpected_token, { :token => 'tTILDE' }],
6958
+ %q{a ? b ~ '': nil},
6959
+ %q{ ^ location},
6960
+ SINCE_2_2)
6961
+
6962
+ assert_diagnoses(
6963
+ [:error, :unexpected_token, { :token => 'tBANG' }],
6964
+ %q{a ? b ! '': nil},
6965
+ %q{ ^ location},
6966
+ SINCE_2_2)
6967
+ end
6845
6968
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.0.5
4
+ version: 2.5.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - whitequark
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-24 00:00:00.000000000 Z
11
+ date: 2018-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ast
@@ -216,6 +216,8 @@ files:
216
216
  - lib/parser/ruby24.y
217
217
  - lib/parser/ruby25.rb
218
218
  - lib/parser/ruby25.y
219
+ - lib/parser/ruby26.rb
220
+ - lib/parser/ruby26.y
219
221
  - lib/parser/rubymotion.rb
220
222
  - lib/parser/rubymotion.y
221
223
  - lib/parser/runner.rb