parser 3.2.2.3 → 3.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6df2e6383fb2571b7b534703d56589f4ee58235cf8579eb42409915bad548bf1
4
- data.tar.gz: ae96b9894891d64599e0253d35a274f41e17d5a7f1d18c2b121faedd1d5ee978
3
+ metadata.gz: afc1515c06b8557b5f15fcc7575524189c127b94184ecdce6df93960a4d97516
4
+ data.tar.gz: b5a2d1b9e4ec2446b98f6d6de6d68c7b3c6fce7b57556e03e6b68938d2dee1ef
5
5
  SHA512:
6
- metadata.gz: a225b9a96a99999e59b4d4c61f056e7501073a9b69bed0987f6ea7272f38efe7aaae50901cfbf3074c4de6174622bf9282ecd8b1b915ecc9aed462ebde2e6faf
7
- data.tar.gz: 17116f52ec7abc4f13fd1fecf9c0edf0c8a0fc07294c1b60eb5c7c113571788a5ef3c077e7e774671a490d8c606f0dce52723f84cb9752ea580ee1d764c16066
6
+ metadata.gz: 6677f0acce4584140ae9bf9597c583986496e68a4411799d0172e6a9f13e6b78fceee4844b278091f0c5fb9db66417faa18db51e854b0901313d942650ceb402
7
+ data.tar.gz: 81f225e76c4ed00ca5ccd2598200423fcc9c03ef6a5d2d331c5b592a6ae8d53d4c33129383b30e671e115d024ec0d553f8c4bfa89223557111f69cd43598b38c
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'gauntlet'
4
- require 'parser/all'
4
+ require_relative 'parser/all'
5
5
  require 'shellwords'
6
6
 
7
7
  class ParserGauntlet < Gauntlet
data/lib/parser/all.rb CHANGED
@@ -1,16 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'parser/ruby18'
4
- require 'parser/ruby19'
5
- require 'parser/ruby20'
6
- require 'parser/ruby21'
7
- require 'parser/ruby22'
8
- require 'parser/ruby23'
9
- require 'parser/ruby24'
10
- require 'parser/ruby25'
11
- require 'parser/ruby26'
12
- require 'parser/ruby27'
13
- require 'parser/ruby30'
14
- require 'parser/ruby31'
15
- require 'parser/ruby32'
16
- require 'parser/ruby33'
3
+ require_relative 'ruby18'
4
+ require_relative 'ruby19'
5
+ require_relative 'ruby20'
6
+ require_relative 'ruby21'
7
+ require_relative 'ruby22'
8
+ require_relative 'ruby23'
9
+ require_relative 'ruby24'
10
+ require_relative 'ruby25'
11
+ require_relative 'ruby26'
12
+ require_relative 'ruby27'
13
+ require_relative 'ruby30'
14
+ require_relative 'ruby31'
15
+ require_relative 'ruby32'
16
+ require_relative 'ruby33'
17
+ require_relative 'ruby34'
@@ -6,7 +6,9 @@ module Parser
6
6
  ##
7
7
  # @api public
8
8
  #
9
- class Processor < ::AST::Processor
9
+ class Processor
10
+ include ::AST::Processor::Mixin
11
+
10
12
  def process_regular_node(node)
11
13
  node.updated(nil, process_all(node))
12
14
  end
@@ -594,7 +594,13 @@ module Parser
594
594
  end
595
595
 
596
596
  def gvar(token)
597
- n(:gvar, [ value(token).to_sym ],
597
+ gvar_name = value(token)
598
+
599
+ if gvar_name.start_with?('$0') && gvar_name.length > 2
600
+ diagnostic :error, :gvar_name, { :name => gvar_name }, loc(token)
601
+ end
602
+
603
+ n(:gvar, [ gvar_name.to_sym ],
598
604
  variable_map(token))
599
605
  end
600
606
 
@@ -654,6 +660,13 @@ module Parser
654
660
  end
655
661
 
656
662
  unless @parser.static_env.declared?(name)
663
+ if @parser.version == 33 &&
664
+ name == :it &&
665
+ @parser.context.in_block &&
666
+ !@parser.max_numparam_stack.has_ordinary_params?
667
+ diagnostic :warning, :ambiguous_it_call, nil, node.loc.expression
668
+ end
669
+
657
670
  return n(:send, [ nil, name ],
658
671
  var_send_map(node))
659
672
  end
@@ -1690,24 +1703,34 @@ module Parser
1690
1703
  cond
1691
1704
  end
1692
1705
 
1693
- when :and, :or, :irange, :erange
1706
+ when :and, :or
1694
1707
  lhs, rhs = *cond
1695
1708
 
1696
- type = case cond.type
1697
- when :irange then :iflipflop
1698
- when :erange then :eflipflop
1699
- end
1700
-
1701
- if [:and, :or].include?(cond.type) &&
1702
- @parser.version == 18
1709
+ if @parser.version == 18
1703
1710
  cond
1704
1711
  else
1705
- cond.updated(type, [
1712
+ cond.updated(cond.type, [
1706
1713
  check_condition(lhs),
1707
1714
  check_condition(rhs)
1708
1715
  ])
1709
1716
  end
1710
1717
 
1718
+ when :irange, :erange
1719
+ lhs, rhs = *cond
1720
+
1721
+ type = case cond.type
1722
+ when :irange then :iflipflop
1723
+ when :erange then :eflipflop
1724
+ end
1725
+
1726
+ lhs_condition = check_condition(lhs) unless lhs.nil?
1727
+ rhs_condition = check_condition(rhs) unless rhs.nil?
1728
+
1729
+ return cond.updated(type, [
1730
+ lhs_condition,
1731
+ rhs_condition
1732
+ ])
1733
+
1711
1734
  when :regexp
1712
1735
  n(:match_current_line, [ cond ], expr_map(cond.loc.expression))
1713
1736
 
@@ -2245,6 +2268,10 @@ module Parser
2245
2268
 
2246
2269
  def static_regexp_node(node)
2247
2270
  if node.type == :regexp
2271
+ if @parser.version >= 33 && node.children[0..-2].any? { |child| child.type != :str }
2272
+ return nil
2273
+ end
2274
+
2248
2275
  parts, options = node.children[0..-2], node.children[-1]
2249
2276
  static_regexp(parts, options)
2250
2277
  end
@@ -17,7 +17,7 @@ module Parser
17
17
  warn_syntax_deviation 'parser/ruby20', current_version
18
18
  end
19
19
 
20
- require 'parser/ruby20'
20
+ require_relative 'ruby20'
21
21
  CurrentRuby = Ruby20
22
22
 
23
23
  when /^2\.1\./
@@ -26,7 +26,7 @@ module Parser
26
26
  warn_syntax_deviation 'parser/ruby21', current_version
27
27
  end
28
28
 
29
- require 'parser/ruby21'
29
+ require_relative 'ruby21'
30
30
  CurrentRuby = Ruby21
31
31
 
32
32
  when /^2\.2\./
@@ -35,7 +35,7 @@ module Parser
35
35
  warn_syntax_deviation 'parser/ruby22', current_version
36
36
  end
37
37
 
38
- require 'parser/ruby22'
38
+ require_relative 'ruby22'
39
39
  CurrentRuby = Ruby22
40
40
 
41
41
  when /^2\.3\./
@@ -44,7 +44,7 @@ module Parser
44
44
  warn_syntax_deviation 'parser/ruby23', current_version
45
45
  end
46
46
 
47
- require 'parser/ruby23'
47
+ require_relative 'ruby23'
48
48
  CurrentRuby = Ruby23
49
49
 
50
50
  when /^2\.4\./
@@ -53,7 +53,7 @@ module Parser
53
53
  warn_syntax_deviation 'parser/ruby24', current_version
54
54
  end
55
55
 
56
- require 'parser/ruby24'
56
+ require_relative 'ruby24'
57
57
  CurrentRuby = Ruby24
58
58
 
59
59
  when /^2\.5\./
@@ -62,7 +62,7 @@ module Parser
62
62
  warn_syntax_deviation 'parser/ruby25', current_version
63
63
  end
64
64
 
65
- require 'parser/ruby25'
65
+ require_relative 'ruby25'
66
66
  CurrentRuby = Ruby25
67
67
 
68
68
  when /^2\.6\./
@@ -71,7 +71,7 @@ module Parser
71
71
  warn_syntax_deviation 'parser/ruby26', current_version
72
72
  end
73
73
 
74
- require 'parser/ruby26'
74
+ require_relative 'ruby26'
75
75
  CurrentRuby = Ruby26
76
76
 
77
77
  when /^2\.7\./
@@ -80,49 +80,58 @@ module Parser
80
80
  warn_syntax_deviation 'parser/ruby27', current_version
81
81
  end
82
82
 
83
- require 'parser/ruby27'
83
+ require_relative 'ruby27'
84
84
  CurrentRuby = Ruby27
85
85
 
86
86
  when /^3\.0\./
87
- current_version = '3.0.6'
87
+ current_version = '3.0.7'
88
88
  if RUBY_VERSION != current_version
89
89
  warn_syntax_deviation 'parser/ruby30', current_version
90
90
  end
91
91
 
92
- require 'parser/ruby30'
92
+ require_relative 'ruby30'
93
93
  CurrentRuby = Ruby30
94
94
 
95
95
  when /^3\.1\./
96
- current_version = '3.1.4'
96
+ current_version = '3.1.6'
97
97
  if RUBY_VERSION != current_version
98
98
  warn_syntax_deviation 'parser/ruby31', current_version
99
99
  end
100
100
 
101
- require 'parser/ruby31'
101
+ require_relative 'ruby31'
102
102
  CurrentRuby = Ruby31
103
103
 
104
104
  when /^3\.2\./
105
- current_version = '3.2.2'
105
+ current_version = '3.2.4'
106
106
  if RUBY_VERSION != current_version
107
107
  warn_syntax_deviation 'parser/ruby32', current_version
108
108
  end
109
109
 
110
- require 'parser/ruby32'
110
+ require_relative 'ruby32'
111
111
  CurrentRuby = Ruby32
112
112
 
113
113
  when /^3\.3\./
114
- current_version = '3.3.0-dev'
114
+ current_version = '3.3.3'
115
115
  if RUBY_VERSION != current_version
116
116
  warn_syntax_deviation 'parser/ruby33', current_version
117
117
  end
118
118
 
119
- require 'parser/ruby33'
119
+ require_relative 'ruby33'
120
120
  CurrentRuby = Ruby33
121
121
 
122
+ when /^3\.4\./
123
+ current_version = '3.4.0'
124
+ if RUBY_VERSION != current_version
125
+ warn_syntax_deviation 'parser/ruby34', current_version
126
+ end
127
+
128
+ require_relative 'ruby34'
129
+ CurrentRuby = Ruby34
130
+
122
131
  else # :nocov:
123
132
  # Keep this in sync with released Ruby.
124
- warn_syntax_deviation 'parser/ruby32', '3.2.x'
125
- require 'parser/ruby32'
126
- CurrentRuby = Ruby32
133
+ warn_syntax_deviation 'parser/ruby33', '3.3.x'
134
+ require_relative 'ruby33'
135
+ CurrentRuby = Ruby33
127
136
  end
128
137
  end
@@ -5,6 +5,8 @@ module Parser
5
5
 
6
6
  class Lexer::Literal
7
7
  DELIMITERS = { '(' => ')', '[' => ']', '{' => '}', '<' => '>' }
8
+ SPACE = ' '.ord
9
+ TAB = "\t".ord
8
10
 
9
11
  TYPES = {
10
12
  # type start token interpolate?
@@ -234,7 +236,20 @@ module Parser
234
236
  protected
235
237
 
236
238
  def delimiter?(delimiter)
237
- if @indent
239
+ if heredoc?
240
+ # This heredoc is valid:
241
+ # <<~E
242
+ # E
243
+ # and this:
244
+ # <<~E
245
+ # E
246
+ # but this one is not:
247
+ # <<~' E'
248
+ # E
249
+ # because there are not enough leading spaces in the closing delimiter.
250
+ delimiter.end_with?(@end_delim) &&
251
+ delimiter.sub(/#{Regexp.escape(@end_delim)}\z/, '').bytes.all? { |c| c == SPACE || c == TAB }
252
+ elsif @indent
238
253
  @end_delim == delimiter.lstrip
239
254
  else
240
255
  @end_delim == delimiter