parser 2.7.2.0 → 3.0.0.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 +4 -4
- data/LICENSE.txt +25 -0
- data/lib/parser/ast/processor.rb +3 -0
- data/lib/parser/base.rb +1 -0
- data/lib/parser/builders/default.rb +125 -12
- data/lib/parser/context.rb +4 -0
- data/lib/parser/current.rb +4 -4
- data/lib/parser/current_arg_stack.rb +5 -2
- data/lib/parser/lexer.rb +812 -802
- data/lib/parser/max_numparam_stack.rb +12 -4
- data/lib/parser/messages.rb +1 -0
- data/lib/parser/meta.rb +2 -1
- data/lib/parser/ruby18.rb +6 -2
- data/lib/parser/ruby27.rb +3719 -3699
- data/lib/parser/ruby30.rb +3657 -3649
- data/lib/parser/runner.rb +1 -1
- data/lib/parser/source/buffer.rb +45 -27
- data/lib/parser/static_environment.rb +4 -0
- data/lib/parser/variables_stack.rb +4 -0
- data/lib/parser/version.rb +1 -1
- data/parser.gemspec +1 -1
- metadata +6 -5
data/lib/parser/runner.rb
CHANGED
@@ -37,7 +37,7 @@ module Parser
|
|
37
37
|
|
38
38
|
private
|
39
39
|
|
40
|
-
LEGACY_MODES = %i[lambda procarg0 encoding index arg_inside_procarg0 forward_arg].freeze
|
40
|
+
LEGACY_MODES = %i[lambda procarg0 encoding index arg_inside_procarg0 forward_arg kwargs match_pattern].freeze
|
41
41
|
|
42
42
|
def runner_name
|
43
43
|
raise NotImplementedError, "implement #{self.class}##{__callee__}"
|
data/lib/parser/source/buffer.rb
CHANGED
@@ -114,8 +114,7 @@ module Parser
|
|
114
114
|
@slice_source = nil
|
115
115
|
|
116
116
|
# Cache for fast lookup
|
117
|
-
@
|
118
|
-
@column_for_position = {}
|
117
|
+
@line_index_for_position = {}
|
119
118
|
|
120
119
|
self.source = source if source
|
121
120
|
end
|
@@ -207,9 +206,10 @@ module Parser
|
|
207
206
|
# @return [[Integer, Integer]] `[line, column]`
|
208
207
|
#
|
209
208
|
def decompose_position(position)
|
210
|
-
|
209
|
+
line_index = line_index_for_position(position)
|
210
|
+
line_begin = line_begins[line_index]
|
211
211
|
|
212
|
-
[ @first_line +
|
212
|
+
[ @first_line + line_index , position - line_begin ]
|
213
213
|
end
|
214
214
|
|
215
215
|
##
|
@@ -220,10 +220,7 @@ module Parser
|
|
220
220
|
# @api private
|
221
221
|
#
|
222
222
|
def line_for_position(position)
|
223
|
-
|
224
|
-
line_no, _ = line_for(position)
|
225
|
-
@first_line + line_no
|
226
|
-
end
|
223
|
+
line_index_for_position(position) + @first_line
|
227
224
|
end
|
228
225
|
|
229
226
|
##
|
@@ -234,10 +231,8 @@ module Parser
|
|
234
231
|
# @api private
|
235
232
|
#
|
236
233
|
def column_for_position(position)
|
237
|
-
|
238
|
-
|
239
|
-
position - line_begin
|
240
|
-
end
|
234
|
+
line_index = line_index_for_position(position)
|
235
|
+
position - line_begins[line_index]
|
241
236
|
end
|
242
237
|
|
243
238
|
##
|
@@ -278,15 +273,13 @@ module Parser
|
|
278
273
|
# @raise [IndexError] if `lineno` is out of bounds
|
279
274
|
#
|
280
275
|
def line_range(lineno)
|
281
|
-
index = lineno - @first_line
|
282
|
-
if index
|
276
|
+
index = lineno - @first_line
|
277
|
+
if index < 0 || index + 1 >= line_begins.size
|
283
278
|
raise IndexError, 'Parser::Source::Buffer: range for line ' \
|
284
279
|
"#{lineno} requested, valid line numbers are #{@first_line}.." \
|
285
|
-
"#{@first_line + line_begins.size -
|
286
|
-
elsif index == line_begins.size
|
287
|
-
Range.new(self, line_begins[-index][1], @source.size)
|
280
|
+
"#{@first_line + line_begins.size - 2}"
|
288
281
|
else
|
289
|
-
Range.new(self, line_begins[
|
282
|
+
Range.new(self, line_begins[index], line_begins[index + 1] - 1)
|
290
283
|
end
|
291
284
|
end
|
292
285
|
|
@@ -303,27 +296,52 @@ module Parser
|
|
303
296
|
# @return [Integer]
|
304
297
|
#
|
305
298
|
def last_line
|
306
|
-
line_begins.size + @first_line -
|
299
|
+
line_begins.size + @first_line - 2
|
300
|
+
end
|
301
|
+
|
302
|
+
# :nodoc:
|
303
|
+
def freeze
|
304
|
+
source_lines; line_begins; source_range # build cache
|
305
|
+
super
|
307
306
|
end
|
308
307
|
|
309
308
|
private
|
310
309
|
|
310
|
+
# @returns [0, line_begin_of_line_1, ..., source.size + 1]
|
311
311
|
def line_begins
|
312
|
-
|
313
|
-
|
314
|
-
|
312
|
+
@line_begins ||= begin
|
313
|
+
begins = [0]
|
314
|
+
index = 0
|
315
315
|
while index = @source.index("\n".freeze, index)
|
316
316
|
index += 1
|
317
|
-
|
317
|
+
begins << index
|
318
318
|
end
|
319
|
+
begins << @source.size + 1
|
320
|
+
begins
|
319
321
|
end
|
322
|
+
end
|
320
323
|
|
321
|
-
|
324
|
+
# @returns 0-based line index of position
|
325
|
+
def line_index_for_position(position)
|
326
|
+
@line_index_for_position[position] || begin
|
327
|
+
index = bsearch(line_begins, position) - 1
|
328
|
+
@line_index_for_position[position] = index unless @line_index_for_position.frozen?
|
329
|
+
index
|
330
|
+
end
|
322
331
|
end
|
323
332
|
|
324
|
-
|
325
|
-
line_begins
|
326
|
-
|
333
|
+
if Array.method_defined?(:bsearch_index) # RUBY_VERSION >= 2.3
|
334
|
+
def bsearch(line_begins, position)
|
335
|
+
line_begins.bsearch_index do |line_begin|
|
336
|
+
position < line_begin
|
337
|
+
end || line_begins.size - 1 # || only for out of bound values
|
338
|
+
end
|
339
|
+
else
|
340
|
+
def bsearch(line_begins, position)
|
341
|
+
@line_range ||= 0...line_begins.size
|
342
|
+
@line_range.bsearch do |i|
|
343
|
+
position < line_begins[i]
|
344
|
+
end || line_begins.size - 1 # || only for out of bound values
|
327
345
|
end
|
328
346
|
end
|
329
347
|
end
|
data/lib/parser/version.rb
CHANGED
data/parser.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
'source_code_uri' => "https://github.com/whitequark/parser/tree/v#{spec.version}"
|
21
21
|
}
|
22
22
|
|
23
|
-
spec.files = Dir['bin/*', 'lib/**/*.rb', 'parser.gemspec']
|
23
|
+
spec.files = Dir['bin/*', 'lib/**/*.rb', 'parser.gemspec', 'LICENSE.txt']
|
24
24
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
25
25
|
spec.require_paths = ['lib']
|
26
26
|
|
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:
|
4
|
+
version: 3.0.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- whitequark
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-12-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ast
|
@@ -165,6 +165,7 @@ executables:
|
|
165
165
|
extensions: []
|
166
166
|
extra_rdoc_files: []
|
167
167
|
files:
|
168
|
+
- LICENSE.txt
|
168
169
|
- bin/ruby-parse
|
169
170
|
- bin/ruby-rewrite
|
170
171
|
- lib/gauntlet_parser.rb
|
@@ -243,9 +244,9 @@ licenses:
|
|
243
244
|
- MIT
|
244
245
|
metadata:
|
245
246
|
bug_tracker_uri: https://github.com/whitequark/parser/issues
|
246
|
-
changelog_uri: https://github.com/whitequark/parser/blob/
|
247
|
-
documentation_uri: https://www.rubydoc.info/gems/parser/
|
248
|
-
source_code_uri: https://github.com/whitequark/parser/tree/
|
247
|
+
changelog_uri: https://github.com/whitequark/parser/blob/v3.0.0.0/CHANGELOG.md
|
248
|
+
documentation_uri: https://www.rubydoc.info/gems/parser/3.0.0.0
|
249
|
+
source_code_uri: https://github.com/whitequark/parser/tree/v3.0.0.0
|
249
250
|
post_install_message:
|
250
251
|
rdoc_options: []
|
251
252
|
require_paths:
|