summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEarlopain <14981592+Earlopain@users.noreply.github.com>2026-01-26 17:28:31 +0100
committergit <svn-admin@ruby-lang.org>2026-01-27 14:43:51 +0000
commit5d769228c1055524205437860beb1fc2de2d11a0 (patch)
tree869773d857c43d213dee513dda49fdb70d3f7a59
parentfa3e3d1090b2f843735c467aec31dfe7c34581cd (diff)
[ruby/prism] Remove `Prism.lex_ripper`
Since `on_sp` is emitted, it doesn't do a whole lot anymore. This leaves one incompatibility for code like `"x#$%"` Ripper confuses this for bare interpolation with a global, but `$%` is not a valid global name. Still, it emits two string tokens in such a case. It doesn't make sense for prism to work around this bug, so the affected files are added as excludes. Since the only usage of this method makes sense for testing in prism itself, the method is removed instead of deprecated. https://github.com/ruby/prism/commit/31be379f98
-rw-r--r--lib/prism.rb11
-rw-r--r--lib/prism/lex_ripper.rb55
-rw-r--r--lib/prism/prism.gemspec1
-rw-r--r--test/prism/bom_test.rb3
-rw-r--r--test/prism/lex_test.rb3
5 files changed, 4 insertions, 69 deletions
diff --git a/lib/prism.rb b/lib/prism.rb
index dab3420377..781bd4bb01 100644
--- a/lib/prism.rb
+++ b/lib/prism.rb
@@ -20,7 +20,6 @@ module Prism
autoload :DSL, "prism/dsl"
autoload :InspectVisitor, "prism/inspect_visitor"
autoload :LexCompat, "prism/lex_compat"
- autoload :LexRipper, "prism/lex_ripper"
autoload :MutationCompiler, "prism/mutation_compiler"
autoload :Pack, "prism/pack"
autoload :Pattern, "prism/pattern"
@@ -35,7 +34,6 @@ module Prism
# private here.
private_constant :LexCompat
- private_constant :LexRipper
# Raised when requested to parse as the currently running Ruby version but Prism has no support for it.
class CurrentVersionError < ArgumentError
@@ -69,15 +67,6 @@ module Prism
end
# :call-seq:
- # Prism::lex_ripper(source) -> Array
- #
- # This wraps the result of Ripper.lex. It produces almost exactly the
- # same tokens. Raises SyntaxError if the syntax in source is invalid.
- def self.lex_ripper(source)
- LexRipper.new(source).result # steep:ignore
- end
-
- # :call-seq:
# Prism::load(source, serialized, freeze) -> ParseResult
#
# Load the serialized AST using the source as a reference into a tree.
diff --git a/lib/prism/lex_ripper.rb b/lib/prism/lex_ripper.rb
deleted file mode 100644
index f069e50ba9..0000000000
--- a/lib/prism/lex_ripper.rb
+++ /dev/null
@@ -1,55 +0,0 @@
-# frozen_string_literal: true
-# :markup: markdown
-
-require "ripper"
-
-module Prism
- # This is a class that wraps the Ripper lexer to produce almost exactly the
- # same tokens.
- class LexRipper # :nodoc:
- attr_reader :source
-
- def initialize(source)
- @source = source
- end
-
- def result
- previous = [] #: [[Integer, Integer], Symbol, String, untyped] | []
- results = [] #: Array[[[Integer, Integer], Symbol, String, untyped]]
-
- lex(source).each do |token|
- case token[1]
- when :on_tstring_content
- if previous[1] == :on_tstring_content && (token[2].start_with?("\#$") || token[2].start_with?("\#@"))
- previous[2] << token[2]
- else
- results << token
- previous = token
- end
- else
- results << token
- previous = token
- end
- end
-
- results
- end
-
- private
-
- if Ripper.method(:lex).parameters.assoc(:keyrest)
- def lex(source)
- Ripper.lex(source, raise_errors: true)
- end
- else
- def lex(source)
- ripper = Ripper::Lexer.new(source)
- ripper.lex.tap do |result|
- raise SyntaxError, ripper.errors.map(&:message).join(' ;') if ripper.errors.any?
- end
- end
- end
- end
-
- private_constant :LexRipper
-end
diff --git a/lib/prism/prism.gemspec b/lib/prism/prism.gemspec
index 283c7b04aa..8c9b140f0e 100644
--- a/lib/prism/prism.gemspec
+++ b/lib/prism/prism.gemspec
@@ -77,7 +77,6 @@ Gem::Specification.new do |spec|
"lib/prism/ffi.rb",
"lib/prism/inspect_visitor.rb",
"lib/prism/lex_compat.rb",
- "lib/prism/lex_ripper.rb",
"lib/prism/mutation_compiler.rb",
"lib/prism/node_ext.rb",
"lib/prism/node.rb",
diff --git a/test/prism/bom_test.rb b/test/prism/bom_test.rb
index 890bc4b36c..0fa00ae4e8 100644
--- a/test/prism/bom_test.rb
+++ b/test/prism/bom_test.rb
@@ -5,6 +5,7 @@
return if RUBY_ENGINE != "ruby"
require_relative "test_helper"
+require "ripper"
module Prism
class BOMTest < TestCase
@@ -53,7 +54,7 @@ module Prism
def assert_bom(source)
bommed = "\xEF\xBB\xBF#{source}"
- assert_equal Prism.lex_ripper(bommed), Prism.lex_compat(bommed).value
+ assert_equal Ripper.lex(bommed), Prism.lex_compat(bommed).value
end
end
end
diff --git a/test/prism/lex_test.rb b/test/prism/lex_test.rb
index ea4606d2fb..9a9f203c28 100644
--- a/test/prism/lex_test.rb
+++ b/test/prism/lex_test.rb
@@ -3,6 +3,7 @@
return if !(RUBY_ENGINE == "ruby" && RUBY_VERSION >= "3.2.0")
require_relative "test_helper"
+require "ripper"
module Prism
class LexTest < TestCase
@@ -49,7 +50,7 @@ module Prism
if RUBY_VERSION >= "3.3"
def test_lex_compare
prism = Prism.lex_compat(File.read(__FILE__), version: "current").value
- ripper = Prism.lex_ripper(File.read(__FILE__))
+ ripper = Ripper.lex(File.read(__FILE__))
assert_equal(ripper, prism)
end
end