11# frozen_string_literal: true
22# typed: ignore
33
4+ require "ripper"
5+
46module Prism
5- # This class is responsible for lexing files with both lex_compat and
6- # lex_ripper and ensuring they match up. It keeps track of the files which
7+ # This class is responsible for lexing files with both prism and
8+ # ripper and ensuring they match up. It keeps track of the files which
79 # failed to match up, and the files which passed.
810 class LexTask
911 attr_reader :failing_files , :passing_file_count
@@ -28,7 +30,7 @@ module Prism
2830 end
2931
3032 result = Prism . lex_compat ( source )
31- if result . errors . empty? && Prism . lex_ripper ( source ) == result . value
33+ if result . errors . empty? && Ripper . lex ( source ) == result . value
3234 @passing_file_count += 1
3335 true
3436 else
@@ -98,6 +100,10 @@ TARGETS = {
98100
99101 # Requires an implicit -x, which ripper does not respect
100102 "tool/merger.rb" ,
103+
104+ # Contains `"x#$%"` which looks like bare interpolation but $% is not a valid global.
105+ # This confuses ripper, it emits two string tokens. https://bugs.ruby-lang.org/issues/21849
106+ "ext/psych/lib/psych/scalar_scanner.rb" ,
101107 ]
102108 } ,
103109 discourse : {
@@ -265,6 +271,16 @@ TOP_100_GEMS_INVALID_SYNTAX_PREFIXES = %w[
265271 top-100-gems/devise-4.9.2/lib/generators/templates/controllers/
266272 top-100-gems/fastlane-2.212.1/fastlane/lib/assets/custom_action_template.rb
267273]
274+ TOP_100_GEMS_LEX_RIPPER_BUG = [
275+ # Contains code like `"x#$%"` which looks like bare interpolation but $% is not a valid global.
276+ # This confuses ripper, it emits two string tokens. https://bugs.ruby-lang.org/issues/21849
277+ "faker-3.1.1/lib/faker/default/internet.rb" ,
278+ "ruby_parser-3.20.0/test/test_ruby_parser.rb" ,
279+ "rouge-4.1.0/lib/rouge/lexers/cisco_ios.rb" ,
280+ "rouge-4.1.0/lib/rouge/lexers/ghc_cmm.rb" ,
281+ "rouge-4.1.0/lib/rouge/lexers/nasm.rb" ,
282+ "rouge-4.1.0/lib/rouge/lexers/velocity.rb" ,
283+ ]
268284
269285namespace :download do
270286 directory TOP_100_GEMS_DIR
@@ -346,7 +362,10 @@ task "lex:topgems": ["download:topgems", :compile] do
346362 lex_task . compare ( filepath )
347363 end
348364
349- gem_failing_files = lex_task . failing_files . map { |todo | todo . delete_prefix ( "#{ directory } /" ) }
365+ gem_failing_files = lex_task . failing_files . filter_map do |todo |
366+ next if TOP_100_GEMS_LEX_RIPPER_BUG . any? { |path | todo . end_with? ( path ) }
367+ todo . delete_prefix ( "#{ directory } /" )
368+ end
350369 failing_files [ gem_name ] = gem_failing_files if gem_failing_files . any?
351370 end
352371
0 commit comments