parser 3.0.1.0 → 3.0.1.1

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.
data/lib/parser/runner.rb CHANGED
@@ -118,6 +118,11 @@ module Parser
118
118
  @parser_class = Parser::Ruby30
119
119
  end
120
120
 
121
+ opts.on '--31', 'Parse as Ruby 3.1 would' do
122
+ require 'parser/ruby31'
123
+ @parser_class = Parser::Ruby31
124
+ end
125
+
121
126
  opts.on '--mac', 'Parse as MacRuby 0.12 would' do
122
127
  require 'parser/macruby'
123
128
  @parser_class = Parser::MacRuby
@@ -48,6 +48,19 @@ module Parser
48
48
  associator.associate_locations
49
49
  end
50
50
 
51
+ ##
52
+ # Associate `comments` with `ast` nodes using identity.
53
+ #
54
+ # @param [Parser::AST::Node] ast
55
+ # @param [Array<Comment>] comments
56
+ # @return [Hash<Parser::Source::Node, Array<Comment>>]
57
+ # @see Parser::Source::Comment::Associator#associate_by_identity
58
+ #
59
+ def self.associate_by_identity(ast, comments)
60
+ associator = Associator.new(ast, comments)
61
+ associator.associate_by_identity
62
+ end
63
+
51
64
  ##
52
65
  # @param [Parser::Source::Range] range
53
66
  #
@@ -84,12 +84,24 @@ module Parser
84
84
  #
85
85
  # Note that {associate} produces unexpected result for nodes which are
86
86
  # equal but have distinct locations; comments for these nodes are merged.
87
+ # You may prefer using {associate_by_identity} or {associate_locations}.
87
88
  #
88
89
  # @return [Hash<Parser::AST::Node, Array<Parser::Source::Comment>>]
89
90
  # @deprecated Use {associate_locations}.
90
91
  #
91
92
  def associate
92
- @map_using_locations = false
93
+ @map_using = :eql
94
+ do_associate
95
+ end
96
+
97
+ ##
98
+ # Same as {associate}, but compares by identity, thus producing an unambiguous
99
+ # result even in presence of equal nodes.
100
+ #
101
+ # @return [Hash<Parser::Source::Node, Array<Parser::Source::Comment>>]
102
+ #
103
+ def associate_locations
104
+ @map_using = :location
93
105
  do_associate
94
106
  end
95
107
 
@@ -100,8 +112,8 @@ module Parser
100
112
  #
101
113
  # @return [Hash<Parser::Source::Map, Array<Parser::Source::Comment>>]
102
114
  #
103
- def associate_locations
104
- @map_using_locations = true
115
+ def associate_by_identity
116
+ @map_using = :identity
105
117
  do_associate
106
118
  end
107
119
 
@@ -122,6 +134,7 @@ module Parser
122
134
 
123
135
  def do_associate
124
136
  @mapping = Hash.new { |h, k| h[k] = [] }
137
+ @mapping.compare_by_identity if @map_using == :identity
125
138
  @comment_num = -1
126
139
  advance_comment
127
140
 
@@ -191,7 +204,7 @@ module Parser
191
204
  end
192
205
 
193
206
  def associate_and_advance_comment(node)
194
- key = @map_using_locations ? node.location : node
207
+ key = @map_using == :location ? node.location : node
195
208
  @mapping[key] << @current_comment
196
209
  advance_comment
197
210
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Parser
4
- VERSION = '3.0.1.0'
4
+ VERSION = '3.0.1.1'
5
5
  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: 3.0.1.0
4
+ version: 3.0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - whitequark
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-06 00:00:00.000000000 Z
11
+ date: 2021-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ast
@@ -205,6 +205,7 @@ files:
205
205
  - lib/parser/ruby27.rb
206
206
  - lib/parser/ruby28.rb
207
207
  - lib/parser/ruby30.rb
208
+ - lib/parser/ruby31.rb
208
209
  - lib/parser/rubymotion.rb
209
210
  - lib/parser/runner.rb
210
211
  - lib/parser/runner/ruby_parse.rb
@@ -244,9 +245,9 @@ licenses:
244
245
  - MIT
245
246
  metadata:
246
247
  bug_tracker_uri: https://github.com/whitequark/parser/issues
247
- changelog_uri: https://github.com/whitequark/parser/blob/v3.0.1.0/CHANGELOG.md
248
- documentation_uri: https://www.rubydoc.info/gems/parser/3.0.1.0
249
- source_code_uri: https://github.com/whitequark/parser/tree/v3.0.1.0
248
+ changelog_uri: https://github.com/whitequark/parser/blob/v3.0.1.1/CHANGELOG.md
249
+ documentation_uri: https://www.rubydoc.info/gems/parser/3.0.1.1
250
+ source_code_uri: https://github.com/whitequark/parser/tree/v3.0.1.1
250
251
  post_install_message:
251
252
  rdoc_options: []
252
253
  require_paths: