parser 3.0.0.0 → 3.0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5c9739554579c0061f120ab4da2fff7c46f93e73d7785fda21ee9c4c32aaa006
4
- data.tar.gz: 41c63f89745378c4ea653859ca7f0d957c48d9d9e75eb97aa86c919a6b8aa53d
3
+ metadata.gz: 2f2373806f006b11c31c2f32d9576d0518857bd56a6aa2cdcb726d53b9637b9b
4
+ data.tar.gz: 75b1007432711a397706519cf5c58ca8e4b1080d3d0ff2f78b7211335b339aab
5
5
  SHA512:
6
- metadata.gz: 035f3708a107fb247dcd71dadb85314245ad66a08889ec8a7829528434e7b661d1bd1533a4402a99797e6b133141c7ea0eb179f43d6247eb5707b2540a2c745f
7
- data.tar.gz: c2b628d2c64c79cb31f8bd5d294b17cfddefe4dd2126075f6241f40ce91f9d6ad33d1415b5ea6dc1a8254933c82c86d64a6cd4a8aa40b403ca124a3dc66e8fb0
6
+ metadata.gz: '01900a02647f2a01d3124adba64fa162d2bd34b894d5e308131bde78076efbaec5bcc9b78237cdfea3361b6a46358e9812e7cb6f09cbadec79bd0bf54c1046a9'
7
+ data.tar.gz: efcf5dcbc08a9082b495f39fe18379398f29ba97b0a00444bf26e2e32b477c31b7cf7e0c01c24f8e8b67e30f6c3ac87f42eb3a3d9201f97cec84fc9fd0062949
data/lib/parser/all.rb CHANGED
@@ -11,3 +11,4 @@ require 'parser/ruby25'
11
11
  require 'parser/ruby26'
12
12
  require 'parser/ruby27'
13
13
  require 'parser/ruby30'
14
+ require 'parser/ruby31'
@@ -161,7 +161,7 @@ module Parser
161
161
  #
162
162
  # ```
163
163
  # (send nil :foo
164
- # (hash
164
+ # (kwargs
165
165
  # (pair
166
166
  # (sym :a)
167
167
  # (int 42))
@@ -518,12 +518,52 @@ module Parser
518
518
  n(:pair, [ key, value ], pair_map)
519
519
  end
520
520
 
521
+ def pair_label(key_t)
522
+ key_l = loc(key_t)
523
+ value_l = key_l.adjust(end_pos: -1)
524
+
525
+ label = value(key_t)
526
+ value =
527
+ if label =~ /\A[[:lower:]]/
528
+ n(:ident, [ label.to_sym ], Source::Map::Variable.new(value_l))
529
+ else
530
+ n(:const, [ nil, label.to_sym ], Source::Map::Constant.new(nil, value_l, value_l))
531
+ end
532
+ pair_keyword(key_t, accessible(value))
533
+ end
534
+
521
535
  def kwsplat(dstar_t, arg)
522
536
  n(:kwsplat, [ arg ],
523
537
  unary_op_map(dstar_t, arg))
524
538
  end
525
539
 
526
540
  def associate(begin_t, pairs, end_t)
541
+ 0.upto(pairs.length - 1) do |i|
542
+ (i + 1).upto(pairs.length - 1) do |j|
543
+ key1, = *pairs[i]
544
+ key2, = *pairs[j]
545
+
546
+ do_warn = false
547
+
548
+ # keys have to be simple nodes, MRI ignores equal composite keys like
549
+ # `{ a(1) => 1, a(1) => 1 }`
550
+ case key1.type
551
+ when :sym, :str, :int, :float
552
+ if key1 == key2
553
+ do_warn = true
554
+ end
555
+ when :rational, :complex, :regexp
556
+ if @parser.version >= 31 && key1 == key2
557
+ do_warn = true
558
+ end
559
+ end
560
+
561
+ if do_warn
562
+ diagnostic :warning, :duplicate_hash_key, nil, key2.loc.expression
563
+ end
564
+ end
565
+ end
566
+
527
567
  n(:hash, [ *pairs ],
528
568
  collection_map(begin_t, pairs, end_t))
529
569
  end
@@ -608,19 +648,29 @@ module Parser
608
648
  when :ident
609
649
  name, = *node
610
650
 
611
- if @parser.static_env.declared?(name)
612
- if name.to_s == parser.current_arg_stack.top
613
- diagnostic :error, :circular_argument_reference,
614
- { :var_name => name.to_s }, node.loc.expression
615
- end
651
+ if %w[? !].any? { |c| name.to_s.end_with?(c) }
652
+ diagnostic :error, :invalid_id_to_get,
653
+ { :identifier => name.to_s }, node.loc.expression
654
+ end
616
655
 
617
- node.updated(:lvar)
618
- else
619
- name, = *node
620
- n(:send, [ nil, name ],
656
+ # Numbered parameters are not declared anywhere,
657
+ # so they take precedence over method calls in numblock contexts
658
+ if @parser.version >= 27 && @parser.try_declare_numparam(node)
659
+ return node.updated(:lvar)
660
+ end
661
+
662
+ unless @parser.static_env.declared?(name)
663
+ return n(:send, [ nil, name ],
621
664
  var_send_map(node))
622
665
  end
623
666
 
667
+ if name.to_s == parser.current_arg_stack.top
668
+ diagnostic :error, :circular_argument_reference,
669
+ { :var_name => name.to_s }, node.loc.expression
670
+ end
671
+
672
+ node.updated(:lvar)
673
+
624
674
  else
625
675
  node
626
676
  end
@@ -683,6 +733,17 @@ module Parser
683
733
 
684
734
  node.updated(:lvasgn)
685
735
 
736
+ when :match_var
737
+ name, = *node
738
+
739
+ var_name = node.children[0].to_s
740
+ name_loc = node.loc.expression
741
+
742
+ check_assignment_to_numparam(var_name, name_loc)
743
+ check_reserved_for_numparam(var_name, name_loc)
744
+
745
+ node
746
+
686
747
  when :nil, :self, :true, :false,
687
748
  :__FILE__, :__LINE__, :__ENCODING__
688
749
  diagnostic :error, :invalid_assignment, nil, node.loc.expression
@@ -1724,7 +1785,7 @@ module Parser
1724
1785
  end
1725
1786
 
1726
1787
  def check_lvar_name(name, loc)
1727
- if name =~ /\A[[[:lower:]]|_][[[:alnum:]]_]*\z/
1788
+ if name =~ /\A[[[:lower:]]_][[[:alnum:]]_]*\z/
1728
1789
  # OK
1729
1790
  else
1730
1791
  diagnostic :error, :lvar_name, { name: name }, loc
@@ -57,7 +57,7 @@ module Parser
57
57
  CurrentRuby = Ruby24
58
58
 
59
59
  when /^2\.5\./
60
- current_version = '2.5.8'
60
+ current_version = '2.5.9'
61
61
  if RUBY_VERSION != current_version
62
62
  warn_syntax_deviation 'parser/ruby25', current_version
63
63
  end
@@ -66,7 +66,7 @@ module Parser
66
66
  CurrentRuby = Ruby25
67
67
 
68
68
  when /^2\.6\./
69
- current_version = '2.6.6'
69
+ current_version = '2.6.9'
70
70
  if RUBY_VERSION != current_version
71
71
  warn_syntax_deviation 'parser/ruby26', current_version
72
72
  end
@@ -75,7 +75,7 @@ module Parser
75
75
  CurrentRuby = Ruby26
76
76
 
77
77
  when /^2\.7\./
78
- current_version = '2.7.2'
78
+ current_version = '2.7.5'
79
79
  if RUBY_VERSION != current_version
80
80
  warn_syntax_deviation 'parser/ruby27', current_version
81
81
  end
@@ -84,7 +84,7 @@ module Parser
84
84
  CurrentRuby = Ruby27
85
85
 
86
86
  when /^3\.0\./
87
- current_version = '3.0.0'
87
+ current_version = '3.0.3'
88
88
  if RUBY_VERSION != current_version
89
89
  warn_syntax_deviation 'parser/ruby30', current_version
90
90
  end
@@ -92,6 +92,15 @@ module Parser
92
92
  require 'parser/ruby30'
93
93
  CurrentRuby = Ruby30
94
94
 
95
+ when /^3\.1\./
96
+ current_version = '3.1.0-dev'
97
+ if RUBY_VERSION != current_version
98
+ warn_syntax_deviation 'parser/ruby31', current_version
99
+ end
100
+
101
+ require 'parser/ruby31'
102
+ CurrentRuby = Ruby31
103
+
95
104
  else # :nocov:
96
105
  # Keep this in sync with released Ruby.
97
106
  warn_syntax_deviation 'parser/ruby30', '3.0.x'
@@ -38,7 +38,13 @@ module Parser
38
38
  # Prevent the following error when processing binary encoded source.
39
39
  # "\xC0".split # => ArgumentError (invalid byte sequence in UTF-8)
40
40
  lines = string.force_encoding(Encoding::BINARY).split("\\\n")
41
- lines.map! {|s| s.force_encoding(original_encoding) }
41
+ if lines.length == 1
42
+ # If the line continuation sequence was found but there is no second
43
+ # line, it was not really a line continuation and must be ignored.
44
+ lines = [string]
45
+ else
46
+ lines.map! {|s| s.force_encoding(original_encoding) }
47
+ end
42
48
 
43
49
  if @at_line_begin
44
50
  lines_to_dedent = lines