parser 3.0.3.0 → 3.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2f2373806f006b11c31c2f32d9576d0518857bd56a6aa2cdcb726d53b9637b9b
4
- data.tar.gz: 75b1007432711a397706519cf5c58ca8e4b1080d3d0ff2f78b7211335b339aab
3
+ metadata.gz: 12a38198be7971a87e3fbc2514f45120238a8004b1b267382a481ea971c8d9ec
4
+ data.tar.gz: ec1a2a51e94eb30280b31e5f26cb28cb1e50b94a9d3a11ae35616b79eaf11b52
5
5
  SHA512:
6
- metadata.gz: '01900a02647f2a01d3124adba64fa162d2bd34b894d5e308131bde78076efbaec5bcc9b78237cdfea3361b6a46358e9812e7cb6f09cbadec79bd0bf54c1046a9'
7
- data.tar.gz: efcf5dcbc08a9082b495f39fe18379398f29ba97b0a00444bf26e2e32b477c31b7cf7e0c01c24f8e8b67e30f6c3ac87f42eb3a3d9201f97cec84fc9fd0062949
6
+ metadata.gz: e37d66e7c76e0af7d9ad1e9c3c635741436f92d0eef67032fdad83c38090c90cdb9be49018e20786ae540b24d18628695ab4b372a94c96e93b1ce36418e41da5
7
+ data.tar.gz: 9ad75e610252fb6db157948fb162b0907baedeac7c4107574b78b3869c2490afabec269ab31303ceec2a3a7f17659eb06b43e9b6677b279fb412abade076b93a
data/lib/parser/all.rb CHANGED
@@ -12,3 +12,4 @@ require 'parser/ruby26'
12
12
  require 'parser/ruby27'
13
13
  require 'parser/ruby30'
14
14
  require 'parser/ruby31'
15
+ require 'parser/ruby32'
@@ -714,7 +714,7 @@ module Parser
714
714
  node.updated(:gvasgn)
715
715
 
716
716
  when :const
717
- unless @parser.context.dynamic_const_definition_allowed?
717
+ if @parser.context.in_def
718
718
  diagnostic :error, :dynamic_const, nil, node.loc.expression
719
719
  end
720
720
 
@@ -879,8 +879,14 @@ module Parser
879
879
 
880
880
  def args(begin_t, args, end_t, check_args=true)
881
881
  args = check_duplicate_args(args) if check_args
882
- n(:args, args,
883
- collection_map(begin_t, args, end_t))
882
+ validate_no_forward_arg_after_restarg(args)
883
+
884
+ map = collection_map(begin_t, args, end_t)
885
+ if !self.class.emit_forward_arg && args.length == 1 && args[0].type == :forward_arg
886
+ n(:forward_args, [], map)
887
+ else
888
+ n(:args, args, map)
889
+ end
884
890
  end
885
891
 
886
892
  def numargs(max_numparam)
@@ -967,9 +973,12 @@ module Parser
967
973
  end
968
974
 
969
975
  def blockarg(amper_t, name_t)
970
- check_reserved_for_numparam(value(name_t), loc(name_t))
976
+ if !name_t.nil?
977
+ check_reserved_for_numparam(value(name_t), loc(name_t))
978
+ end
971
979
 
972
- n(:blockarg, [ value(name_t).to_sym ],
980
+ arg_name = name_t ? value(name_t).to_sym : nil
981
+ n(:blockarg, [ arg_name ],
973
982
  arg_prefix_map(amper_t, name_t))
974
983
  end
975
984
 
@@ -1744,6 +1753,21 @@ module Parser
1744
1753
  end
1745
1754
  end
1746
1755
 
1756
+ def validate_no_forward_arg_after_restarg(args)
1757
+ restarg = nil
1758
+ forward_arg = nil
1759
+ args.each do |arg|
1760
+ case arg.type
1761
+ when :restarg then restarg = arg
1762
+ when :forward_arg then forward_arg = arg
1763
+ end
1764
+ end
1765
+
1766
+ if !forward_arg.nil? && !restarg.nil?
1767
+ diagnostic :error, :forward_arg_after_restarg, nil, forward_arg.loc.expression, [restarg.loc.expression]
1768
+ end
1769
+ end
1770
+
1747
1771
  def check_assignment_to_numparam(name, loc)
1748
1772
  # MRI < 2.7 treats numbered parameters as regular variables
1749
1773
  # and so it's allowed to perform assignments like `_1 = 42`.
@@ -9,60 +9,41 @@ module Parser
9
9
  # + :sclass - in the singleton class body (class << obj; end)
10
10
  # + :def - in the method body (def m; end)
11
11
  # + :defs - in the singleton method body (def self.m; end)
12
+ # + :def_open_args - in the arglist of the method definition
13
+ # keep in mind that it's set **only** after reducing the first argument,
14
+ # if you need to handle the first argument check `lex_state == expr_fname`
12
15
  # + :block - in the block body (tap {})
13
16
  # + :lambda - in the lambda body (-> {})
14
17
  #
15
18
  class Context
16
- attr_reader :stack
19
+ FLAGS = %i[
20
+ in_defined
21
+ in_kwarg
22
+ in_argdef
23
+ in_def
24
+ in_class
25
+ in_block
26
+ in_lambda
27
+ ]
17
28
 
18
29
  def initialize
19
- @stack = []
20
- freeze
21
- end
22
-
23
- def push(state)
24
- @stack << state
25
- end
26
-
27
- def pop
28
- @stack.pop
30
+ reset
29
31
  end
30
32
 
31
33
  def reset
32
- @stack.clear
33
- end
34
-
35
- def empty?
36
- @stack.empty?
37
- end
38
-
39
- def in_class?
40
- @stack.last == :class
34
+ @in_defined = false
35
+ @in_kwarg = false
36
+ @in_argdef = false
37
+ @in_def = false
38
+ @in_class = false
39
+ @in_block = false
40
+ @in_lambda = false
41
41
  end
42
42
 
43
- def indirectly_in_def?
44
- @stack.include?(:def) || @stack.include?(:defs)
45
- end
46
-
47
- def class_definition_allowed?
48
- def_index = stack.rindex { |item| [:def, :defs].include?(item) }
49
- sclass_index = stack.rindex(:sclass)
50
-
51
- def_index.nil? || (!sclass_index.nil? && sclass_index > def_index)
52
- end
53
- alias module_definition_allowed? class_definition_allowed?
54
- alias dynamic_const_definition_allowed? class_definition_allowed?
55
-
56
- def in_block?
57
- @stack.last == :block
58
- end
59
-
60
- def in_lambda?
61
- @stack.last == :lambda
62
- end
43
+ attr_accessor(*FLAGS)
63
44
 
64
45
  def in_dynamic_block?
65
- in_block? || in_lambda?
46
+ in_block || in_lambda
66
47
  end
67
48
  end
68
49
  end
@@ -3,9 +3,9 @@
3
3
  module Parser
4
4
  class << self
5
5
  def warn_syntax_deviation(feature, version)
6
- warn "warning: parser/current is loading #{feature}, which recognizes"
7
- warn "warning: #{version}-compliant syntax, but you are running #{RUBY_VERSION}."
8
- warn "warning: please see https://github.com/whitequark/parser#compatibility-with-ruby-mri."
6
+ warn "warning: parser/current is loading #{feature}, which recognizes" \
7
+ "#{version}-compliant syntax, but you are running #{RUBY_VERSION}.\n" \
8
+ "Please see https://github.com/whitequark/parser#compatibility-with-ruby-mri."
9
9
  end
10
10
  private :warn_syntax_deviation
11
11
  end
@@ -93,7 +93,7 @@ module Parser
93
93
  CurrentRuby = Ruby30
94
94
 
95
95
  when /^3\.1\./
96
- current_version = '3.1.0-dev'
96
+ current_version = '3.1.1'
97
97
  if RUBY_VERSION != current_version
98
98
  warn_syntax_deviation 'parser/ruby31', current_version
99
99
  end
@@ -101,10 +101,19 @@ module Parser
101
101
  require 'parser/ruby31'
102
102
  CurrentRuby = Ruby31
103
103
 
104
+ when /^3\.2\./
105
+ current_version = '3.2.0-dev'
106
+ if RUBY_VERSION != current_version
107
+ warn_syntax_deviation 'parser/ruby32', current_version
108
+ end
109
+
110
+ require 'parser/ruby32'
111
+ CurrentRuby = Ruby32
112
+
104
113
  else # :nocov:
105
114
  # Keep this in sync with released Ruby.
106
- warn_syntax_deviation 'parser/ruby30', '3.0.x'
107
- require 'parser/ruby30'
108
- CurrentRuby = Ruby30
115
+ warn_syntax_deviation 'parser/ruby31', '3.1.x'
116
+ require 'parser/ruby31'
117
+ CurrentRuby = Ruby31
109
118
  end
110
119
  end
@@ -41,7 +41,7 @@ module Parser
41
41
  if lines.length == 1
42
42
  # If the line continuation sequence was found but there is no second
43
43
  # line, it was not really a line continuation and must be ignored.
44
- lines = [string]
44
+ lines = [string.force_encoding(original_encoding)]
45
45
  else
46
46
  lines.map! {|s| s.force_encoding(original_encoding) }
47
47
  end
@@ -18,7 +18,7 @@ module Parser
18
18
  def advance
19
19
  type, (val, range) = advance_before_explanation
20
20
 
21
- more = "(in-kwarg)" if @in_kwarg
21
+ more = "(in-kwarg)" if @context.in_kwarg
22
22
 
23
23
  puts decorate(range,
24
24
  Color.green("#{type} #{val.inspect}"),